Browse Source

Code cleanup and API doc improvements

Tig 11 months ago
parent
commit
cb1c793f43
2 changed files with 22 additions and 28 deletions
  1. 11 11
      Terminal.Gui/Views/Scroll/ScrollBar.cs
  2. 11 17
      UICatalog/Scenarios/CharacterMap.cs

+ 11 - 11
Terminal.Gui/Views/Scroll/ScrollBar.cs

@@ -35,24 +35,24 @@ public class ScrollBar : View
     private readonly ScrollButton _decrease;
     private readonly ScrollButton _increase;
 
-    private bool _autoHideScrollBar = true;
+    private bool _autoHide = true;
     private bool _showScrollIndicator = true;
 
-    /// <summary>If true the vertical/horizontal scroll bars won't be shown if it's not needed.</summary>
-    public bool AutoHideScrollBar
+    /// <summary>Gets or sets whether <see cref="View.Visible"/> will be set to <see langword="false"/> if the dimension of the scroll bar is greater than or equal to <see cref="Size"/>.</summary>
+    public bool AutoHide
     {
-        get => _autoHideScrollBar;
+        get => _autoHide;
         set
         {
-            if (_autoHideScrollBar != value)
+            if (_autoHide != value)
             {
-                _autoHideScrollBar = value;
+                _autoHide = value;
                 AdjustAll ();
             }
         }
     }
 
-    /// <summary>Defines if a scrollbar is vertical or horizontal.</summary>
+    /// <summary>Gets or sets if a scrollbar is vertical or horizontal.</summary>
     public Orientation Orientation
     {
         get => _scroll.Orientation;
@@ -63,7 +63,7 @@ public class ScrollBar : View
         }
     }
 
-    /// <summary>The position, relative to <see cref="Size"/>, to set the scrollbar at.</summary>
+    /// <summary>Gets or sets the position, relative to <see cref="Size"/>, to set the scrollbar at.</summary>
     /// <value>The position.</value>
     public int Position
     {
@@ -145,15 +145,15 @@ public class ScrollBar : View
 
     private void AdjustAll ()
     {
-        CheckScrollBarVisibility ();
+        CheckVisibility ();
         _scroll.AdjustScroll ();
         _decrease.AdjustButton ();
         _increase.AdjustButton ();
     }
 
-    private bool CheckScrollBarVisibility ()
+    private bool CheckVisibility ()
     {
-        if (!AutoHideScrollBar)
+        if (!AutoHide)
         {
             if (Visible != _showScrollIndicator)
             {

+ 11 - 17
UICatalog/Scenarios/CharacterMap.cs

@@ -27,7 +27,6 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Controls")]
 [ScenarioCategory ("Layout")]
 [ScenarioCategory ("Scrolling")]
-
 public class CharacterMap : Scenario
 {
     public Label _errorLabel;
@@ -243,7 +242,6 @@ public class CharacterMap : Scenario
             // Ensure the typed glyph is selected 
             _charMap.SelectedCodePoint = (int)result;
 
-
             // Cancel the event to prevent ENTER from being handled elsewhere
             e.Handled = true;
         }
@@ -305,7 +303,6 @@ public class CharacterMap : Scenario
 
         return item;
     }
-
 }
 
 internal class CharMap : View
@@ -464,6 +461,7 @@ internal class CharMap : View
 
         // Add scrollbars
         Padding.Thickness = new (0, 0, 1, 0);
+
         ScrollBar hScrollBar = new ()
         {
             X = 0,
@@ -473,10 +471,7 @@ internal class CharMap : View
             Orientation = Orientation.Horizontal
         };
 
-        hScrollBar.VisibleChanged += (sender, args) =>
-                                     {
-                                         Padding.Thickness = Padding.Thickness with { Bottom = hScrollBar.Visible ? 1 : 0 };
-                                     };
+        hScrollBar.VisibleChanged += (sender, args) => { Padding.Thickness = Padding.Thickness with { Bottom = hScrollBar.Visible ? 1 : 0 }; };
 
         ScrollBar vScrollBar = new ()
         {
@@ -491,14 +486,12 @@ internal class CharMap : View
         Padding.Add (vScrollBar, hScrollBar);
         hScrollBar.PositionChanged += (sender, args) => { Viewport = Viewport with { X = args.CurrentValue }; };
 
-        ViewportChanged += UpdateVertialScrollBar;
-
-        void UpdateVertialScrollBar (object sender, DrawEventArgs e)
-        {
-            vScrollBar.Size = GetContentSize ().Height;
-            vScrollBar.Position = Viewport.Y;
-        }
-    }
+        ViewportChanged += (sender, args) =>
+                           {
+                               vScrollBar.Size = GetContentSize ().Height;
+                               vScrollBar.Position = Viewport.Y;
+                           };
+    };
 
     private void Handle_MouseEvent (object sender, MouseEventEventArgs e)
     {
@@ -861,6 +854,7 @@ internal class CharMap : View
         if (me.Flags == MouseFlags.Button1Clicked)
         {
             SelectedCodePoint = val;
+
             return;
         }
 
@@ -976,7 +970,7 @@ internal class CharMap : View
                                                         document.RootElement,
                                                         new
                                                             JsonSerializerOptions
-                                                        { WriteIndented = true }
+                                                            { WriteIndented = true }
                                                        );
             }
 
@@ -1053,7 +1047,7 @@ internal class CharMap : View
             };
             dlg.Add (label);
 
-            var json = new TextView ()
+            var json = new TextView
             {
                 X = 0,
                 Y = Pos.Bottom (label),