removed Showpercent

This commit is contained in:
Tig
2024-11-18 13:33:27 -07:00
parent 245d78e952
commit 2f2076ddb7
5 changed files with 26 additions and 125 deletions

View File

@@ -4,8 +4,29 @@ namespace Terminal.Gui;
public partial class View
{
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!;
/// <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>
/// Initializes the ScrollBars of the View. Called by the View constructor.
/// </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>
/// Clean up the ScrollBars of the View. Called by View.Dispose.
/// </summary>

View File

@@ -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>.
/// </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"/>.
/// 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"/>
/// to <see langword="true"/>.
/// </para>
@@ -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
}
}
/// <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;
/// <summary>

View File

@@ -100,22 +100,6 @@ public class ScrollSlider : View, IOrientation, IDesignable
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;
/// <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>
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/>
public override Attribute GetNormalColor () { return base.GetHotNormalColor (); }
@@ -478,10 +435,8 @@ public class ScrollSlider : View, IOrientation, IDesignable
/// <inheritdoc/>
public bool EnableForDesign ()
{
ShowPercent = true;
Size = 5;
return true;
}
}

View File

@@ -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:",

View File

@@ -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);
}
}