Tig 8 mēneši atpakaļ
vecāks
revīzija
bc46801a6a

+ 36 - 3
Terminal.Gui/View/View.ScrollBars.cs

@@ -20,6 +20,26 @@ public partial class View
         _horizontalScrollBar = new (() => CreateScrollBar (Orientation.Horizontal));
         _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)
     private ScrollBar CreateScrollBar (Orientation orientation)
     {
     {
         var scrollBar = new ScrollBar
         var scrollBar = new ScrollBar
@@ -37,16 +57,23 @@ public partial class View
             ConfigureHorizontalScrollBar (scrollBar);
             ConfigureHorizontalScrollBar (scrollBar);
         }
         }
 
 
-        Padding?.Add (scrollBar);
         scrollBar.Initialized += OnScrollBarInitialized;
         scrollBar.Initialized += OnScrollBarInitialized;
 
 
+        Padding?.Add (scrollBar);
         return scrollBar;
         return scrollBar;
     }
     }
 
 
     private void ConfigureVerticalScrollBar (ScrollBar scrollBar)
     private void ConfigureVerticalScrollBar (ScrollBar scrollBar)
     {
     {
         scrollBar.X = Pos.AnchorEnd ();
         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;
         scrollBar.ScrollableContentSize = GetContentSize ().Height;
 
 
         ViewportChanged += (_, _) =>
         ViewportChanged += (_, _) =>
@@ -64,7 +91,13 @@ public partial class View
     private void ConfigureHorizontalScrollBar (ScrollBar scrollBar)
     private void ConfigureHorizontalScrollBar (ScrollBar scrollBar)
     {
     {
         scrollBar.Y = Pos.AnchorEnd ();
         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;
         scrollBar.ScrollableContentSize = GetContentSize ().Width;
 
 
         ViewportChanged += (_, _) =>
         ViewportChanged += (_, _) =>

+ 1 - 1
Terminal.Gui/Views/ListView.cs

@@ -230,7 +230,7 @@ public class ListView : View, IDesignable
 
 
     private void ListView_LayoutComplete (object sender, LayoutEventArgs e)
     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>
     /// <summary>Gets or sets whether this <see cref="ListView"/> allows items to be marked.</summary>

+ 8 - 2
UICatalog/Scenarios/Scrolling.cs

@@ -42,7 +42,10 @@ public class Scrolling : Scenario
 
 
         app.Add (demoView);
         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
         var hCheckBox = new CheckBox
         {
         {
             X = Pos.X (demoView),
             X = Pos.X (demoView),
@@ -56,7 +59,10 @@ public class Scrolling : Scenario
                                              demoView.HorizontalScrollBar.Visible = args.CurrentValue == CheckState.Checked;
                                              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
         var vCheckBox = new CheckBox
         {
         {
             X = Pos.Right (hCheckBox) + 3,
             X = Pos.Right (hCheckBox) + 3,

+ 2 - 1
UICatalog/UICatalog.cs

@@ -799,7 +799,8 @@ public class UICatalogApp
             CategoryList.OpenSelectedItem += (s, a) => { ScenarioList!.SetFocus (); };
             CategoryList.OpenSelectedItem += (s, a) => { ScenarioList!.SetFocus (); };
             CategoryList.SelectedItemChanged += CategoryView_SelectedChanged;
             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
             // 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
             // Category list selection changes (to show just the scenarios that belong to the selected