Refactored again

This commit is contained in:
Tig
2024-11-12 16:33:03 -05:00
parent e591453694
commit 7fae0c36b6
7 changed files with 530 additions and 1372 deletions

View File

@@ -109,9 +109,6 @@
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Folder Include="Views\Scroll\" />
</ItemGroup>
<!-- =================================================================== -->
<!-- Nuget -->
<!-- =================================================================== -->

View File

@@ -1,344 +0,0 @@
//#nullable enable
//using System.ComponentModel;
//using static Unix.Terminal.Delegates;
//namespace Terminal.Gui;
///// <summary>
///// Provides a visual indicator that content can be scrolled. ScrollBars consist of two buttons, one each for scrolling
///// forward or backwards, a <see cref="Scroll"/> that can be dragged
///// to scroll continuously. ScrollBars can be oriented either horizontally or vertically and support the user dragging
///// and clicking with the mouse to scroll.
///// </summary>
///// <remarks>
///// </remarks>
//public class ScrollBar : View, IOrientation, IDesignable
//{
// private readonly Scroll _scroll;
// private readonly Button _decreaseButton;
// private readonly Button _increaseButton;
// /// <inheritdoc/>
// public ScrollBar ()
// {
// CanFocus = false;
// _scroll = new ();
// _scroll.SliderPositionChanged += ScrollOnSliderPositionChanged;
// _scroll.ContentPositionChanging += OnScrollOnContentPositionChanging;
// _scroll.ContentPositionChanged += OnScrollOnContentPositionChanged;
// _scroll.Scrolled += ScrollOnScrolled;
// _scroll.SizeChanged += OnScrollOnSizeChanged;
// _decreaseButton = new ()
// {
// CanFocus = false,
// NoDecorations = true,
// NoPadding = true,
// ShadowStyle = ShadowStyle.None,
// WantContinuousButtonPressed = true
// };
// _decreaseButton.Accepting += OnDecreaseButtonOnAccept;
// _increaseButton = new ()
// {
// CanFocus = false,
// NoDecorations = true,
// NoPadding = true,
// ShadowStyle = ShadowStyle.None,
// WantContinuousButtonPressed = true
// };
// _increaseButton.Accepting += OnIncreaseButtonOnAccept;
// Add (_decreaseButton, _scroll, _increaseButton);
// _orientationHelper = new (this); // Do not use object initializer!
// _orientationHelper.Orientation = Orientation.Vertical;
// _orientationHelper.OrientationChanging += (sender, e) => OrientationChanging?.Invoke (this, e);
// _orientationHelper.OrientationChanged += (sender, e) => OrientationChanged?.Invoke (this, e);
// // This sets the width/height etc...
// OnOrientationChanged (Orientation);
// return;
// void OnDecreaseButtonOnAccept (object? s, CommandEventArgs e)
// {
// ContentPosition -= Increment;
// e.Cancel = true;
// }
// void OnIncreaseButtonOnAccept (object? s, CommandEventArgs e)
// {
// ContentPosition += Increment;
// e.Cancel = true;
// }
// }
// #region IOrientation members
// private readonly OrientationHelper _orientationHelper;
// /// <inheritdoc/>
// public Orientation Orientation
// {
// get => _orientationHelper.Orientation;
// set => _orientationHelper.Orientation = value;
// }
// /// <inheritdoc/>
// public event EventHandler<CancelEventArgs<Orientation>>? OrientationChanging;
// /// <inheritdoc/>
// public event EventHandler<EventArgs<Orientation>>? OrientationChanged;
// /// <inheritdoc/>
// public void OnOrientationChanged (Orientation newOrientation)
// {
// TextDirection = Orientation == Orientation.Vertical ? TextDirection.TopBottom_LeftRight : TextDirection.LeftRight_TopBottom;
// TextAlignment = Alignment.Center;
// VerticalTextAlignment = Alignment.Center;
// if (Orientation == Orientation.Vertical)
// {
// Width = 1;
// Height = Dim.Fill ();
// }
// else
// {
// Width = Dim.Fill ();
// Height = 1;
// }
// // Force a layout to ensure _scroll
// Layout ();
// _scroll.Orientation = newOrientation;
// }
// #endregion
// private bool _autoHide = true;
// /// <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 => _autoHide;
// set
// {
// if (_autoHide != value)
// {
// _autoHide = value;
// if (!AutoHide)
// {
// Visible = true;
// }
// SetNeedsLayout ();
// }
// }
// }
// /// <inheritdoc/>
// protected override void OnFrameChanged (in Rectangle frame)
// {
// ShowHide ();
// if (!_viewportDimension.HasValue)
// {
// _scroll.ViewportDimension = (Orientation == Orientation.Vertical ? Frame.Height : Frame.Width) - 2;
// }
// }
// private void ShowHide ()
// {
// if (!AutoHide || !IsInitialized)
// {
// return;
// }
// if (Orientation == Orientation.Vertical)
// {
// Visible = Frame.Height < Size;
// }
// else
// {
// Visible = Frame.Width < Size;
// }
// }
// /// <summary>
// /// Gets or sets whether the Scroll will show the percentage the slider
// /// takes up within the <see cref="Size"/>.
// /// </summary>
// public bool ShowPercent
// {
// get => _scroll.ShowPercent;
// set => _scroll.ShowPercent = value;
// }
// /// <summary>Get or sets if the view-port is kept in all visible area of this <see cref="ScrollBar"/>.</summary>
// public bool KeepContentInAllViewport
// {
// //get => _scroll.KeepContentInAllViewport;
// //set => _scroll.KeepContentInAllViewport = value;
// get;
// set;
// }
// /// <summary>Gets or sets the position of the slider within the ScrollBar's Viewport.</summary>
// /// <returns>The position.</returns>
// public int GetSliderPosition () => _scroll.GetSliderPosition ();
// private void ScrollOnSliderPositionChanged (object? sender, EventArgs<int> e) { SliderPositionChanged?.Invoke (this, e); }
// /// <summary>Raised when the position of the slider has changed.</summary>
// public event EventHandler<EventArgs<int>>? SliderPositionChanged;
// private void ScrollOnScrolled (object? sender, EventArgs<int> e) { Scrolled?.Invoke (this, e); }
// /// <summary>Raised when the position of the slider has changed.</summary>
// public event EventHandler<EventArgs<int>>? Scrolled;
// /// <summary>
// /// Gets or sets the size of the Scroll. This is the total size of the content that can be scrolled through.
// /// </summary>
// public int Size
// {
// get => _scroll.Size;
// set => _scroll.Size = value;
// }
// private int? _viewportDimension;
// /// <summary>
// /// Gets or sets the size of the viewport into the content being scrolled, bounded by <see cref="Size"/>.
// /// </summary>
// /// <remarks>
// /// If not explicitly set, will be the appropriate dimension of the Scroll's Frame.
// /// </remarks>
// public int ViewportDimension
// {
// get
// {
// if (_viewportDimension.HasValue)
// {
// return _viewportDimension.Value;
// }
// return Orientation == Orientation.Vertical ? Frame.Height : Frame.Width;
// }
// set
// {
// _scroll.ViewportDimension = value - 2;
// _viewportDimension = value;
// }
// }
// /// <summary>
// /// Gets or sets the position of the ScrollSlider within the range of 0...<see cref="Size"/>.
// /// </summary>
// public int ContentPosition
// {
// get => _scroll.ContentPosition;
// set => _scroll.ContentPosition = value;
// }
// private void OnScrollOnContentPositionChanging (object? sender, CancelEventArgs<int> e) { ContentPositionChanging?.Invoke (this, e); }
// private void OnScrollOnContentPositionChanged (object? sender, EventArgs<int> e) { ContentPositionChanged?.Invoke (this, e); }
// /// <summary>
// /// Raised when the <see cref="ContentPosition"/> is changing. Set <see cref="CancelEventArgs.Cancel"/> to
// /// <see langword="true"/> to prevent the position from being changed.
// /// </summary>
// public event EventHandler<CancelEventArgs<int>>? ContentPositionChanging;
// /// <summary>Raised when the <see cref="ContentPosition"/> has changed.</summary>
// public event EventHandler<EventArgs<int>>? ContentPositionChanged;
// /// <summary>Raised when <see cref="Size"/> has changed.</summary>
// public event EventHandler<EventArgs<int>>? SizeChanged;
// private void OnScrollOnSizeChanged (object? sender, EventArgs<int> e)
// {
// ShowHide ();
// SizeChanged?.Invoke (this, e);
// }
// /// <summary>
// /// Gets or sets the amount each click of the increment/decrement buttons and each
// /// mouse wheel event will incremenet/decrement the <see cref="ContentPosition"/>.
// /// </summary>
// /// <remarks>
// /// The default is 1.
// /// </remarks>
// public int Increment { get => _scroll.Increment; set => _scroll.Increment = value; }
// /// <inheritdoc/>
// protected override void OnSubviewLayout (LayoutEventArgs args) { PositionSubviews (); }
// private void PositionSubviews ()
// {
// if (Orientation == Orientation.Vertical)
// {
// _decreaseButton.Y = 0;
// _decreaseButton.X = 0;
// _decreaseButton.Width = Dim.Fill ();
// _decreaseButton.Height = 1;
// _decreaseButton.Title = Glyphs.UpArrow.ToString ();
// _increaseButton.Y = Pos.Bottom (_scroll);
// _increaseButton.X = 0;
// _increaseButton.Width = Dim.Fill ();
// _increaseButton.Height = 1;
// _increaseButton.Title = Glyphs.DownArrow.ToString ();
// _scroll.X = 0;
// _scroll.Y = Pos.Bottom (_decreaseButton);
// _scroll.Height = Dim.Fill (1);
// _scroll.Width = Dim.Fill ();
// }
// else
// {
// _decreaseButton.Y = 0;
// _decreaseButton.X = 0;
// _decreaseButton.Width = 1;
// _decreaseButton.Height = Dim.Fill ();
// _decreaseButton.Title = Glyphs.LeftArrow.ToString ();
// _increaseButton.Y = 0;
// _increaseButton.X = Pos.Right (_scroll);
// _increaseButton.Width = 1;
// _increaseButton.Height = Dim.Fill ();
// _increaseButton.Title = Glyphs.RightArrow.ToString ();
// _scroll.Y = 0;
// _scroll.X = Pos.Right (_decreaseButton);
// _scroll.Width = Dim.Fill (1);
// _scroll.Height = Dim.Fill ();
// }
// }
// /// <inheritdoc/>
// public bool EnableForDesign ()
// {
// OrientationChanged += (sender, args) =>
// {
// if (args.CurrentValue == Orientation.Vertical)
// {
// Width = 1;
// Height = Dim.Fill ();
// }
// else
// {
// Width = Dim.Fill ();
// Height = 1;
// }
// };
// Width = 1;
// Height = Dim.Fill ();
// Size = 200;
// //ShowPercent = true;
// return true;
// }
//}

View File

@@ -121,7 +121,9 @@ public class ScrollBar : View, IOrientation, IDesignable
{
return 1;
}
return (int)Math.Clamp (Math.Floor ((double)ViewportDimension / Size * (Viewport.Height - 2)), 1, ViewportDimension);
int viewport = Orientation == Orientation.Vertical ? Viewport.Height : Viewport.Width;
return (int)Math.Clamp (Math.Floor ((double)ViewportDimension / Size * (viewport - 2)), 1, ViewportDimension);
}
private void PositionSubviews ()

View File

@@ -1,12 +1,12 @@
#nullable enable
using System.ComponentModel;
using System.Diagnostics;
namespace Terminal.Gui;
/// <summary>
/// The ScrollSlider can be dragged with the mouse, constrained by the size of the Viewport of it's superview. The ScrollSlider can be
/// The ScrollSlider can be dragged with the mouse, constrained by the size of the Viewport of it's superview. The
/// ScrollSlider can be
/// oriented either vertically or horizontally.
/// </summary>
/// <remarks>
@@ -16,7 +16,7 @@ namespace Terminal.Gui;
/// be show what percent the slider is to the Superview's Viewport size.
/// </para>
/// <para>
/// Used to represent the proportion of the visible content to the Viewport in a <see cref="Scrolled"/>.
/// Used to represent the proportion of the visible content to the Viewport in a <see cref="Scrolled"/>.
/// </para>
/// </remarks>
public class ScrollSlider : View, IOrientation, IDesignable
@@ -42,6 +42,7 @@ public class ScrollSlider : View, IOrientation, IDesignable
}
#region IOrientation members
private readonly OrientationHelper _orientationHelper;
/// <inheritdoc/>
@@ -109,13 +110,16 @@ public class ScrollSlider : View, IOrientation, IDesignable
}
/// <summary>
/// Gets or sets the size of the ScrollSlider. This is a helper that simply gets or sets the Width or Height depending on the
/// <see cref="Orientation"/>. The size will be constrained such that the ScrollSlider will not go outside the Viewport of
/// Gets or sets the size of the ScrollSlider. This is a helper that simply gets or sets the Width or Height depending
/// on the
/// <see cref="Orientation"/>. The size will be constrained such that the ScrollSlider will not go outside the Viewport
/// of
/// the <see cref="View.SuperView"/>. The size will never be less than 1.
/// </summary>
/// <remarks>
/// <para>
/// The dimension of the ScrollSlider that is perpendicular to the <see cref="Orientation"/> will be set to <see cref="Dim.Fill()"/>
/// The dimension of the ScrollSlider that is perpendicular to the <see cref="Orientation"/> will be set to
/// <see cref="Dim.Fill()"/>
/// </para>
/// </remarks>
public int Size
@@ -126,10 +130,8 @@ public class ScrollSlider : View, IOrientation, IDesignable
{
return Viewport.Height - ShrinkBy / 2;
}
else
{
return Viewport.Width - ShrinkBy / 2;
}
return Viewport.Width - ShrinkBy / 2;
}
set
{
@@ -149,6 +151,7 @@ public class ScrollSlider : View, IOrientation, IDesignable
}
private int? _viewportDimension;
/// <summary>
/// Gets the size of the viewport into the content being scrolled, bounded by <see cref="Size"/>.
/// </summary>
@@ -163,6 +166,7 @@ public class ScrollSlider : View, IOrientation, IDesignable
{
return _viewportDimension.Value;
}
return Orientation == Orientation.Vertical ? SuperView?.Viewport.Height ?? 0 : SuperView?.Viewport.Width ?? 0;
}
set => _viewportDimension = value;
@@ -170,7 +174,6 @@ public class ScrollSlider : View, IOrientation, IDesignable
private void OnFrameChanged (object? sender, EventArgs<Rectangle> e)
{
Position = (Orientation == Orientation.Vertical ? e.CurrentValue.Y : e.CurrentValue.X) - ShrinkBy / 2;
}
@@ -225,10 +228,8 @@ public class ScrollSlider : View, IOrientation, IDesignable
{
return Math.Clamp (newPosittion, 0, Math.Max (0, ViewportDimension - Viewport.Height));
}
else
{
return Math.Clamp (newPosittion, 0, Math.Max (0, ViewportDimension - Viewport.Width));
}
return Math.Clamp (newPosittion, 0, Math.Max (0, ViewportDimension - Viewport.Width));
}
private void RaisePositionChangeEvents (int newPosition)
@@ -255,7 +256,7 @@ public class ScrollSlider : View, IOrientation, IDesignable
OnScrolled (distance);
Scrolled?.Invoke (this, new (in distance));
RaiseSelecting (new CommandContext (Command.Select, null, null, distance));
RaiseSelecting (new (Command.Select, null, null, distance));
}
/// <summary>
@@ -275,7 +276,6 @@ public class ScrollSlider : View, IOrientation, IDesignable
/// <summary>Raised when the <see cref="Position"/> has changed.</summary>
public event EventHandler<EventArgs<int>>? PositionChanged;
/// <summary>Called when <see cref="Position"/> has changed. Indicates how much to scroll.</summary>
protected virtual void OnScrolled (int distance) { }
@@ -349,10 +349,10 @@ public class ScrollSlider : View, IOrientation, IDesignable
if (Orientation == Orientation.Vertical)
{
Y = Frame.Y + offset < ShrinkBy / 2
? ShrinkBy / 2
: Frame.Y + offset + Frame.Height > superViewDimension
? Math.Max (superViewDimension - Frame.Height + ShrinkBy, 1)
: Frame.Y + offset;
? ShrinkBy / 2
: Frame.Y + offset + Frame.Height > superViewDimension
? Math.Max (superViewDimension - Frame.Height + ShrinkBy, 1)
: Frame.Y + offset;
}
else
{
@@ -372,13 +372,14 @@ public class ScrollSlider : View, IOrientation, IDesignable
Application.UngrabMouse ();
}
}
return true;
}
return false;
return false;
}
/// <inheritdoc />
/// <inheritdoc/>
public bool EnableForDesign ()
{
OrientationChanged += (sender, args) =>

View File

@@ -1,369 +0,0 @@
//using System;
//using System.Collections.ObjectModel;
//using System.Linq;
//using Terminal.Gui;
//namespace UICatalog.Scenarios;
//[ScenarioMetadata ("Scroll Demo", "Demonstrates Scroll.")]
//[ScenarioCategory ("Scrolling")]
//public class ScrollDemo : Scenario
//{
// public override void Main ()
// {
// Application.Init ();
// Window app = new ()
// {
// Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
// Arrangement = ViewArrangement.Fixed
// };
// var demoFrame = new FrameView ()
// {
// Title = "Demo View",
// X = 0,
// Width = 75,
// Height = 25 + 4,
// ColorScheme = Colors.ColorSchemes ["Base"],
// Arrangement = ViewArrangement.Resizable
// };
// demoFrame.Padding.Thickness = new (1);
// demoFrame.Padding.Diagnostics = ViewDiagnosticFlags.Ruler;
// app.Add (demoFrame);
// var scroll = new Scroll
// {
// X = Pos.AnchorEnd () - 5,
// Size = 1000,
// };
// demoFrame.Add (scroll);
// ListView controlledList = new ()
// {
// X = Pos.AnchorEnd (),
// Width = 5,
// Height = Dim.Fill (),
// ColorScheme = Colors.ColorSchemes ["Error"],
// };
// demoFrame.Add (controlledList);
// // populate the list box with Size items of the form "{n:00000}"
// controlledList.SetSource (new ObservableCollection<string> (Enumerable.Range (0, scroll.Size).Select (n => $"{n:00000}")));
// int GetMaxLabelWidth (int groupId)
// {
// return demoFrame.Subviews.Max (
// v =>
// {
// if (v.Y.Has<PosAlign> (out var pos) && pos.GroupId == groupId)
// {
// return v.Text.GetColumns ();
// }
// return 0;
// });
// }
// var lblWidthHeight = new Label
// {
// Text = "_Width/Height:",
// TextAlignment = Alignment.End,
// Y = Pos.Align (Alignment.Start, AlignmentModes.StartToEnd, groupId: 1),
// Width = Dim.Func (() => GetMaxLabelWidth (1))
// };
// demoFrame.Add (lblWidthHeight);
// NumericUpDown<int> scrollWidthHeight = new ()
// {
// Value = scroll.Frame.Width,
// X = Pos.Right (lblWidthHeight) + 1,
// Y = Pos.Top (lblWidthHeight)
// };
// demoFrame.Add (scrollWidthHeight);
// scrollWidthHeight.ValueChanging += (s, e) =>
// {
// if (e.NewValue < 1
// || (e.NewValue
// > (scroll.Orientation == Orientation.Vertical
// ? scroll.SuperView?.GetContentSize ().Width
// : scroll.SuperView?.GetContentSize ().Height)))
// {
// // TODO: This must be handled in the ScrollSlider if Width and Height being virtual
// e.Cancel = true;
// return;
// }
// if (scroll.Orientation == Orientation.Vertical)
// {
// scroll.Width = e.NewValue;
// }
// else
// {
// scroll.Height = e.NewValue;
// }
// };
// var lblOrientationabel = new Label
// {
// Text = "_Orientation:",
// TextAlignment = Alignment.End,
// Y = Pos.Align (Alignment.Start, groupId: 1),
// Width = Dim.Func (() => GetMaxLabelWidth (1))
// };
// demoFrame.Add (lblOrientationabel);
// var rgOrientation = new RadioGroup
// {
// X = Pos.Right (lblOrientationabel) + 1,
// Y = Pos.Top (lblOrientationabel),
// RadioLabels = ["Vertical", "Horizontal"],
// Orientation = Orientation.Horizontal
// };
// demoFrame.Add (rgOrientation);
// rgOrientation.SelectedItemChanged += (s, e) =>
// {
// if (e.SelectedItem == e.PreviousSelectedItem)
// {
// return;
// }
// if (rgOrientation.SelectedItem == 0)
// {
// scroll.Orientation = Orientation.Vertical;
// scroll.X = Pos.AnchorEnd ();
// scroll.Y = 0;
// scrollWidthHeight.Value = Math.Min (scrollWidthHeight.Value, scroll.SuperView.GetContentSize ().Width);
// scroll.Width = scrollWidthHeight.Value;
// controlledList.Visible = true;
// }
// else
// {
// scroll.Orientation = Orientation.Horizontal;
// scroll.X = 0;
// scroll.Y = Pos.AnchorEnd ();
// scrollWidthHeight.Value = Math.Min (scrollWidthHeight.Value, scroll.SuperView.GetContentSize ().Height);
// scroll.Height = scrollWidthHeight.Value;
// controlledList.Visible = false;
// }
// };
// var lblSize = new Label
// {
// Text = "_Size:",
// TextAlignment = Alignment.End,
// Y = Pos.Align (Alignment.Start, groupId: 1),
// Width = Dim.Func (() => GetMaxLabelWidth (1))
// };
// demoFrame.Add (lblSize);
// NumericUpDown<int> scrollSize = new ()
// {
// Value = scroll.Size,
// X = Pos.Right (lblSize) + 1,
// Y = Pos.Top (lblSize)
// };
// demoFrame.Add (scrollSize);
// scrollSize.ValueChanging += (s, e) =>
// {
// if (e.NewValue < 0)
// {
// e.Cancel = true;
// return;
// }
// if (scroll.Size != e.NewValue)
// {
// scroll.Size = e.NewValue;
// }
// };
// var lblSliderPosition = new Label
// {
// Text = "_SliderPosition:",
// TextAlignment = Alignment.End,
// Y = Pos.Align (Alignment.Start, groupId: 1),
// Width = Dim.Func (() => GetMaxLabelWidth (1))
// };
// demoFrame.Add (lblSliderPosition);
// Label scrollSliderPosition = new ()
// {
// X = Pos.Right (lblSliderPosition) + 1,
// Y = Pos.Top (lblSliderPosition)
// };
// demoFrame.Add (scrollSliderPosition);
// var lblScrolled = new Label
// {
// Text = "_Scrolled:",
// TextAlignment = Alignment.End,
// Y = Pos.Align (Alignment.Start, groupId: 1),
// Width = Dim.Func (() => GetMaxLabelWidth (1))
// };
// demoFrame.Add (lblScrolled);
// Label scrolled = new ()
// {
// X = Pos.Right (lblScrolled) + 1,
// Y = Pos.Top (lblScrolled)
// };
// demoFrame.Add (scrolled);
// var lblContentPosition = new Label
// {
// Text = "_ContentPosition:",
// TextAlignment = Alignment.End,
// Y = Pos.Align (Alignment.Start, groupId: 1),
// Width = Dim.Func (() => GetMaxLabelWidth (1))
// };
// demoFrame.Add (lblContentPosition);
// NumericUpDown<int> scrollContentPosition = new ()
// {
// Value = scroll.GetSliderPosition (),
// X = Pos.Right (lblContentPosition) + 1,
// Y = Pos.Top (lblContentPosition)
// };
// demoFrame.Add (scrollContentPosition);
// scrollContentPosition.ValueChanging += (s, e) =>
// {
// if (e.NewValue < 0)
// {
// e.Cancel = true;
// return;
// }
// if (scroll.ContentPosition != e.NewValue)
// {
// scroll.ContentPosition = e.NewValue;
// }
// if (scroll.ContentPosition != e.NewValue)
// {
// e.Cancel = true;
// }
// };
// var lblOptions = new Label
// {
// Text = "_Options:",
// TextAlignment = Alignment.End,
// Y = Pos.Align (Alignment.Start, groupId: 1),
// Width = Dim.Func (() => GetMaxLabelWidth (1))
// };
// demoFrame.Add (lblOptions);
// var ckbShowPercent = new CheckBox
// {
// Y = Pos.Top (lblOptions),
// X = Pos.Right (lblOptions) + 1,
// Text = "Sho_wPercent",
// CheckedState = scroll.ShowPercent ? CheckState.Checked : CheckState.UnChecked
// };
// ckbShowPercent.CheckedStateChanging += (s, e) => scroll.ShowPercent = e.NewValue == CheckState.Checked;
// demoFrame.Add (ckbShowPercent);
// //var ckbKeepContentInAllViewport = new CheckBox
// //{
// // X = Pos.Right (ckbShowScrollIndicator) + 1, Y = Pos.Bottom (scrollPosition), Text = "KeepContentInAllViewport",
// // CheckedState = Scroll.KeepContentInAllViewport ? CheckState.Checked : CheckState.UnChecked
// //};
// //ckbKeepContentInAllViewport.CheckedStateChanging += (s, e) => Scroll.KeepContentInAllViewport = e.NewValue == CheckState.Checked;
// //view.Add (ckbKeepContentInAllViewport);
// var lblScrollFrame = new Label
// {
// Y = Pos.Bottom (lblOptions) + 1
// };
// demoFrame.Add (lblScrollFrame);
// var lblScrollViewport = new Label
// {
// Y = Pos.Bottom (lblScrollFrame)
// };
// demoFrame.Add (lblScrollViewport);
// var lblScrollContentSize = new Label
// {
// Y = Pos.Bottom (lblScrollViewport)
// };
// demoFrame.Add (lblScrollContentSize);
// scroll.SubviewsLaidOut += (s, e) =>
// {
// lblScrollFrame.Text = $"Scroll Frame: {scroll.Frame.ToString ()}";
// lblScrollViewport.Text = $"Scroll Viewport: {scroll.Viewport.ToString ()}";
// lblScrollContentSize.Text = $"Scroll ContentSize: {scroll.GetContentSize ().ToString ()}";
// };
// EventLog eventLog = new ()
// {
// X = Pos.AnchorEnd (),
// Y = 0,
// Height = Dim.Fill (),
// BorderStyle = LineStyle.Single,
// ViewToLog = scroll
// };
// app.Add (eventLog);
// app.Initialized += AppOnInitialized;
// void AppOnInitialized (object sender, EventArgs e)
// {
// scroll.SizeChanged += (s, e) =>
// {
// eventLog.Log ($"SizeChanged: {e.CurrentValue}");
// if (scrollSize.Value != e.CurrentValue)
// {
// scrollSize.Value = e.CurrentValue;
// }
// };
// scroll.SliderPositionChanged += (s, e) =>
// {
// eventLog.Log ($"SliderPositionChanged: {e.CurrentValue}");
// eventLog.Log ($" ContentPosition: {scroll.ContentPosition}");
// scrollSliderPosition.Text = e.CurrentValue.ToString ();
// };
// scroll.Scrolled += (s, e) =>
// {
// eventLog.Log ($"Scrolled: {e.CurrentValue}");
// eventLog.Log ($" SliderPosition: {scroll.GetSliderPosition ()}");
// scrolled.Text = e.CurrentValue.ToString ();
// };
// scroll.ContentPositionChanged += (s, e) =>
// {
// eventLog.Log ($"ContentPositionChanged: {e.CurrentValue}");
// scrollContentPosition.Value = e.CurrentValue;
// controlledList.Viewport = controlledList.Viewport with { Y = e.CurrentValue };
// };
// controlledList.ViewportChanged += (s, e) =>
// {
// eventLog.Log ($"ViewportChanged: {e.NewViewport.Y}");
// scroll.ContentPosition = e.NewViewport.Y;
// };
// }
// Application.Run (app);
// app.Dispose ();
// Application.Shutdown ();
// }
//}

View File

@@ -179,6 +179,31 @@ public class ScrollBarTests
[Theory]
[SetupFakeDriver]
#region Vertical
#region Super 10 - ScrollBar 8
[InlineData (
10,
1,
10,
-1,
Orientation.Horizontal,
@"
┌──────────┐
│◄████████►│
└──────────┘")]
[InlineData (
10,
1,
20,
-1,
Orientation.Horizontal,
@"
┌──────────┐
│◄████░░░░►│
└──────────┘")]
[InlineData (
10,
1,
@@ -187,69 +212,462 @@ public class ScrollBarTests
Orientation.Horizontal,
@"
┌──────────┐
│◄███░░░░►│
│◄███░░░░►│
└──────────┘")]
[InlineData (
10,
3,
1,
20,
1,
Orientation.Horizontal,
@"
┌──────────┐
███░░░░
│◄░███░░░░►│
│ ░███░░░░ │
◄████░░░░
└──────────┘")]
[InlineData (
10,
1,
20,
2,
Orientation.Horizontal,
@"
┌──────────┐
│◄░████░░░►│
└──────────┘
")]
[InlineData (
10,
1,
20,
3,
Orientation.Horizontal,
@"
┌──────────┐
│◄░████░░░►│
└──────────┘
")]
[InlineData (
10,
1,
20,
4,
Orientation.Horizontal,
@"
┌──────────┐
│◄░░████░░►│
└──────────┘
")]
[InlineData (
10,
1,
20,
5,
Orientation.Horizontal,
@"
┌──────────┐
│◄░░████░░►│
└──────────┘
")]
[InlineData (
10,
1,
20,
6,
Orientation.Horizontal,
@"
┌──────────┐
│◄░░░████░►│
└──────────┘
")]
[InlineData (
10,
1,
20,
7,
Orientation.Horizontal,
@"
┌──────────┐
│◄░░░████░►│
└──────────┘
")]
[InlineData (
10,
1,
20,
8,
Orientation.Horizontal,
@"
┌──────────┐
│◄░░░░████►│
└──────────┘
")]
[InlineData (
10,
1,
20,
9,
Orientation.Horizontal,
@"
┌──────────┐
│◄░░░░████►│
└──────────┘
")]
[InlineData (
10,
1,
20,
10,
Orientation.Horizontal,
@"
┌──────────┐
│◄░░░░████►│
└──────────┘
")]
[InlineData (
10,
1,
20,
19,
Orientation.Horizontal,
@"
┌──────────┐
│◄░░░░████►│
└──────────┘
")]
[InlineData (
10,
1,
20,
20,
Orientation.Horizontal,
@"
┌──────────┐
│◄░░░░████►│
└──────────┘
")]
#endregion Super 10 - ScrollBar 8
#region Super 12 - ScrollBar 10
[InlineData (
12,
1,
10,
-1,
Orientation.Horizontal,
@"
┌────────────┐
│◄██████████►│
└────────────┘")]
[InlineData (
12,
1,
20,
-1,
Orientation.Horizontal,
@"
┌────────────┐
│◄██████░░░░►│
└────────────┘")]
[InlineData (
12,
1,
20,
0,
Orientation.Horizontal,
@"
┌────────────┐
│◄██████░░░░►│
└────────────┘")]
[InlineData (
12,
1,
20,
1,
Orientation.Horizontal,
@"
┌────────────┐
│◄██████░░░░►│
└────────────┘")]
[InlineData (
12,
1,
20,
2,
Orientation.Horizontal,
@"
┌────────────┐
│◄░██████░░░►│
└────────────┘
")]
[InlineData (
12,
1,
20,
3,
Orientation.Horizontal,
@"
┌────────────┐
│◄░██████░░░►│
└────────────┘
")]
[InlineData (
12,
1,
20,
4,
Orientation.Horizontal,
@"
┌────────────┐
│◄░░██████░░►│
└────────────┘
")]
[InlineData (
12,
1,
20,
5,
Orientation.Horizontal,
@"
┌────────────┐
│◄░░░██████░►│
└────────────┘
")]
[InlineData (
12,
1,
20,
6,
Orientation.Horizontal,
@"
┌────────────┐
│◄░░░██████░►│
└────────────┘
")]
[InlineData (
12,
1,
20,
7,
Orientation.Horizontal,
@"
┌────────────┐
│◄░░░░██████►│
└────────────┘
")]
[InlineData (
12,
1,
20,
8,
Orientation.Horizontal,
@"
┌────────────┐
│◄░░░░██████►│
└────────────┘
")]
[InlineData (
12,
1,
20,
9,
Orientation.Horizontal,
@"
┌────────────┐
│◄░░░░██████►│
└────────────┘
")]
[InlineData (
12,
1,
20,
10,
Orientation.Horizontal,
@"
┌────────────┐
│◄░░░░██████►│
└────────────┘
")]
[InlineData (
12,
1,
20,
19,
Orientation.Horizontal,
@"
┌────────────┐
│◄░░░░██████►│
└────────────┘
")]
[InlineData (
12,
1,
20,
20,
Orientation.Horizontal,
@"
┌────────────┐
│◄░░░░██████►│
└────────────┘
")]
#endregion Super 12 - ScrollBar 10
[InlineData (
10,
3,
20,
2,
Orientation.Horizontal,
@"
┌──────────┐
│ ░████░░░ │
│◄░████░░░►│
│ ░████░░░ │
└──────────┘
")]
#endregion Vertical
#region Horizontal
[InlineData (
1,
10,
10,
-1,
Orientation.Vertical,
@"
┌─┐
│▲│
│█│
│█│
│█│
│█│
│█│
│█│
│█│
│█│
│▼│
└─┘")]
[InlineData (
1,
10,
10,
5,
Orientation.Vertical,
@"
┌─┐
│▲│
│█│
│█│
│█│
│█│
│█│
│█│
│█│
│█│
│▼│
└─┘")]
[InlineData (
1,
10,
20,
5,
Orientation.Vertical,
@"
┌─┐
│▲│
│░│
│░│
│█│
│█│
│█│
│█│
│░│
│░│
│▼│
└─┘")]
[InlineData (
1,
12,
20,
5,
Orientation.Vertical,
@"
┌─┐
│▲│
│░│
│░│
│░│
│█│
│█│
│█│
│█│
│█│
│█│
│░│
│▼│
└─┘")]
[InlineData (
3,
10,
20,
0,
2,
Orientation.Vertical,
@"
┌───┐
│ ▲ │
│███│
│███│
│███│
│░░░│
│░░░│
│███│
│███│
│███│
│███│
│░░░│
│░░░│
│░░░│
│ ▼ │
└───┘")]
[InlineData (
6,
10,
20,
1,
Orientation.Vertical,
@"
┌──────┐
│ ▲ │
│░░░░░░│
│██████│
│██████│
│██████│
│░░░░░░│
│░░░░░░│
│░░░░░░│
│░░░░░░│
│ ▼ │
└──────┘")]
└───┘
")]
#endregion
public void Draws_Correctly (int superViewportWidth, int superViewportHeight, int sliderSize, int sliderPosition, Orientation orientation, string expected)
public void Draws_Correctly (int superWidth, int superHeight, int contentSize, int contentPosition, Orientation orientation, string expected)
{
var super = new Window
{
Id = "super",
Width = superViewportWidth + 2,
Height = superViewportHeight + 2
Width = superWidth + 2,
Height = superHeight + 2
};
var scrollBar = new ScrollBar
@@ -267,9 +685,9 @@ public class ScrollBarTests
}
super.Add (scrollBar);
scrollBar.Size = sliderSize;
scrollBar.Size = contentSize;
scrollBar.Layout ();
scrollBar.ContentPosition = sliderPosition;
scrollBar.ContentPosition = contentPosition;
super.BeginInit ();
super.EndInit ();
@@ -374,4 +792,54 @@ public class ScrollBarTests
Application.ResetState (true);
}
[Theory]
[InlineData (1, 10, 0, 0)]
[InlineData (1, 10, 5, 0)]
[InlineData (1, 10, 10, 1)]
[InlineData (1, 20, 0, 0)]
[InlineData (1, 20, 10, 0)]
[InlineData (1, 20, 20, 1)]
[InlineData (2, 10, 0, 0)]
[InlineData (2, 10, 5, 1)]
[InlineData (2, 10, 10, 2)]
[InlineData (2, 20, 0, 0)]
[InlineData (2, 20, 10, 1)]
[InlineData (2, 20, 20, 2)]
[InlineData (3, 10, 0, 0)]
[InlineData (3, 10, 5, 1)]
[InlineData (3, 10, 10, 3)]
[InlineData (3, 20, 0, 0)]
[InlineData (3, 20, 10, 1)]
[InlineData (3, 20, 20, 3)]
[InlineData (4, 10, 0, 0)]
[InlineData (4, 10, 5, 2)]
[InlineData (4, 10, 10, 4)]
[InlineData (4, 20, 0, 0)]
[InlineData (4, 20, 10, 2)]
[InlineData (4, 20, 20, 4)]
[InlineData (5, 10, 0, 0)]
[InlineData (5, 10, 5, 2)]
[InlineData (5, 10, 10, 5)]
[InlineData (5, 20, 0, 0)]
[InlineData (5, 20, 10, 2)]
[InlineData (5, 20, 20, 5)]
public void ScrollBar_CombinatorialTests (int width, int size, int contentPosition, int expectedSliderPosition)
{
// Arrange
var scrollBar = new ScrollBar
{
Width = width,
Size = size,
ContentPosition = contentPosition
};
scrollBar.Layout ();
// Act
var sliderPosition = scrollBar.GetSliderPosition ();
// Assert
Assert.Equal (expectedSliderPosition, sliderPosition);
}
}

View File

@@ -1,597 +0,0 @@
//using Microsoft.VisualStudio.TestPlatform.Utilities;
//using Xunit.Abstractions;
//namespace Terminal.Gui.ViewsTests;
//public class ScrollTests
//{
// public ScrollTests (ITestOutputHelper output) { _output = output; }
// private readonly ITestOutputHelper _output;
// [Fact]
// public void OnOrientationChanged_Keeps_Size ()
// {
// var scroll = new Scroll ();
// scroll.Layout ();
// scroll.Size = 1;
// scroll.Orientation = Orientation.Horizontal;
// Assert.Equal (1, scroll.Size);
// }
// [Fact]
// public void OnOrientationChanged_Sets_ContentPosition_To_0 ()
// {
// View super = new View ()
// {
// Id = "super",
// Width = 10,
// Height = 10
// };
// var scroll = new Scroll ()
// {
// };
// super.Add (scroll);
// scroll.Layout ();
// scroll.ContentPosition = 1;
// scroll.Orientation = Orientation.Horizontal;
// Assert.Equal (0, scroll.ContentPosition);
// }
// // [Theory]
// // [AutoInitShutdown]
// // [InlineData (
// // 20,
// // @"
// //█
// //█
// //█
// //█
// //█
// //░
// //░
// //░
// //░
// //░",
// // @"
// //░
// //░
// //█
// //█
// //█
// //█
// //█
// //░
// //░
// //░",
// // @"
// //░
// //░
// //░
// //░
// //░
// //█
// //█
// //█
// //█
// //█",
// // @"
// //░
// //░
// //█
// //█
// //█
// //░
// //░
// //░
// //░
// //░",
// // @"
// //█████░░░░░",
// // @"
// //░░█████░░░",
// // @"
// //░░░░░█████",
// // @"
// //░░███░░░░░")]
// // [InlineData (
// // 40,
// // @"
// //█
// //█
// //█
// //░
// //░
// //░
// //░
// //░
// //░
// //░",
// // @"
// //░
// //█
// //█
// //█
// //░
// //░
// //░
// //░
// //░
// //░",
// // @"
// //░
// //░
// //█
// //█
// //█
// //░
// //░
// //░
// //░
// //░",
// // @"
// //░
// //█
// //█
// //░
// //░
// //░
// //░
// //░
// //░
// //░",
// // @"
// //███░░░░░░░",
// // @"
// //░███░░░░░░",
// // @"
// //░░███░░░░░",
// // @"
// //░██░░░░░░░")]
// // public void Changing_Position_Size_Orientation_Draws_Correctly_KeepContentInAllViewport_True (
// // int size,
// // string firstVertExpected,
// // string middleVertExpected,
// // string endVertExpected,
// // string sizeVertExpected,
// // string firstHoriExpected,
// // string middleHoriExpected,
// // string endHoriExpected,
// // string sizeHoriExpected
// // )
// // {
// // var scroll = new Scroll
// // {
// // Orientation = Orientation.Vertical,
// // Size = size,
// // Height = 10,
// // KeepContentInAllViewport = true
// // };
// // var top = new Toplevel ();
// // top.Add (scroll);
// // RunState rs = Application.Begin (top);
// // Application.RunIteration (ref rs);
// // _ = TestHelpers.AssertDriverContentsWithFrameAre (firstVertExpected, _output);
// // scroll.Position = 4;
// // Application.RunIteration (ref rs);
// // _ = TestHelpers.AssertDriverContentsWithFrameAre (middleVertExpected, _output);
// // scroll.Position = 10;
// // Application.RunIteration (ref rs);
// // _ = TestHelpers.AssertDriverContentsWithFrameAre (endVertExpected, _output);
// // scroll.Size = size * 2;
// // Application.RunIteration (ref rs);
// // _ = TestHelpers.AssertDriverContentsWithFrameAre (sizeVertExpected, _output);
// // scroll.Orientation = Orientation.Horizontal;
// // scroll.Width = 10;
// // scroll.Height = 1;
// // scroll.Position = 0;
// // scroll.Size = size;
// // Application.RunIteration (ref rs);
// // _ = TestHelpers.AssertDriverContentsWithFrameAre (firstHoriExpected, _output);
// // scroll.Position = 4;
// // Application.RunIteration (ref rs);
// // _ = TestHelpers.AssertDriverContentsWithFrameAre (middleHoriExpected, _output);
// // scroll.Position = 10;
// // Application.RunIteration (ref rs);
// // _ = TestHelpers.AssertDriverContentsWithFrameAre (endHoriExpected, _output);
// // scroll.Size = size * 2;
// // Application.RunIteration (ref rs);
// // _ = TestHelpers.AssertDriverContentsWithFrameAre (sizeHoriExpected, _output);
// // }
// [Fact]
// public void Constructor_Defaults ()
// {
// var scroll = new Scroll ();
// Assert.False (scroll.CanFocus);
// Assert.Equal (Orientation.Vertical, scroll.Orientation);
// Assert.Equal (0, scroll.Size);
// Assert.Equal (0, scroll.GetSliderPosition ());
// }
// //[Fact]
// //[AutoInitShutdown]
// //public void KeepContentInAllViewport_True_False_KeepContentInAllViewport_True ()
// //{
// // var view = new View { Width = Dim.Fill (), Height = Dim.Fill () };
// // view.Padding.Thickness = new (0, 0, 2, 0);
// // view.SetContentSize (new (view.Viewport.Width, 30));
// // var scroll = new Scroll { Width = 2, Height = Dim.Fill (), Size = view.GetContentSize ().Height, KeepContentInAllViewport = true };
// // scroll.PositionChanged += (_, e) => view.Viewport = view.Viewport with { Y = e.CurrentValue };
// // view.Padding.Add (scroll);
// // var top = new Toplevel ();
// // top.Add (view);
// // Application.Begin (top);
// // Assert.True (scroll.KeepContentInAllViewport);
// // Assert.Equal (80, view.Padding.Viewport.Width);
// // Assert.Equal (25, view.Padding.Viewport.Height);
// // Assert.Equal (2, scroll.Viewport.Width);
// // Assert.Equal (25, scroll.Viewport.Height);
// // Assert.Equal (30, scroll.Size);
// // scroll.KeepContentInAllViewport = false;
// // scroll.Position = 50;
// // Assert.Equal (scroll.Position, scroll.Size - 1);
// // Assert.Equal (scroll.Position, view.Viewport.Y);
// // Assert.Equal (29, scroll.Position);
// // Assert.Equal (29, view.Viewport.Y);
// // top.Dispose ();
// //}
// //[Theory]
// //[AutoInitShutdown]
// //[InlineData (Orientation.Vertical)]
// //[InlineData (Orientation.Horizontal)]
// //public void Moving_Mouse_Outside_Host_Ensures_Correct_Location_KeepContentInAllViewport_True (Orientation orientation)
// //{
// // var scroll = new Scroll
// // {
// // X = 10, Y = 10, Width = orientation == Orientation.Vertical ? 1 : 10, Height = orientation == Orientation.Vertical ? 10 : 1, Size = 20,
// // SliderPosition = 5, Orientation = orientation
// // };
// // var top = new Toplevel ();
// // top.Add (scroll);
// // RunState rs = Application.Begin (top);
// // Rectangle scrollSliderFrame = scroll.Subviews.FirstOrDefault (x => x.Id == "scrollSlider")!.Frame;
// // Assert.Equal (scrollSliderFrame, orientation == Orientation.Vertical ? new (0, 2, 1, 5) : new (2, 0, 5, 1));
// // Application.RaiseMouseEvent (new () { ScreenPosition = orientation == Orientation.Vertical ? new (10, 12) : new (12, 10), Flags = MouseFlags.Button1Pressed });
// // Application.RunIteration (ref rs);
// // Application.RaiseMouseEvent (
// // new ()
// // {
// // ScreenPosition = orientation == Orientation.Vertical ? new (10, 0) : new (0, 10),
// // Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
// // });
// // Application.RunIteration (ref rs);
// // Assert.Equal (new (0, 0), scroll.Subviews.FirstOrDefault (x => x.Id == "scrollSlider")!.Frame.Location);
// // Application.RaiseMouseEvent (
// // new ()
// // {
// // ScreenPosition = orientation == Orientation.Vertical ? new (0, 25) : new (80, 0),
// // Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
// // });
// // Application.RunIteration (ref rs);
// // Assert.Equal (
// // orientation == Orientation.Vertical ? new (0, 5) : new (5, 0),
// // scroll.Subviews.FirstOrDefault (x => x.Id == "scrollSlider")!.Frame.Location);
// //}
// [Theory]
// [CombinatorialData]
// [AutoInitShutdown]
// public void Mouse_Wheel_Increments_Position ([CombinatorialRange (1, 3, 1)] int increment, Orientation orientation)
// {
// var top = new Toplevel ()
// {
// Id = "top",
// Width = 10,
// Height = 10
// };
// var scroll = new Scroll
// {
// Id = "scroll",
// Orientation = orientation,
// Size = 20,
// Increment = increment
// };
// top.Add (scroll);
// RunState rs = Application.Begin (top);
// Assert.Equal (0, scroll.GetSliderPosition ());
// Assert.Equal (0, scroll.ContentPosition);
// Application.RaiseMouseEvent (new ()
// {
// ScreenPosition = new (0, 0),
// Flags = orientation == Orientation.Vertical ? MouseFlags.WheeledDown : MouseFlags.WheeledRight
// });
// Application.RunIteration (ref rs);
// Assert.Equal (increment, scroll.ContentPosition);
// Application.RaiseMouseEvent (new ()
// {
// ScreenPosition = new (0, 0),
// Flags = orientation == Orientation.Vertical ? MouseFlags.WheeledDown : MouseFlags.WheeledRight
// });
// Application.RunIteration (ref rs);
// Assert.Equal (increment * 2, scroll.ContentPosition);
// Application.RaiseMouseEvent (new ()
// {
// ScreenPosition = new (0, 0),
// Flags = orientation == Orientation.Vertical ? MouseFlags.WheeledUp : MouseFlags.WheeledLeft
// });
// Application.RunIteration (ref rs);
// Assert.Equal (increment, scroll.ContentPosition);
// Application.ResetState (true);
// }
// [Theory]
// [CombinatorialData]
// [AutoInitShutdown]
// public void Mouse_Click_Outside_Slider_Moves (Orientation orientation)
// {
// var top = new Toplevel ()
// {
// Id = "top",
// Width = 10,
// Height = 10
// };
// var scroll = new Scroll
// {
// Id = "scroll",
// Orientation = orientation,
// Size = 20,
// };
// top.Add (scroll);
// RunState rs = Application.Begin (top);
// scroll.ContentPosition = 5;
// Application.RunIteration (ref rs);
// Assert.Equal (5, scroll.GetSliderPosition ());
// Assert.Equal (10, scroll.ContentPosition);
// Application.RaiseMouseEvent (new ()
// {
// ScreenPosition = new (0, 0),
// Flags = MouseFlags.Button1Clicked
// });
// Application.RunIteration (ref rs);
// Assert.Equal (0, scroll.GetSliderPosition ());
// Assert.Equal (0, scroll.ContentPosition);
// Application.ResetState (true);
// }
// [Theory]
// [CombinatorialData]
// public void Position_Clamps_To_Size (
// [CombinatorialRange (1, 6, 1)] int scrollSize,
// [CombinatorialRange (-1, 6, 1)] int scrollPosition,
// Orientation orientation
// )
// {
// var super = new View
// {
// Id = "super",
// Width = 5,
// Height = 5
// };
// var scroll = new Scroll
// {
// Orientation = orientation,
// Width = Dim.Fill (),
// Height = Dim.Fill ()
// };
// super.Add (scroll);
// scroll.Size = scrollSize;
// super.Layout ();
// scroll.ContentPosition = scrollPosition;
// super.Layout ();
// Assert.True (scroll.GetSliderPosition () <= scrollSize);
// }
// [Fact]
// public void PositionChanging_PositionChanged_Events_Only_Raises_Once_If_Position_Was_Really_Changed ()
// {
// var changing = 0;
// var cancel = false;
// var changed = 0;
// var scroll = new Scroll { Height = 10, Size = 20 };
// scroll.SliderPositionChanged += Scroll_PositionChanged;
// Assert.Equal (Orientation.Vertical, scroll.Orientation);
// scroll.Layout ();
// Assert.Equal (new (0, 0, 1, 10), scroll.Viewport);
// Assert.Equal (0, scroll.GetSliderPosition ());
// Assert.Equal (0, changing);
// Assert.Equal (0, changed);
// scroll.ContentPosition = 0;
// Assert.Equal (0, scroll.GetSliderPosition ());
// Assert.Equal (0, changing);
// Assert.Equal (0, changed);
// scroll.ContentPosition = 1;
// Assert.Equal (1, scroll.GetSliderPosition ());
// Assert.Equal (1, changing);
// Assert.Equal (1, changed);
// Reset ();
// cancel = true;
// scroll.ContentPosition = 2;
// Assert.Equal (1, scroll.GetSliderPosition ());
// Assert.Equal (1, changing);
// Assert.Equal (0, changed);
// Reset ();
// scroll.ContentPosition = 10;
// Assert.Equal (5, scroll.GetSliderPosition ());
// Assert.Equal (1, changing);
// Assert.Equal (1, changed);
// Reset ();
// scroll.ContentPosition = 11;
// Assert.Equal (5, scroll.GetSliderPosition ());
// Assert.Equal (1, changing);
// Assert.Equal (1, changed);
// Reset ();
// scroll.ContentPosition = 0;
// Assert.Equal (0, scroll.GetSliderPosition ());
// Assert.Equal (1, changing);
// Assert.Equal (1, changed);
// scroll.SliderPositionChanged -= Scroll_PositionChanged;
// void Scroll_PositionChanged (object sender, EventArgs<int> e) { changed++; }
// void Reset ()
// {
// changing = 0;
// cancel = false;
// changed = 0;
// }
// }
// [Fact]
// public void Size_Cannot_Be_Negative ()
// {
// var scroll = new Scroll { Height = 10, Size = -1 };
// Assert.Equal (0, scroll.Size);
// scroll.Size = -10;
// Assert.Equal (0, scroll.Size);
// }
// [Fact]
// public void SizeChanged_Event ()
// {
// var count = 0;
// var scroll = new Scroll ();
// scroll.Layout ();
// scroll.SizeChanged += (s, e) => count++;
// scroll.Size = 10;
// Assert.Equal (10, scroll.Size);
// Assert.Equal (1, count);
// }
// [Theory]
// [SetupFakeDriver]
// [InlineData (
// 10,
// 1,
// 20,
// 0,
// Orientation.Horizontal,
// @"
//┌──────────┐
//│█████░░░░░│
//└──────────┘")]
// [InlineData (
// 10,
// 3,
// 20,
// 1,
// Orientation.Horizontal,
// @"
//┌──────────┐
//│░█████░░░░│
//│░█████░░░░│
//│░█████░░░░│
//└──────────┘")]
// [InlineData (
// 3,
// 10,
// 20,
// 0,
// Orientation.Vertical,
// @"
//┌───┐
//│███│
//│███│
//│███│
//│███│
//│███│
//│░░░│
//│░░░│
//│░░░│
//│░░░│
//│░░░│
//└───┘")]
// public void Draws_Correctly (int superViewportWidth, int superViewportHeight, int sliderSize, int sliderPosition, Orientation orientation, string expected)
// {
// var super = new Window
// {
// Id = "super",
// Width = superViewportWidth + 2,
// Height = superViewportHeight + 2
// };
// var scroll = new Scroll
// {
// Orientation = orientation,
// };
// if (orientation == Orientation.Vertical)
// {
// scroll.Width = Dim.Fill ();
// }
// else
// {
// scroll.Height = Dim.Fill ();
// }
// super.Add (scroll);
// scroll.Size = sliderSize;
// scroll.Layout ();
// scroll.ContentPosition = sliderPosition;
// super.BeginInit ();
// super.EndInit ();
// super.Layout ();
// super.Draw ();
// _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
// }
//}