فهرست منبع

removed Showpercent

Tig 8 ماه پیش
والد
کامیت
2f2076ddb7

+ 21 - 20
Terminal.Gui/View/View.ScrollBars.cs

@@ -4,8 +4,29 @@ namespace Terminal.Gui;
 public partial class View
 public partial class View
 {
 {
     private Lazy<ScrollBar> _horizontalScrollBar = null!;
     private Lazy<ScrollBar> _horizontalScrollBar = null!;
+
+    /// <summary>
+    ///     Gets the horizontal <see cref="ScrollBar"/>. This property is lazy-loaded and will not be created until it is accessed.
+    /// </summary>
+    /// <remarks>
+    ///     <para>
+    ///         See <see cref="ScrollBar"/> for more information on how to use the ScrollBar.
+    ///     </para>
+    /// </remarks>
+    public ScrollBar HorizontalScrollBar => _horizontalScrollBar.Value;
+
     private Lazy<ScrollBar> _verticalScrollBar = null!;
     private Lazy<ScrollBar> _verticalScrollBar = null!;
 
 
+    /// <summary>
+    ///     Gets the vertical <see cref="ScrollBar"/>. This property is lazy-loaded and will not be created until it is accessed.
+    /// </summary>
+    /// <remarks>
+    ///     <para>
+    ///         See <see cref="ScrollBar"/> for more information on how to use the ScrollBar.
+    ///     </para>
+    /// </remarks>
+    public ScrollBar VerticalScrollBar => _verticalScrollBar.Value;
+
     /// <summary>
     /// <summary>
     ///     Initializes the ScrollBars of the View. Called by the View constructor.
     ///     Initializes the ScrollBars of the View. Called by the View constructor.
     /// </summary>
     /// </summary>
@@ -151,26 +172,6 @@ public partial class View
                                     };
                                     };
     }
     }
 
 
-    /// <summary>
-    ///     Gets the horizontal <see cref="ScrollBar"/>. This property is lazy-loaded and will not be created until it is accessed.
-    /// </summary>
-    /// <remarks>
-    ///     <para>
-    ///         See <see cref="ScrollBar"/> for more information on how to use the ScrollBar.
-    ///     </para>
-    /// </remarks>
-    public ScrollBar HorizontalScrollBar => _horizontalScrollBar.Value;
-
-    /// <summary>
-    ///     Gets the vertical <see cref="ScrollBar"/>. This property is lazy-loaded and will not be created until it is accessed.
-    /// </summary>
-    /// <remarks>
-    ///     <para>
-    ///         See <see cref="ScrollBar"/> for more information on how to use the ScrollBar.
-    ///     </para>
-    /// </remarks>
-    public ScrollBar VerticalScrollBar => _verticalScrollBar.Value;
-
     /// <summary>
     /// <summary>
     ///     Clean up the ScrollBars of the View. Called by View.Dispose.
     ///     Clean up the ScrollBars of the View. Called by View.Dispose.
     /// </summary>
     /// </summary>

+ 5 - 28
Terminal.Gui/Views/ScrollBar/ScrollBar.cs

@@ -17,9 +17,9 @@ namespace Terminal.Gui;
 ///         See the <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/scrolling.html">Scrolling Deep Dive</see>.
 ///         See the <see href="https://gui-cs.github.io/Terminal.GuiV2Docs/docs/scrolling.html">Scrolling Deep Dive</see>.
 ///     </para>
 ///     </para>
 ///     <para>
 ///     <para>
-///         By default, the built-in View scrollbars have both <see cref="View.Visible"/> and <see cref="AutoShow"/> set to
+///         By default, the built-in View scrollbars (<see cref="View.VerticalScrollBar"/>/<see cref="View.HorizontalScrollBar"/>) have both <see cref="View.Visible"/> and <see cref="AutoShow"/> set to
 ///         <see langword="false"/>.
 ///         <see langword="false"/>.
-///         To enable them, either  set <see cref="AutoShow"/> set to <see langword="true"/> or explictly set
+///         To enable them, either set <see cref="AutoShow"/> set to <see langword="true"/> or explicitly set
 ///         <see cref="View.Visible"/>
 ///         <see cref="View.Visible"/>
 ///         to <see langword="true"/>.
 ///         to <see langword="true"/>.
 ///     </para>
 ///     </para>
@@ -81,6 +81,8 @@ public class ScrollBar : View, IOrientation, IDesignable
         // This sets the width/height etc...
         // This sets the width/height etc...
         OnOrientationChanged (Orientation);
         OnOrientationChanged (Orientation);
 
 
+        return;
+
         void OnDecreaseButtonOnAccept (object? s, CommandEventArgs e)
         void OnDecreaseButtonOnAccept (object? s, CommandEventArgs e)
         {
         {
             Position -= Increment;
             Position -= Increment;
@@ -104,24 +106,9 @@ public class ScrollBar : View, IOrientation, IDesignable
             Visible = VisibleContentSize < ScrollableContentSize;
             Visible = VisibleContentSize < ScrollableContentSize;
         }
         }
 
 
-        if (Orientation == Orientation.Vertical)
-        {
-            _slider.VisibleContentSize = VisibleContentSize;
-        }
-        else
-        {
-            _slider.VisibleContentSize = VisibleContentSize;
-        }
-
+        _slider.VisibleContentSize = VisibleContentSize;
         _slider.Size = CalculateSliderSize ();
         _slider.Size = CalculateSliderSize ();
         _sliderPosition = CalculateSliderPositionFromContentPosition (_position);
         _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;
         _slider.Position = _sliderPosition.Value;
     }
     }
 
 
@@ -235,16 +222,6 @@ public class ScrollBar : View, IOrientation, IDesignable
         }
         }
     }
     }
 
 
-    /// <summary>
-    ///     Gets or sets whether the Scroll will show the percentage the slider
-    ///     takes up within the <see cref="ScrollableContentSize"/>.
-    /// </summary>
-    public bool ShowPercent
-    {
-        get => _slider.ShowPercent;
-        set => _slider.ShowPercent = value;
-    }
-
     private int? _visibleContentSize;
     private int? _visibleContentSize;
 
 
     /// <summary>
     /// <summary>

+ 0 - 45
Terminal.Gui/Views/ScrollBar/ScrollSlider.cs

@@ -100,22 +100,6 @@ public class ScrollSlider : View, IOrientation, IDesignable
         return true;
         return true;
     }
     }
 
 
-    private bool _showPercent;
-
-    /// <summary>
-    ///     Gets or sets whether the ScrollSlider will set <see cref="View.Text"/> to show the percentage the slider
-    ///     takes up within the <see cref="View.SuperView"/>'s Viewport.
-    /// </summary>
-    public bool ShowPercent
-    {
-        get => _showPercent;
-        set
-        {
-            _showPercent = value;
-            SetNeedsDraw ();
-        }
-    }
-
     private int? _size;
     private int? _size;
 
 
     /// <summary>
     /// <summary>
@@ -290,33 +274,6 @@ public class ScrollSlider : View, IOrientation, IDesignable
     /// <summary>Raised when the <see cref="Position"/> has changed. Indicates how much to scroll.</summary>
     /// <summary>Raised when the <see cref="Position"/> has changed. Indicates how much to scroll.</summary>
     public event EventHandler<EventArgs<int>>? Scrolled;
     public event EventHandler<EventArgs<int>>? Scrolled;
 
 
-    /// <inheritdoc/>
-    protected override bool OnDrawingText ()
-    {
-        if (!ShowPercent)
-        {
-            Text = string.Empty;
-
-            return false;
-        }
-
-        if (SuperView is null)
-        {
-            return false;
-        }
-
-        if (Orientation == Orientation.Vertical)
-        {
-            Text = $"{(int)Math.Round ((double)Viewport.Height / SuperView!.GetContentSize ().Height * 100)}%";
-        }
-        else
-        {
-            Text = $"{(int)Math.Round ((double)Viewport.Width / SuperView!.GetContentSize ().Width * 100)}%";
-        }
-
-        return false;
-    }
-
     /// <inheritdoc/>
     /// <inheritdoc/>
     public override Attribute GetNormalColor () { return base.GetHotNormalColor (); }
     public override Attribute GetNormalColor () { return base.GetHotNormalColor (); }
 
 
@@ -478,10 +435,8 @@ public class ScrollSlider : View, IOrientation, IDesignable
     /// <inheritdoc/>
     /// <inheritdoc/>
     public bool EnableForDesign ()
     public bool EnableForDesign ()
     {
     {
-        ShowPercent = true;
         Size = 5;
         Size = 5;
 
 
         return true;
         return true;
     }
     }
-
 }
 }

+ 0 - 10
UICatalog/Scenarios/ScrollBarDemo.cs

@@ -278,16 +278,6 @@ public class ScrollBarDemo : Scenario
         autoShow.CheckedStateChanging += (s, e) => scrollBar.AutoShow = e.NewValue == CheckState.Checked;
         autoShow.CheckedStateChanging += (s, e) => scrollBar.AutoShow = e.NewValue == CheckState.Checked;
         demoFrame.Add (autoShow);
         demoFrame.Add (autoShow);
 
 
-        var ckbShowPercent = new CheckBox
-        {
-            Y = Pos.Top (lblOptions),
-            X = Pos.Right (autoShow) + 1,
-            Text = "ShowP_ercent",
-            CheckedState = scrollBar.ShowPercent ? CheckState.Checked : CheckState.UnChecked
-        };
-        ckbShowPercent.CheckedStateChanging += (s, e) => scrollBar.ShowPercent = e.NewValue == CheckState.Checked;
-        demoFrame.Add (ckbShowPercent);
-
         var lblSliderPosition = new Label
         var lblSliderPosition = new Label
         {
         {
             Text = "SliderPosition:",
             Text = "SliderPosition:",

+ 0 - 22
UnitTests/Views/ScrollSliderTests.cs

@@ -1007,26 +1007,4 @@ public class ScrollSliderTests (ITestOutputHelper output)
 
 
         _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
     }
     }
-
-    [Fact]
-    public void ShowPercent_True_ShowsPercentage ()
-    {
-        View super = new ()
-        {
-            Id = "super",
-            Width = 10,
-            Height = 10
-        };
-        ScrollSlider scrollSlider = new ()
-        {
-            Id = "scrollSlider",
-            Height = 10,
-            Width = 10,
-        };
-        super.Add (scrollSlider);
-        scrollSlider.ShowPercent = true;
-        Assert.True (scrollSlider.ShowPercent);
-        super.Draw ();
-        Assert.Contains ("0%", scrollSlider.Text);
-    }
 }
 }