Browse Source

More autosize related tweaks

Tig 1 year ago
parent
commit
57d4f0dfef
2 changed files with 9 additions and 7 deletions
  1. 6 6
      Terminal.Gui/Views/Scroll.cs
  2. 3 1
      UICatalog/Scenarios/ScrollDemo.cs

+ 6 - 6
Terminal.Gui/Views/Scroll.cs

@@ -21,7 +21,7 @@ public class Scroll : View
         CanFocus = false;
         CanFocus = false;
         Orientation = Orientation.Vertical;
         Orientation = Orientation.Vertical;
         Width = Dim.Auto (DimAutoStyle.Content, 1);
         Width = Dim.Auto (DimAutoStyle.Content, 1);
-        Height = Dim.Auto (DimAutoStyle.Content);
+        Height = Dim.Auto (DimAutoStyle.Content, 1);
 
 
         _slider = new ()
         _slider = new ()
         {
         {
@@ -69,7 +69,7 @@ public class Scroll : View
         get => _position;
         get => _position;
         set
         set
         {
         {
-            int barSize = Orientation == Orientation.Vertical ? Frame.Height : Frame.Width;
+            int barSize = Orientation == Orientation.Vertical ? ContentSize.Height : ContentSize.Width;
 
 
             if (value < 0 || (value > 0 && value + barSize > Size))
             if (value < 0 || (value > 0 && value + barSize > Size))
             {
             {
@@ -232,7 +232,7 @@ public class Scroll : View
     {
     {
         MouseEvent me = e.MouseEvent;
         MouseEvent me = e.MouseEvent;
         int location = Orientation == Orientation.Vertical ? me.Position.Y : me.Position.X;
         int location = Orientation == Orientation.Vertical ? me.Position.Y : me.Position.X;
-        int barSize = Orientation == Orientation.Vertical ? Frame.Height : Frame.Width;
+        int barSize = Orientation == Orientation.Vertical ? ContentSize.Height : ContentSize.Width;
 
 
         (int topLeft, int bottomRight) sliderPos = _orientation == Orientation.Vertical
         (int topLeft, int bottomRight) sliderPos = _orientation == Orientation.Vertical
                                                        ? new (_slider.Frame.Y, _slider.Frame.Bottom - 1)
                                                        ? new (_slider.Frame.Y, _slider.Frame.Bottom - 1)
@@ -285,13 +285,13 @@ public class Scroll : View
         Text = string.Concat (
         Text = string.Concat (
                               Enumerable.Repeat (
                               Enumerable.Repeat (
                                                  Glyphs.Stipple.ToString (),
                                                  Glyphs.Stipple.ToString (),
-                                                 Frame.Width * Frame.Height));
+                                                 ContentSize.Width * ContentSize.Height));
         _slider.TextDirection = Orientation == Orientation.Vertical ? TextDirection.TopBottom_LeftRight : TextDirection.LeftRight_TopBottom;
         _slider.TextDirection = Orientation == Orientation.Vertical ? TextDirection.TopBottom_LeftRight : TextDirection.LeftRight_TopBottom;
 
 
         _slider.Text = string.Concat (
         _slider.Text = string.Concat (
                                       Enumerable.Repeat (
                                       Enumerable.Repeat (
                                                          Glyphs.ContinuousMeterSegment.ToString (),
                                                          Glyphs.ContinuousMeterSegment.ToString (),
-                                                         _slider.Frame.Width * _slider.Frame.Height));
+                                                         _slider.ContentSize.Width * _slider.ContentSize.Height));
     }
     }
 
 
     private void AdjustSlider ()
     private void AdjustSlider ()
@@ -318,7 +318,7 @@ public class Scroll : View
     {
     {
         MouseEvent me = e.MouseEvent;
         MouseEvent me = e.MouseEvent;
         int location = Orientation == Orientation.Vertical ? me.Position.Y : me.Position.X;
         int location = Orientation == Orientation.Vertical ? me.Position.Y : me.Position.X;
-        int barSize = Orientation == Orientation.Vertical ? Frame.Height : Frame.Width;
+        int barSize = Orientation == Orientation.Vertical ? ContentSize.Height : ContentSize.Width;
         int offset = _lastLocation > -1 ? location - _lastLocation : 0;
         int offset = _lastLocation > -1 ? location - _lastLocation : 0;
 
 
         if (me.Flags == MouseFlags.Button1Pressed)
         if (me.Flags == MouseFlags.Button1Pressed)

+ 3 - 1
UICatalog/Scenarios/ScrollDemo.cs

@@ -92,6 +92,7 @@ public class ScrollDemo : Scenario
                                                  {
                                                  {
                                                      scroll.Orientation = Orientation.Vertical;
                                                      scroll.Orientation = Orientation.Vertical;
                                                      scroll.X = Pos.AnchorEnd ();
                                                      scroll.X = Pos.AnchorEnd ();
+                                                     scroll.Y = 0;
                                                      scroll.Width = scrollWidthHeight.Value;
                                                      scroll.Width = scrollWidthHeight.Value;
                                                      scroll.Height = Dim.Fill ();
                                                      scroll.Height = Dim.Fill ();
                                                      scroll.Size /= 3;
                                                      scroll.Size /= 3;
@@ -99,6 +100,7 @@ public class ScrollDemo : Scenario
                                                  else
                                                  else
                                                  {
                                                  {
                                                      scroll.Orientation = Orientation.Horizontal;
                                                      scroll.Orientation = Orientation.Horizontal;
+                                                     scroll.X = 0;
                                                      scroll.Y = Pos.AnchorEnd ();
                                                      scroll.Y = Pos.AnchorEnd ();
                                                      scroll.Width = Dim.Fill ();
                                                      scroll.Width = Dim.Fill ();
                                                      scroll.Height = scrollWidthHeight.Value;
                                                      scroll.Height = scrollWidthHeight.Value;
@@ -218,7 +220,7 @@ public class ScrollDemo : Scenario
         editor.Initialized += (s, e) =>
         editor.Initialized += (s, e) =>
                               {
                               {
                                   scroll.Size = int.Max (app.ContentSize.Height * 2, app.ContentSize.Width * 2);
                                   scroll.Size = int.Max (app.ContentSize.Height * 2, app.ContentSize.Width * 2);
-                                  editor.ViewToEdit = view;
+                                  editor.ViewToEdit = scroll;
                               };
                               };
 
 
         app.Closed += (s, e) => View.Diagnostics = _diagnosticFlags;
         app.Closed += (s, e) => View.Diagnostics = _diagnosticFlags;