Browse Source

Tweaked scroll logic

Tig 8 months ago
parent
commit
e7fc187226

+ 7 - 0
Terminal.Gui/Views/ScrollBar/ScrollBar.cs

@@ -109,6 +109,13 @@ public class ScrollBar : View, IOrientation, IDesignable
 
         _slider.Size = CalculateSliderSize ();
         _sliderPosition = CalculateSliderPositionFromContentPosition (_position);
+
+        // This keeps the position constant while slider is moving
+        if (_sliderPosition.Value != _slider.Position)
+        {
+            //Position = CalculatePositionFromSliderPosition (_sliderPosition.Value);
+        }
+
         _slider.Position = _sliderPosition.Value;
     }
 

+ 1 - 1
Terminal.Gui/Views/ScrollBar/ScrollSlider.cs

@@ -200,7 +200,7 @@ public class ScrollSlider : View, IOrientation, IDesignable
             }
             _visibleContentSize = int.Max (1, value);
 
-            if (_position > _visibleContentSize - _size)
+            if (_position >= _visibleContentSize - _size)
             {
                 Position = _position;
             }

+ 15 - 3
UICatalog/Scenarios/Editors/EventLog.cs

@@ -18,7 +18,7 @@ public class EventLog : ListView
     public EventLog ()
     {
         Title = "Event Log";
-        CanFocus = false;
+        CanFocus = true;
 
         X = Pos.AnchorEnd ();
         Y = 0;
@@ -38,6 +38,20 @@ public class EventLog : ListView
         };
 
         Initialized += EventLog_Initialized;
+
+        HorizontalScrollBar.AutoHide = true;
+        VerticalScrollBar.AutoHide = true;
+
+        AddCommand (Command.DeleteAll,
+                   () =>
+                   {
+                       _eventSource.Clear ();
+
+                       return true;
+                   });
+
+        KeyBindings.Add (Key.Delete, Command.DeleteAll);
+
     }
     public ExpanderButton? ExpandButton { get; }
 
@@ -94,10 +108,8 @@ public class EventLog : ListView
 
     private void EventLog_Initialized (object? _, EventArgs e)
     {
-
         Border?.Add (ExpandButton!);
         Source = new ListWrapper<string> (_eventSource);
-
     }
     private string GetIdentifyingString (View? view)
     {

+ 2 - 2
UICatalog/Scenarios/ScrollBarDemo.cs

@@ -37,7 +37,7 @@ public class ScrollBarDemo : Scenario
             X = Pos.AnchorEnd () - 5,
             AutoHide = false,
             ScrollableContentSize = 100,
-            //ShowPercent = true
+            Height = Dim.Fill()
         };
         demoFrame.Add (scrollBar);
 
@@ -394,7 +394,7 @@ public class ScrollBarDemo : Scenario
 
             controlledList.ViewportChanged += (s, e) =>
                                               {
-                                                  eventLog.Log ($"ViewportChanged: {e.NewViewport.Y}");
+                                                  eventLog.Log ($"ViewportChanged: {e.NewViewport}");
                                                   scrollBar.Position = e.NewViewport.Y;
                                               };