From 2f2076ddb7246e9a0a8791376b264310f8a50712 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 18 Nov 2024 13:33:27 -0700 Subject: [PATCH] removed Showpercent --- Terminal.Gui/View/View.ScrollBars.cs | 41 +++++++++--------- Terminal.Gui/Views/ScrollBar/ScrollBar.cs | 33 +++----------- Terminal.Gui/Views/ScrollBar/ScrollSlider.cs | 45 -------------------- UICatalog/Scenarios/ScrollBarDemo.cs | 10 ----- UnitTests/Views/ScrollSliderTests.cs | 22 ---------- 5 files changed, 26 insertions(+), 125 deletions(-) diff --git a/Terminal.Gui/View/View.ScrollBars.cs b/Terminal.Gui/View/View.ScrollBars.cs index 891a9837d..3db3149d6 100644 --- a/Terminal.Gui/View/View.ScrollBars.cs +++ b/Terminal.Gui/View/View.ScrollBars.cs @@ -4,8 +4,29 @@ namespace Terminal.Gui; public partial class View { private Lazy _horizontalScrollBar = null!; + + /// + /// Gets the horizontal . This property is lazy-loaded and will not be created until it is accessed. + /// + /// + /// + /// See for more information on how to use the ScrollBar. + /// + /// + public ScrollBar HorizontalScrollBar => _horizontalScrollBar.Value; + private Lazy _verticalScrollBar = null!; + /// + /// Gets the vertical . This property is lazy-loaded and will not be created until it is accessed. + /// + /// + /// + /// See for more information on how to use the ScrollBar. + /// + /// + public ScrollBar VerticalScrollBar => _verticalScrollBar.Value; + /// /// Initializes the ScrollBars of the View. Called by the View constructor. /// @@ -151,26 +172,6 @@ public partial class View }; } - /// - /// Gets the horizontal . This property is lazy-loaded and will not be created until it is accessed. - /// - /// - /// - /// See for more information on how to use the ScrollBar. - /// - /// - public ScrollBar HorizontalScrollBar => _horizontalScrollBar.Value; - - /// - /// Gets the vertical . This property is lazy-loaded and will not be created until it is accessed. - /// - /// - /// - /// See for more information on how to use the ScrollBar. - /// - /// - public ScrollBar VerticalScrollBar => _verticalScrollBar.Value; - /// /// Clean up the ScrollBars of the View. Called by View.Dispose. /// diff --git a/Terminal.Gui/Views/ScrollBar/ScrollBar.cs b/Terminal.Gui/Views/ScrollBar/ScrollBar.cs index 84cc34041..bc1892c8b 100644 --- a/Terminal.Gui/Views/ScrollBar/ScrollBar.cs +++ b/Terminal.Gui/Views/ScrollBar/ScrollBar.cs @@ -17,9 +17,9 @@ namespace Terminal.Gui; /// See the Scrolling Deep Dive. /// /// -/// By default, the built-in View scrollbars have both and set to +/// By default, the built-in View scrollbars (/) have both and set to /// . -/// To enable them, either set set to or explictly set +/// To enable them, either set set to or explicitly set /// /// to . /// @@ -81,6 +81,8 @@ public class ScrollBar : View, IOrientation, IDesignable // This sets the width/height etc... OnOrientationChanged (Orientation); + return; + void OnDecreaseButtonOnAccept (object? s, CommandEventArgs e) { Position -= Increment; @@ -104,24 +106,9 @@ public class ScrollBar : View, IOrientation, IDesignable Visible = VisibleContentSize < ScrollableContentSize; } - if (Orientation == Orientation.Vertical) - { - _slider.VisibleContentSize = VisibleContentSize; - } - else - { - _slider.VisibleContentSize = VisibleContentSize; - } - + _slider.VisibleContentSize = VisibleContentSize; _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; } @@ -235,16 +222,6 @@ public class ScrollBar : View, IOrientation, IDesignable } } - /// - /// Gets or sets whether the Scroll will show the percentage the slider - /// takes up within the . - /// - public bool ShowPercent - { - get => _slider.ShowPercent; - set => _slider.ShowPercent = value; - } - private int? _visibleContentSize; /// diff --git a/Terminal.Gui/Views/ScrollBar/ScrollSlider.cs b/Terminal.Gui/Views/ScrollBar/ScrollSlider.cs index 0456ac09d..19159b8cf 100644 --- a/Terminal.Gui/Views/ScrollBar/ScrollSlider.cs +++ b/Terminal.Gui/Views/ScrollBar/ScrollSlider.cs @@ -100,22 +100,6 @@ public class ScrollSlider : View, IOrientation, IDesignable return true; } - private bool _showPercent; - - /// - /// Gets or sets whether the ScrollSlider will set to show the percentage the slider - /// takes up within the 's Viewport. - /// - public bool ShowPercent - { - get => _showPercent; - set - { - _showPercent = value; - SetNeedsDraw (); - } - } - private int? _size; /// @@ -290,33 +274,6 @@ public class ScrollSlider : View, IOrientation, IDesignable /// Raised when the has changed. Indicates how much to scroll. public event EventHandler>? Scrolled; - /// - 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; - } - /// public override Attribute GetNormalColor () { return base.GetHotNormalColor (); } @@ -478,10 +435,8 @@ public class ScrollSlider : View, IOrientation, IDesignable /// public bool EnableForDesign () { - ShowPercent = true; Size = 5; return true; } - } diff --git a/UICatalog/Scenarios/ScrollBarDemo.cs b/UICatalog/Scenarios/ScrollBarDemo.cs index b58f23d56..7394b91f8 100644 --- a/UICatalog/Scenarios/ScrollBarDemo.cs +++ b/UICatalog/Scenarios/ScrollBarDemo.cs @@ -278,16 +278,6 @@ public class ScrollBarDemo : Scenario autoShow.CheckedStateChanging += (s, e) => scrollBar.AutoShow = e.NewValue == CheckState.Checked; 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 { Text = "SliderPosition:", diff --git a/UnitTests/Views/ScrollSliderTests.cs b/UnitTests/Views/ScrollSliderTests.cs index 997c66ffc..6f5d1cd26 100644 --- a/UnitTests/Views/ScrollSliderTests.cs +++ b/UnitTests/Views/ScrollSliderTests.cs @@ -1007,26 +1007,4 @@ public class ScrollSliderTests (ITestOutputHelper 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); - } }