mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 00:46:39 +01:00
Code cleanup
This commit is contained in:
@@ -20,6 +20,26 @@ public partial class View
|
||||
_horizontalScrollBar = new (() => CreateScrollBar (Orientation.Horizontal));
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Causes the scrollbar associated with <paramref name="orientation"/> to be explicitly created.
|
||||
///// </summary>
|
||||
///// <remarks>
|
||||
///// The built-in scrollbars are lazy-created internally. To enable them, the <see cref="VerticalScrollBar"/> or <see cref="HorizontalScrollBar"/>
|
||||
///// need to be referenced. All this method does is reference the associated property.
|
||||
///// </remarks>
|
||||
///// <param name="orientation"></param>
|
||||
//public void EnableScrollBar (Orientation orientation)
|
||||
//{
|
||||
// if (orientation == Orientation.Vertical)
|
||||
// {
|
||||
// _ = VerticalScrollBar; // Explicitly create the vertical scroll bar
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _ = HorizontalScrollBar; // Explicitly create the horizontal scroll bar
|
||||
// }
|
||||
//}
|
||||
|
||||
private ScrollBar CreateScrollBar (Orientation orientation)
|
||||
{
|
||||
var scrollBar = new ScrollBar
|
||||
@@ -37,16 +57,23 @@ public partial class View
|
||||
ConfigureHorizontalScrollBar (scrollBar);
|
||||
}
|
||||
|
||||
Padding?.Add (scrollBar);
|
||||
scrollBar.Initialized += OnScrollBarInitialized;
|
||||
|
||||
Padding?.Add (scrollBar);
|
||||
return scrollBar;
|
||||
}
|
||||
|
||||
private void ConfigureVerticalScrollBar (ScrollBar scrollBar)
|
||||
{
|
||||
scrollBar.X = Pos.AnchorEnd ();
|
||||
scrollBar.Height = Dim.Fill (Dim.Func (() => _horizontalScrollBar is { IsValueCreated: true, Value.Visible: true } ? 1 : 0));
|
||||
scrollBar.Height = Dim.Fill (Dim.Func (() =>
|
||||
{
|
||||
if (_horizontalScrollBar.IsValueCreated)
|
||||
{
|
||||
return _horizontalScrollBar.Value.Visible ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}));
|
||||
scrollBar.ScrollableContentSize = GetContentSize ().Height;
|
||||
|
||||
ViewportChanged += (_, _) =>
|
||||
@@ -64,7 +91,13 @@ public partial class View
|
||||
private void ConfigureHorizontalScrollBar (ScrollBar scrollBar)
|
||||
{
|
||||
scrollBar.Y = Pos.AnchorEnd ();
|
||||
scrollBar.Width = Dim.Fill (Dim.Func (() => _verticalScrollBar is { IsValueCreated: true, Value.Visible: true } ? 1 : 0));
|
||||
scrollBar.Width = Dim.Fill (Dim.Func (() => {
|
||||
if (_verticalScrollBar.IsValueCreated)
|
||||
{
|
||||
return _verticalScrollBar.Value.Visible ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}));
|
||||
scrollBar.ScrollableContentSize = GetContentSize ().Width;
|
||||
|
||||
ViewportChanged += (_, _) =>
|
||||
|
||||
@@ -230,7 +230,7 @@ public class ListView : View, IDesignable
|
||||
|
||||
private void ListView_LayoutComplete (object sender, LayoutEventArgs e)
|
||||
{
|
||||
SetContentSize (new Size (_source?.Length ?? Viewport.Width, _source?.Count ?? Viewport.Width));
|
||||
SetContentSize (new Size (MaxLength, _source?.Count ?? Viewport.Height));
|
||||
}
|
||||
|
||||
/// <summary>Gets or sets whether this <see cref="ListView"/> allows items to be marked.</summary>
|
||||
|
||||
@@ -42,7 +42,10 @@ public class Scrolling : Scenario
|
||||
|
||||
app.Add (demoView);
|
||||
|
||||
demoView.HorizontalScrollBar.Visible = true;
|
||||
//// NOTE: This call to EnableScrollBar is technically not needed because the reference
|
||||
//// NOTE: to demoView.HorizontalScrollBar below will cause it to be lazy created.
|
||||
//// NOTE: The call included in this sample to for illustration purposes.
|
||||
//demoView.EnableScrollBar (Orientation.Horizontal);
|
||||
var hCheckBox = new CheckBox
|
||||
{
|
||||
X = Pos.X (demoView),
|
||||
@@ -56,7 +59,10 @@ public class Scrolling : Scenario
|
||||
demoView.HorizontalScrollBar.Visible = args.CurrentValue == CheckState.Checked;
|
||||
};
|
||||
|
||||
demoView.VerticalScrollBar.Visible = true;
|
||||
//// NOTE: This call to EnableScrollBar is technically not needed because the reference
|
||||
//// NOTE: to demoView.HorizontalScrollBar below will cause it to be lazy created.
|
||||
//// NOTE: The call included in this sample to for illustration purposes.
|
||||
//demoView.EnableScrollBar (Orientation.Vertical);
|
||||
var vCheckBox = new CheckBox
|
||||
{
|
||||
X = Pos.Right (hCheckBox) + 3,
|
||||
|
||||
@@ -799,7 +799,8 @@ public class UICatalogApp
|
||||
CategoryList.OpenSelectedItem += (s, a) => { ScenarioList!.SetFocus (); };
|
||||
CategoryList.SelectedItemChanged += CategoryView_SelectedChanged;
|
||||
|
||||
CategoryList.VerticalScrollBar.AutoHide = true;
|
||||
// This enables the scrollbar by causing lazy instantiation to happen
|
||||
_ = CategoryList.VerticalScrollBar;
|
||||
|
||||
// Create the scenario list. The contents of the scenario list changes whenever the
|
||||
// Category list selection changes (to show just the scenarios that belong to the selected
|
||||
|
||||
Reference in New Issue
Block a user