Sfoglia il codice sorgente

Clarified how Viewport works

Tig 1 anno fa
parent
commit
2d5a99abd8

+ 1 - 0
Terminal.Gui/Application.cs

@@ -99,6 +99,7 @@ public static partial class Application
         // Don't dispose the Top. It's up to caller dispose it
         if (Top is { })
         {
+            
             Debug.Assert (Top.WasDisposed);
 
             // If End wasn't called _cachedRunStateToplevel may be null

+ 19 - 13
Terminal.Gui/View/ViewScrolling.cs

@@ -116,7 +116,11 @@ public partial class View
     /// </summary>
     public ScrollSettings ScrollSettings { get; set; }
 
-    private Point _viewportOffset;
+    /// <summary>
+    /// The location of the viewport.in the view's content (0,0) is the top-left corner of the content. It's size
+    /// is <see cref="ContentSize"/>.
+    /// </summary>
+    private Point _viewportLocation;
 
     /// <summary>
     ///     Gets or sets the rectangle describing the portion of the View's content that is visible to the user.
@@ -141,7 +145,7 @@ public partial class View
     ///     </para>
     ///     <para>
     ///         Altering the Viewport Size will eventually (when the view is next laid out) cause the
-    ///         <see cref="LayoutSubview(View, Rectangle)"/> and <see cref="OnDrawContent(Rectangle)"/> methods to be called.
+    ///         <see cref="LayoutSubview(View, Size)"/> and <see cref="OnDrawContent(Rectangle)"/> methods to be called.
     ///     </para>
     /// </remarks>
     public virtual Rectangle Viewport
@@ -160,30 +164,32 @@ public partial class View
             if (Margin is null || Border is null || Padding is null)
             {
                 // CreateAdornments has not been called yet.
-                return new (_viewportOffset, Frame.Size);
+                return new (_viewportLocation, Frame.Size);
             }
 
-            Thickness totalThickness = GetAdornmentsThickness ();
+            Thickness thickness = GetAdornmentsThickness ();
 
-            return new (
-                        _viewportOffset,
-                        new (
-                             Math.Max (0, Frame.Size.Width - totalThickness.Horizontal),
-                             Math.Max (0, Frame.Size.Height - totalThickness.Vertical)));
+            return new (_viewportLocation, new (
+                                                Math.Max (0, Frame.Size.Width - thickness.Horizontal),
+                                                Math.Max (0, Frame.Size.Height - thickness.Vertical)
+                                                ));
         }
         set
         {
-            _viewportOffset = value.Location;
+            _viewportLocation = value.Location;
 
-            Thickness totalThickness = GetAdornmentsThickness ();
-            Size newSize = new (value.Size.Width + totalThickness.Horizontal,
-                                value.Size.Height + totalThickness.Vertical);
+            Thickness thickness = GetAdornmentsThickness ();
+            Size newSize = new (value.Size.Width + thickness.Horizontal,
+                                value.Size.Height + thickness.Vertical);
             if (newSize == Frame.Size)
             {
+                // The change is not changing the Frame, so we don't need to update it. 
+                // Just call SetRelativeLayout6 to update the layout.
                 SetNeedsLayout ();
                 return;
             }
 
+            // Update the Frame because we made it bigger or smaller which impacts subviews.
             Frame = Frame with
             {
                 Size = newSize

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

@@ -1073,7 +1073,7 @@ public class Slider<T> : View
     private void DrawSlider ()
     {
         // TODO: be more surgical on clear
-        Clear (Viewport);
+        ClearVisibleContent ();
 
         // Attributes
 

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

@@ -662,7 +662,7 @@ public class TabView : View
             _host._tabLocations = _host.CalculateViewport (Viewport).ToArray ();
 
             // clear any old text
-            Clear (viewport);
+            ClearVisibleContent ();
 
             RenderTabLine ();
 

+ 0 - 1
Terminal.Gui/Views/TileView.cs

@@ -182,7 +182,6 @@ public class TileView : View
     public override void OnDrawContent (Rectangle viewport)
     {
         Driver.SetAttribute (ColorScheme.Normal);
-        Clear (viewport);
 
         base.OnDrawContent (viewport);
 

+ 1 - 0
Terminal.Gui/Views/Toplevel.cs

@@ -380,6 +380,7 @@ public partial class Toplevel : View
     /// <param name="top">The Toplevel to adjust.</param>
     public virtual void PositionToplevel (Toplevel top)
     {
+        
         View superView = GetLocationEnsuringFullVisibility (
                                               top,
                                               top.Frame.X,

+ 3 - 2
UICatalog/Scenarios/Clipping.cs

@@ -30,8 +30,9 @@ public class Clipping : Scenario
         scrollView.ContentSize = new (200, 100);
 
         //ContentOffset = Point.Empty,
-        //scrollView.ShowVerticalScrollIndicator = true;
-        //scrollView.ShowHorizontalScrollIndicator = true;
+        scrollView.AutoHideScrollBars = true;
+        scrollView.ShowVerticalScrollIndicator = true;
+        scrollView.ShowHorizontalScrollIndicator = true;
 
         var embedded1 = new View
         {

+ 66 - 59
UICatalog/Scenarios/VirtualContentScrolling.cs

@@ -12,19 +12,19 @@ public class VirtualScrolling : Scenario
 {
     private ViewDiagnosticFlags _diagnosticFlags;
 
-    public class VirtualDemoView : View
+    public class VirtualDemoView : Window
     {
         public VirtualDemoView ()
         {
-            Text = "Virtual Demo View Text. This is long text.\nThe second line.\n3\n4\n5th line.";
+            Text = "Virtual Demo View Text. This is long text.\nThe second line.\n3\n4\n5th line\nLine 6. This is a longer line. fklasjf laspi fiolasjf liasdj flpasfjklas.";
             CanFocus = true;
             Arrangement = ViewArrangement.Movable;
-            ColorScheme = Colors.ColorSchemes ["Toplevel"];
-            BorderStyle = LineStyle.Rounded;
+            ColorScheme = Colors.ColorSchemes ["Error"];
+            BorderStyle = LineStyle.None;
 
             // TODO: Add a way to set the scroll settings in the Scenario
             ContentSize = new Size (100, 60);
-            //ScrollSettings = ScrollSettings.NoRestrict;
+            ScrollSettings = ScrollSettings.NoRestrict;
 
             // Things this view knows how to do
             AddCommand (Command.ScrollDown, () => ScrollVertical (1));
@@ -102,59 +102,66 @@ public class VirtualScrolling : Scenario
 
         var view = new VirtualDemoView { Title = "Virtual Scrolling" };
 
-        var tf1 = new TextField { X = 20, Y = 7, Width = 10, Text = "TextField" };
-        var color = new ColorPicker { Title = "BG", BoxHeight = 1, BoxWidth = 1, X = Pos.AnchorEnd (11) };
-        color.BorderStyle = LineStyle.RoundedDotted;
-
-        color.ColorChanged += (s, e) =>
-                              {
-                                  color.SuperView.ColorScheme = new (color.SuperView.ColorScheme)
-                                  {
-                                      Normal = new (
-                                                    color.SuperView.ColorScheme.Normal.Foreground,
-                                                    e.Color
-                                                   )
-                                  };
-                              };
-
-        var button = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Centered Button" };
-
-        button.Accept += (s, e) =>
-                             MessageBox.Query (20, 7, "Hi", $"Am I a {view.GetType ().Name}?", "Yes", "No");
-
-        var label = new TextView
-        {
-            X = Pos.Center (),
-            Y = 10,
-            Title = "Title",
-            Text = "I have a 3 row top border.\nMy border inherits from the SuperView.",
-            AllowsTab = false,
-            Width = 42,
-            Height = 6 // TODO: Use Dim.Auto
-        };
-        label.Border.Thickness = new (1, 3, 1, 1);
-
-        var btnButtonInWindow = new Button { X = Pos.AnchorEnd (10), Y = Pos.AnchorEnd (1), Text = "Button" };
-
-        var tv = new Label
-        {
-            AutoSize = false,
-            Y = Pos.AnchorEnd (3),
-            Width = 25,
-            Height = Dim.Fill (),
-            Text = "Label\nY=AnchorEnd(3),Height=Dim.Fill()"
-        };
-
-        view.Margin.Data = "Margin";
-        view.Margin.Thickness = new (0);
-
-        view.Border.Data = "Border";
-        view.Border.Thickness = new (3);
-
-        view.Padding.Data = "Padding";
-        view.Padding.Thickness = new (3);
-
-        view.Add (tf1, color, button, label, btnButtonInWindow, tv);
+       // var tf1 = new TextField { X = 20, Y = 7, Width = 10, Text = "TextField" };
+        //var color = new ColorPicker { Title = "BG", BoxHeight = 1, BoxWidth = 1, X = Pos.AnchorEnd (11) };
+        //color.BorderStyle = LineStyle.RoundedDotted;
+
+        //color.ColorChanged += (s, e) =>
+        //                      {
+        //                          color.SuperView.ColorScheme = new (color.SuperView.ColorScheme)
+        //                          {
+        //                              Normal = new (
+        //                                            color.SuperView.ColorScheme.Normal.Foreground,
+        //                                            e.Color
+        //                                           )
+        //                          };
+        //                      };
+
+        //var button = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Centered Button" };
+
+        //button.Accept += (s, e) =>
+        //                     MessageBox.Query (20, 7, "Hi", $"Am I a {view.GetType ().Name}?", "Yes", "No");
+
+        //var label = new TextView
+        //{
+        //    X = Pos.Center (),
+        //    Y = 10,
+        //    Title = "Title",
+        //    Text = "I have a 3 row top border.\nMy border inherits from the SuperView.",
+        //    AllowsTab = false,
+        //    Width = 42,
+        //    Height = 6 // TODO: Use Dim.Auto
+        //};
+        //label.Border.Thickness = new (1, 3, 1, 1);
+
+        //var btnButtonInWindow = new Button { X = Pos.AnchorEnd (10), Y = Pos.AnchorEnd (1), Text = "Button" };
+
+        //var tv = new Label
+        //{
+        //    AutoSize = false,
+        //    Y = Pos.AnchorEnd (3),
+        //    Width = 25,
+        //    Height = Dim.Fill (),
+        //    Text = "Label\nY=AnchorEnd(3),Height=Dim.Fill()"
+        //};
+
+        //view.Margin.Data = "Margin";
+        //view.Margin.Thickness = new (0);
+
+        //view.Border.Data = "Border";
+        //view.Border.Thickness = new (3);
+
+        //view.Padding.Data = "Padding";
+        //view.Padding.Thickness = new (3);
+
+        //view.Add (tf1, color, button, label, btnButtonInWindow, tv);
+        //var label = new Label
+        //{
+        //    X = 0,
+        //    Y = 10,
+        //    Text = "This is a virtual scrolling demo. Use the arrow keys to scroll the content."
+        //};
+        //view.Add (label);
 
         var editor = new Adornments.AdornmentsEditor
         {
@@ -172,7 +179,7 @@ public class VirtualScrolling : Scenario
 
         view.Width = Dim.Fill ();
         view.Height = Dim.Fill ();
-        Application.Run (editor);
+        Application.Run (view);
         editor.Dispose ();
         Application.Shutdown ();
     }