Browse Source

Updated list view so it doesn't lag one frame behind (quite noticeable on quickly updating lists)

BearishSun 9 years ago
parent
commit
ceac99cc68
1 changed files with 12 additions and 4 deletions
  1. 12 4
      Source/MBansheeEngine/GUI/GUIListView.cs

+ 12 - 4
Source/MBansheeEngine/GUI/GUIListView.cs

@@ -239,7 +239,18 @@ namespace BansheeEngine
                 totalHeight = newHeight;
                 totalHeight = newHeight;
                 int maxScrollOffset = MathEx.Max(0, totalHeight - height - 1);
                 int maxScrollOffset = MathEx.Max(0, totalHeight - height - 1);
 
 
-                int startPos = MathEx.FloorToInt(scrollPct * maxScrollOffset);
+                float newScrollPct;
+                if (!scrollToLatest)
+                {
+                    // Calculate the new scroll pct (which will be active after we change the top/bottom padding element
+                    // sizes). If we use the existing scroll pct instead then the elements will lag one frame behind, which
+                    // can be very noticeable on quickly updating lists.
+                    newScrollPct = (scrollPct*scrollArea.Layout.Bounds.height)/totalHeight;
+                }
+                else
+                    newScrollPct = 1.0f;
+
+                int startPos = MathEx.FloorToInt(newScrollPct * maxScrollOffset);
                 int startIndex = MathEx.FloorToInt(startPos / (float)entryHeight);
                 int startIndex = MathEx.FloorToInt(startPos / (float)entryHeight);
 
 
                 // Check if we're at the list bottom and the extra element is out of bounds
                 // Check if we're at the list bottom and the extra element is out of bounds
@@ -249,10 +260,7 @@ namespace BansheeEngine
                 topPadding.SetHeight(startIndex * entryHeight);
                 topPadding.SetHeight(startIndex * entryHeight);
 
 
                 for (int i = 0; i < visibleEntries.Count; i++)
                 for (int i = 0; i < visibleEntries.Count; i++)
-                {
                     visibleEntries[i].UpdateContents(startIndex + i, entries[startIndex + i]);
                     visibleEntries[i].UpdateContents(startIndex + i, entries[startIndex + i]);
-                    visibleEntries[i].panel.SetPosition(0, i * entryHeight);
-                }
 
 
                 int bottomPosition = MathEx.Min(totalHeight, (startIndex + visibleEntries.Count) * entryHeight);
                 int bottomPosition = MathEx.Min(totalHeight, (startIndex + visibleEntries.Count) * entryHeight);
                 bottomPadding.SetHeight(totalHeight - bottomPosition);
                 bottomPadding.SetHeight(totalHeight - bottomPosition);