Преглед на файлове

SetContentSize -> set_ContentSize

Tig преди 1 година
родител
ревизия
7840cea48c

+ 6 - 2
Terminal.Gui/View/ViewContent.cs

@@ -37,7 +37,7 @@ public partial class View
     ///         Negative sizes are not supported.
     ///     </para>
     /// </param>
-    public void SetContentSize (Size? contentSize)
+    private void SetContentSize (Size? contentSize)
     {
         if (ContentSize.Width < 0 || ContentSize.Height < 0)
         {
@@ -65,7 +65,11 @@ public partial class View
     ///         <see cref="Viewport"/>.
     ///     </para>
     /// </remarks>
-    public Size ContentSize => _contentSize ?? Viewport.Size;
+    public Size ContentSize
+    {
+        get => _contentSize ?? Viewport.Size;
+        set => SetContentSize (value);
+    }
 
     /// <summary>
     /// Called when <see cref="ContentSize"/> has changed.

+ 5 - 5
Terminal.Gui/Views/ColorPicker.cs

@@ -39,7 +39,7 @@ public class ColorPicker : View
 
         Width = Dim.Auto (minimumContentDim: _boxWidth * _cols);
         Height = Dim.Auto (minimumContentDim: _boxHeight * _rows);
-        SetContentSize(new (_boxWidth * _cols, _boxHeight * _rows));
+        ContentSize = new (_boxWidth * _cols, _boxHeight * _rows);
 
         MouseClick += ColorPicker_MouseClick;
     }
@@ -67,7 +67,7 @@ public class ColorPicker : View
                 _boxHeight = value;
                 Width = Dim.Auto (minimumContentDim: _boxWidth * _cols);
                 Height = Dim.Auto (minimumContentDim: _boxHeight * _rows);
-                SetContentSize (new (_boxWidth * _cols, _boxHeight * _rows));
+                ContentSize = new (_boxWidth * _cols, _boxHeight * _rows);
                 SetNeedsLayout ();
             }
         }
@@ -84,7 +84,7 @@ public class ColorPicker : View
                 _boxWidth = value;
                 Width = Dim.Auto (minimumContentDim: _boxWidth * _cols);
                 Height = Dim.Auto (minimumContentDim: _boxHeight * _rows);
-                SetContentSize (new (_boxWidth * _cols, _boxHeight * _rows));
+                ContentSize = new (_boxWidth * _cols, _boxHeight * _rows);
                 SetNeedsLayout ();
             }
         }
@@ -178,9 +178,9 @@ public class ColorPicker : View
         Driver.SetAttribute (HasFocus ? ColorScheme.Focus : GetNormalColor ());
         var colorIndex = 0;
 
-        for (var y = 0; y < Math.Max(2, viewport.Height / BoxHeight); y++)
+        for (var y = 0; y < Math.Max (2, viewport.Height / BoxHeight); y++)
         {
-            for (var x = 0; x < Math.Max(8, viewport.Width / BoxWidth); x++)
+            for (var x = 0; x < Math.Max (8, viewport.Width / BoxWidth); x++)
             {
                 int foregroundColorIndex = y == 0 ? colorIndex + _cols : colorIndex - _cols;
                 Driver.SetAttribute (new Attribute ((ColorName)foregroundColorIndex, (ColorName)colorIndex));

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

@@ -275,7 +275,7 @@ public class DatePicker : View
         Height = Dim.Auto (DimAutoStyle.Content);
 
         // BUGBUG: Remove when Dim.Auto(subviews) fully works
-        SetContentSize (new (_calendar.Style.ColumnStyles.Sum (c => c.Value.MinWidth) + 7, _calendar.Frame.Height + 1));
+        ContentSize = new (_calendar.Style.ColumnStyles.Sum (c => c.Value.MinWidth) + 7, _calendar.Frame.Height + 1);
 
         _dateField.DateChanged += DateField_DateChanged;
 

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

@@ -264,7 +264,7 @@ public class ListView : View
             }
             _source = value;
 
-            SetContentSize (new Size (_source?.Length ?? Viewport.Width, _source?.Count ?? Viewport.Width));
+            ContentSize = new Size (_source?.Length ?? Viewport.Width, _source?.Count ?? Viewport.Width);
             if (IsInitialized)
             {
                 Viewport = Viewport with { Y = 0 };

+ 2 - 2
Terminal.Gui/Views/RadioGroup.cs

@@ -456,7 +456,7 @@ private void SetContentSize ()
                 width = Math.Max (s.GetColumns () + 2, width);
             }
 
-            SetContentSize (new (width, _radioLabels.Count));
+            ContentSize = new (width, _radioLabels.Count);
             break;
 
         case Orientation.Horizontal:
@@ -471,7 +471,7 @@ private void SetContentSize ()
                 length = _radioLabels [i].GetColumns () + 2 + (i < _radioLabels.Count - 1 ? _horizontalSpace : 0);
                 _horizontal.Add ((start, length));
             }
-            SetContentSize (new (_horizontal.Sum (item => item.length), 1));
+            ContentSize = new (_horizontal.Sum (item => item.length), 1);
             break;
     }
 }

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

@@ -464,7 +464,7 @@ public class Slider<T> : View
             CalcSpacingConfig (horizontal ? Viewport.Width : Viewport.Height);
         }
 
-        SetContentSize (new (GetIdealWidth (), GetIdealHeight ()));
+        ContentSize = new (GetIdealWidth (), GetIdealHeight ());
 
         return;
 

+ 1 - 1
UICatalog/Scenarios/ASCIICustomButton.cs

@@ -235,7 +235,7 @@ public class ASCIICustomButtonTest : Scenario
                 pages++;
             }
 
-            _scrollView.SetContentSize (new (25, pages * BUTTONS_ON_PAGE * BUTTON_HEIGHT));
+            _scrollView.ContentSize = new (25, pages * BUTTONS_ON_PAGE * BUTTON_HEIGHT);
 
             if (_smallerWindow)
             {

+ 0 - 3
UICatalog/Scenarios/AllViewsTester.cs

@@ -416,11 +416,8 @@ public class AllViewsTester : Scenario
             return;
         }
 
-        LayoutStyle layout = view.LayoutStyle;
-
         try
         {
-            //view.LayoutStyle = LayoutStyle.Absolute;
 
             view.X = _xRadioGroup.SelectedItem switch
                      {

+ 1 - 1
UICatalog/Scenarios/CharacterMap.cs

@@ -328,7 +328,7 @@ internal class CharMap : View
         CanFocus = true;
         CursorVisibility = CursorVisibility.Default;
 
-        SetContentSize (new (RowWidth, (MaxCodePoint / 16 + 2) * _rowHeight));
+        ContentSize = new (RowWidth, (MaxCodePoint / 16 + 2) * _rowHeight);
 
         AddCommand (
                     Command.ScrollUp,

+ 1 - 1
UICatalog/Scenarios/Clipping.cs

@@ -29,7 +29,7 @@ public class Clipping : Scenario
 
         var scrollView = new ScrollView { X = 3, Y = 3, Width = 50, Height = 20 };
         scrollView.ColorScheme = Colors.ColorSchemes ["Menu"];
-        scrollView.SetContentSize (new (200, 100));
+        scrollView.ContentSize = new (200, 100);
 
         //ContentOffset = Point.Empty,
         scrollView.AutoHideScrollBars = true;

+ 3 - 3
UICatalog/Scenarios/ContentScrolling.cs

@@ -26,7 +26,7 @@ public class ContentScrolling : Scenario
             BorderStyle = LineStyle.Rounded;
             Arrangement = ViewArrangement.Fixed;
 
-            SetContentSize (new (60, 40));
+            ContentSize = new (60, 40);
             ViewportSettings |= ViewportSettings.ClearContentOnly;
             ViewportSettings |= ViewportSettings.ClipContentOnly;
 
@@ -245,7 +245,7 @@ public class ContentScrolling : Scenario
                 return;
             }
 
-            view.SetContentSize (view.ContentSize with { Width = e.NewValue });
+            view.ContentSize = view.ContentSize with { Width = e.NewValue };
         }
 
         var labelComma = new Label
@@ -273,7 +273,7 @@ public class ContentScrolling : Scenario
                 return;
             }
 
-            view.SetContentSize (view.ContentSize with { Height = e.NewValue });
+            view.ContentSize = view.ContentSize with { Height = e.NewValue };
         }
 
         var cbClearOnlyVisible = new CheckBox

+ 1 - 1
UICatalog/Scenarios/Scrolling.cs

@@ -44,7 +44,7 @@ public class Scrolling : Scenario
             ShowVerticalScrollIndicator = true,
             ShowHorizontalScrollIndicator = true
         };
-        scrollView.SetContentSize (new (120, 40));
+        scrollView.ContentSize = new (120, 40);
         scrollView.Padding.Thickness = new (1);
 
         label.Text = $"{scrollView}\nContentSize: {scrollView.ContentSize}\nContentOffset: {scrollView.ContentOffset}";

+ 1 - 1
UnitTests/Application/MouseTests.cs

@@ -236,7 +236,7 @@ public class MouseTests
     {
         var tf = new TextField { Width = 10 };
         var sv = new ScrollView { Width = Dim.Fill (), Height = Dim.Fill () };
-        sv.SetContentSize (new (100, 100));
+        sv.ContentSize = new (100, 100);
 
         sv.Add (tf);
         var top = new Toplevel ();

+ 2 - 21
UnitTests/UICatalog/ScenarioTests.cs

@@ -106,7 +106,6 @@ public class ScenarioTests : TestsAllViews
 
         // Settings
         FrameView _settingsPane;
-        CheckBox _computedCheckBox;
         FrameView _locationFrame;
         RadioGroup _xRadioGroup;
         TextField _xText;
@@ -164,15 +163,13 @@ public class ScenarioTests : TestsAllViews
             ColorScheme = Colors.ColorSchemes ["TopLevel"],
             Title = "Settings"
         };
-        _computedCheckBox = new () { X = 0, Y = 0, Text = "Computed Layout", Checked = true };
-        _settingsPane.Add (_computedCheckBox);
 
         var radioItems = new [] { "Percent(x)", "AnchorEnd(x)", "Center", "Absolute(x)" };
 
         _locationFrame = new ()
         {
-            X = Pos.Left (_computedCheckBox),
-            Y = Pos.Bottom (_computedCheckBox),
+            X = 0,
+            Y = 0,
             Height = 3 + radioItems.Length,
             Width = 36,
             Title = "Location (Pos)"
@@ -249,15 +246,6 @@ public class ScenarioTests : TestsAllViews
                                                   _curView = CreateClass (_viewClasses.Values.ToArray () [_classListView.SelectedItem]);
                                               };
 
-        _computedCheckBox.Toggled += (s, e) =>
-                                     {
-                                         if (_curView != null)
-                                         {
-                                             //_curView.LayoutStyle = e.OldValue == true ? LayoutStyle.Absolute : LayoutStyle.Computed;
-                                             _hostPane.LayoutSubviews ();
-                                         }
-                                     };
-
         _xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
 
         _xText.TextChanged += (s, args) =>
@@ -351,12 +339,8 @@ public class ScenarioTests : TestsAllViews
                 return;
             }
 
-            LayoutStyle layout = view.LayoutStyle;
-
             try
             {
-                //view.LayoutStyle = LayoutStyle.Absolute;
-
                 switch (_xRadioGroup.SelectedItem)
                 {
                     case 0:
@@ -531,9 +515,6 @@ public class ScenarioTests : TestsAllViews
                 view?.GetType ().GetProperty ("Source")?.GetSetMethod ()?.Invoke (view, new [] { source });
             }
 
-            // Set Settings
-            _computedCheckBox.Checked = view.LayoutStyle == LayoutStyle.Computed;
-
             // Add
             _hostPane.Add (view);
 

+ 2 - 2
UnitTests/View/DrawTests.cs

@@ -921,7 +921,7 @@ public class DrawTests (ITestOutputHelper _output)
             Height = Dim.Fill (),
             ViewportSettings = ViewportSettings.ClipContentOnly
         };
-        view.SetContentSize (new Size (10, 10));
+        view.ContentSize = new Size (10, 10);
         view.Border.Thickness = new Thickness (1);
         view.BeginInit ();
         view.EndInit ();
@@ -953,7 +953,7 @@ public class DrawTests (ITestOutputHelper _output)
             Width = Dim.Fill (),
             Height = Dim.Fill (),
         };
-        view.SetContentSize (new Size (10, 10));
+        view.ContentSize = new Size (10, 10);
         view.Border.Thickness = new Thickness (1);
         view.BeginInit ();
         view.EndInit ();

+ 1 - 1
UnitTests/View/FindDeepestViewTests.cs

@@ -470,7 +470,7 @@ public class FindDeepestViewTests ()
         subview.Padding.Thickness = new (1);
 
         // Scroll the subview
-        subview.SetContentSize (new (10, 10));
+        subview.ContentSize = new (10, 10);
         subview.Viewport = subview.Viewport with { Location = new (1, 1) };
 
         // This subview will be at the bottom-right-corner of subview

+ 6 - 6
UnitTests/View/Layout/Dim.AutoTests.cs

@@ -83,7 +83,7 @@ public class DimAutoTests (ITestOutputHelper output)
             ValidatePosDim = true
         };
 
-        view.SetContentSize (new (contentSize, 0));
+        view.ContentSize = new (contentSize, 0);
 
         Assert.Equal (expected, view.Frame.Width);
     }
@@ -102,7 +102,7 @@ public class DimAutoTests (ITestOutputHelper output)
             ValidatePosDim = true
         };
 
-        view.SetContentSize (new (contentSize, 0));
+        view.ContentSize = new (contentSize, 0);
         view.SetRelativeLayout (new (100, 100));
 
         Assert.Equal (expected, view.Frame.Width);
@@ -124,7 +124,7 @@ public class DimAutoTests (ITestOutputHelper output)
             ValidatePosDim = true
         };
 
-        view.SetContentSize (new (contentSize, 0));
+        view.ContentSize = new (contentSize, 0);
         view.SetRelativeLayout (new (100, 100));
 
         Assert.Equal (expected, view.Frame.Width);
@@ -766,7 +766,7 @@ public class DimAutoTests (ITestOutputHelper output)
         var view = new View ();
         view.Width = Auto (DimAutoStyle.Text);
         view.Height = Auto (DimAutoStyle.Text);
-        view.SetContentSize (new (1, 1));
+        view.ContentSize = new (1, 1);
         view.Text = text;
         Assert.Equal (new (expectedW, expectedH), view.TextFormatter.Size);
     }
@@ -963,7 +963,7 @@ public class DimAutoTests (ITestOutputHelper output)
     public void DimAutoStyle_Content_UsesContentSize_WhenSet ()
     {
         var view = new View ();
-        view.SetContentSize (new (10, 5));
+        view.ContentSize = new (10, 5);
 
         var dim = Dim.Auto (DimAutoStyle.Content);
 
@@ -1299,7 +1299,7 @@ public class DimAutoTests (ITestOutputHelper output)
     public void DimAutoStyle_Content_UsesContentSize_If_No_Subviews ()
     {
         DimAutoTestView view = new (Auto (DimAutoStyle.Content), Auto (DimAutoStyle.Content));
-        view.SetContentSize (new (5, 5));
+        view.ContentSize = new (5, 5);
         view.SetRelativeLayout (new (10, 10));
 
         Assert.Equal (new (5, 5), view.Frame.Size);

+ 1 - 1
UnitTests/View/Layout/LayoutTests.cs

@@ -123,7 +123,7 @@ public class LayoutTests (ITestOutputHelper output)
             Width = 5,
             Height = 5,
         };
-        superView.SetContentSize (new (10, 10));
+        superView.ContentSize = new (10, 10);
         var view = new View ()
         {
             X = Pos.Center ()

+ 2 - 2
UnitTests/View/Layout/ScreenToTests.cs

@@ -108,7 +108,7 @@ public class ScreenToTests
             BorderStyle = LineStyle.Single,
         };
         var view = new View { X = viewX, Y = viewY, Width = 5, Height = 5 };
-        view.SetContentSize (new (6, 6));
+        view.ContentSize = new (6, 6);
         super.Add (view);
 
         view.Viewport = new (1, 1, 5, 5);
@@ -164,7 +164,7 @@ public class ScreenToTests
             X = viewX, Y = viewY, Width = 5, Height = 5,
             BorderStyle = LineStyle.Single,
         };
-        view.SetContentSize (new (10, 10));
+        view.ContentSize = new (10, 10);
         super.Add (view);
 
         view.Viewport = view.Viewport with { Location = new (1, 1) };

+ 5 - 5
UnitTests/View/Layout/ToScreenTests.cs

@@ -336,7 +336,7 @@ public class ToScreenTests (ITestOutputHelper output)
             Width = 10,
             Height = 10
         };
-        view.SetContentSize (new (20, 20));
+        view.ContentSize = new (20, 20);
 
         Point testPoint = new (0, 0);
         Assert.Equal (new Point (1, 1), view.ContentToScreen (testPoint));
@@ -362,7 +362,7 @@ public class ToScreenTests (ITestOutputHelper output)
 
         var view = new View ();
         view.Frame = frame;
-        view.SetContentSize (new (20, 20));
+        view.ContentSize = new (20, 20);
         view.BorderStyle = LineStyle.Single;
 
         // Act
@@ -403,7 +403,7 @@ public class ToScreenTests (ITestOutputHelper output)
 
         var view = new View ();
         view.Frame = frame;
-        view.SetContentSize (new (20, 20));
+        view.ContentSize = new (20, 20);
 
         superView.Add (view);
         superView.LayoutSubviews ();
@@ -608,7 +608,7 @@ public class ToScreenTests (ITestOutputHelper output)
 
     //    var view = new View ();
     //    view.Frame = frame;
-    //    view.SetContentSize (new (11, 11));
+    //    view.ContentSize = new (11, 11);
     //    view.Content = view.Content with { Location = new (1, 1) };
 
     //    superView.Add (view);
@@ -928,7 +928,7 @@ public class ToScreenTests (ITestOutputHelper output)
 
         var view = new View ();
         view.Frame = frame;
-        view.SetContentSize (new (11, 11));
+        view.ContentSize = new (11, 11);
         view.Viewport = view.Viewport with { Location = new (1, 1) };
 
         superView.Add (view);

+ 1 - 1
UnitTests/View/Layout/ViewportTests.cs

@@ -279,7 +279,7 @@ public class ViewportTests (ITestOutputHelper output)
     {
         // Arrange
         var view = new View ();
-        view.SetContentSize (new (100, 100));
+        view.ContentSize = new (100, 100);
         var newViewport = new Rectangle (0, 0, 200, 200);
         view.ViewportSettings = ViewportSettings.AllowLocationGreaterThanContentSize;
 

+ 1 - 1
UnitTests/View/TextTests.cs

@@ -32,7 +32,7 @@ public class TextTests (ITestOutputHelper output)
     public void TextFormatter_Size_Tracks_ContentSize (string text, int expectedW, int expectedH)
     {
         var view = new View ();
-        view.SetContentSize(new (1,1));
+        view.ContentSize = new (1,1);
         view.Text = text;
         Assert.Equal (new (expectedW, expectedH), view.TextFormatter.Size);
     }

+ 9 - 9
UnitTests/Views/ScrollViewTests.cs

@@ -12,7 +12,7 @@ public class ScrollViewTests
     public void Adding_Views ()
     {
         var sv = new ScrollView { Width = 20, Height = 10 };
-        sv.SetContentSize (new (30, 20));
+        sv.ContentSize = new (30, 20);
 
         sv.Add (
                 new View { Width = 10, Height = 5 },
@@ -187,7 +187,7 @@ public class ScrollViewTests
             Height = 10,
             KeepContentAlwaysInViewport = false
         };
-        sv.SetContentSize (new (23, 23));
+        sv.ContentSize = new (23, 23);
         var bottomLabel = new Label { X = 15, Y = 15, Text = "At 15,15" };
         var top = new Toplevel ();
         top.Add (topLabel, sv, bottomLabel);
@@ -378,7 +378,7 @@ public class ScrollViewTests
             Height = 5,
             ColorScheme = new ColorScheme { Normal = new Attribute (Color.Red, Color.Green) }
         };
-        sv.SetContentSize (size);
+        sv.ContentSize = size;
         string text = null;
 
         for (var i = 0; i < size.Height; i++)
@@ -447,7 +447,7 @@ public class ScrollViewTests
         {
             Width = 10, Height = 10,
         };
-        sv.SetContentSize (new (50, 50));
+        sv.ContentSize = new (50, 50);
         sv.ContentOffset = new (25, 25);
 
         var top = new Toplevel ();
@@ -482,7 +482,7 @@ public class ScrollViewTests
     public void ContentSize_AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator ()
     {
         var sv = new ScrollView { Width = 10, Height = 10, };
-        sv.SetContentSize (new (50, 50));
+        sv.ContentSize = new (50, 50);
 
         var top = new Toplevel ();
         top.Add (sv);
@@ -546,7 +546,7 @@ public class ScrollViewTests
             ShowHorizontalScrollIndicator = true,
             ShowVerticalScrollIndicator = true
         };
-        scrollView.SetContentSize (size);
+        scrollView.ContentSize = size;
         scrollView.Add (view);
         var win = new Window { X = 1, Y = 1, Width = 20, Height = 14 };
         win.Add (scrollView);
@@ -871,7 +871,7 @@ public class ScrollViewTests
             Width = 10,
             Height = 10,
         };
-        sv.SetContentSize (new (50, 50));
+        sv.ContentSize = new (50, 50);
 
         for (var i = 0; i < 8; i++)
         {
@@ -921,7 +921,7 @@ public class ScrollViewTests
     public void KeyBindings_Command ()
     {
         var sv = new ScrollView { Width = 20, Height = 10, };
-        sv.SetContentSize (new (40, 20));
+        sv.ContentSize = new (40, 20);
 
         sv.Add (
                 new View { Width = 20, Height = 5 },
@@ -1056,7 +1056,7 @@ public class ScrollViewTests
     public void Remove_Added_View_Is_Allowed ()
     {
         var sv = new ScrollView { Width = 20, Height = 20, };
-        sv.SetContentSize (new (100, 100));
+        sv.ContentSize = new (100, 100);
 
         sv.Add (
                 new View { Width = Dim.Fill (), Height = Dim.Fill (50), Id = "View1" },

+ 3 - 3
UnitTests/Views/SliderTests.cs

@@ -519,7 +519,7 @@ public class SliderTests
 
         Assert.Equal (new (6, 3), expectedSize);
 
-        view.SetContentSize (new (1, 1));
+        view.ContentSize = new (1, 1);
 
         view.LayoutSubviews ();
         slider.SetRelativeLayout (view.Viewport.Size);
@@ -552,7 +552,7 @@ public class SliderTests
 
         Assert.Equal (new (6, 10), expectedSize);
 
-        view.SetContentSize (new (1, 1));
+        view.ContentSize = new (1, 1);
 
         view.LayoutSubviews ();
         slider.SetRelativeLayout (view.Viewport.Size);
@@ -585,7 +585,7 @@ public class SliderTests
 
         Assert.Equal (new (10, 3), expectedSize);
 
-        view.SetContentSize (new (1, 1));
+        view.ContentSize = new (1, 1);
 
         view.LayoutSubviews ();
         slider.SetRelativeLayout (view.Viewport.Size);

+ 1 - 1
UnitTests/Views/ToplevelTests.cs

@@ -1321,7 +1321,7 @@ public class ToplevelTests
             Width = 40,
             Height = 16,
         };
-        scrollView.SetContentSize (new (200, 100));
+        scrollView.ContentSize = new (200, 100);
         var win = new Window { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3), Arrangement = ViewArrangement.Movable };
         scrollView.Add (win);
         Toplevel top = new ();