diff --git a/ReactiveExample/LoginView.cs b/ReactiveExample/LoginView.cs index 4f057cb17..154bfbece 100644 --- a/ReactiveExample/LoginView.cs +++ b/ReactiveExample/LoginView.cs @@ -79,7 +79,7 @@ public class LoginView : Window, IViewFor var loginProgressLabel = new Label { - AutoSize = false, X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40, Height = 1, Text = idle + X = Pos.Left (previous), Y = Pos.Top (previous) + 1, Width = 40, Height = 1, Text = idle }; ViewModel diff --git a/Terminal.Gui/View/Layout/PosDim.cs b/Terminal.Gui/View/Layout/PosDim.cs index 94fa1c6cf..cb1b01a02 100644 --- a/Terminal.Gui/View/Layout/PosDim.cs +++ b/Terminal.Gui/View/Layout/PosDim.cs @@ -917,7 +917,7 @@ public class Dim } } - internal class DimAuto (DimAutoStyle style, Dim min, Dim max) : Dim + public class DimAuto (DimAutoStyle style, Dim min, Dim max) : Dim { internal readonly Dim _max = max; internal readonly Dim _min = min; diff --git a/Terminal.Gui/View/ViewAdornments.cs b/Terminal.Gui/View/ViewAdornments.cs index 4efd92b52..37355a2cf 100644 --- a/Terminal.Gui/View/ViewAdornments.cs +++ b/Terminal.Gui/View/ViewAdornments.cs @@ -136,7 +136,14 @@ public partial class View /// Gets the thickness describing the sum of the Adornments' thicknesses. /// /// A thickness that describes the sum of the Adornments' thicknesses. - public Thickness GetAdornmentsThickness () { return Margin.Thickness + Border.Thickness + Padding.Thickness; } + public Thickness GetAdornmentsThickness () + { + if (Margin is null) + { + return Thickness.Empty; + } + return Margin.Thickness + Border.Thickness + Padding.Thickness; + } /// Lays out the Adornments of the View. /// diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 37b8dfff7..1a72616ec 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -208,7 +208,7 @@ public class AllViewsTester : Scenario Title = "Size (Dim)" }; - radioItems = new [] { "Auto", "_Percent(width)", "_Fill(width)", "_Sized(width)" }; + radioItems = new [] { "Auto (min)", "_Percent(width)", "_Fill(width)", "_Sized(width)" }; label = new Label { X = 0, Y = 0, Text = "Width:" }; _sizeFrame.Add (label); _wRadioGroup = new RadioGroup { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems }; @@ -221,12 +221,13 @@ public class AllViewsTester : Scenario { switch (_wRadioGroup.SelectedItem) { - case 0: + case 1: _wVal = Math.Min (int.Parse (_wText.Text), 100); break; - case 1: + case 0: case 2: + case 3: _wVal = int.Parse (_wText.Text); break; @@ -240,7 +241,7 @@ public class AllViewsTester : Scenario _sizeFrame.Add (_wText); _sizeFrame.Add (_wRadioGroup); - radioItems = new [] { "_Auto", "P_ercent(height)", "F_ill(height)", "Si_zed(height)" }; + radioItems = new [] { "_Auto (min)", "P_ercent(height)", "F_ill(height)", "Si_zed(height)" }; label = new Label { X = Pos.Right (_wRadioGroup) + 1, Y = 0, Text = "Height:" }; _sizeFrame.Add (label); _hText = new TextField { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_hVal}" }; @@ -251,12 +252,13 @@ public class AllViewsTester : Scenario { switch (_hRadioGroup.SelectedItem) { - case 0: + case 1: _hVal = Math.Min (int.Parse (_hText.Text), 100); break; - case 1: + case 0: case 2: + case 3: _hVal = int.Parse (_hText.Text); break; @@ -386,38 +388,40 @@ public class AllViewsTester : Scenario //view.LayoutStyle = LayoutStyle.Absolute; view.X = _xRadioGroup.SelectedItem switch - { - 0 => Pos.Percent (_xVal), - 1 => Pos.AnchorEnd (), - 2 => Pos.Center (), - 3 => Pos.At (_xVal), - _ => view.X - }; + { + 0 => Pos.Percent (_xVal), + 1 => Pos.AnchorEnd (), + 2 => Pos.Center (), + 3 => Pos.At (_xVal), + _ => view.X + }; view.Y = _yRadioGroup.SelectedItem switch - { - 0 => Pos.Percent (_yVal), - 1 => Pos.AnchorEnd (), - 2 => Pos.Center (), - 3 => Pos.At (_yVal), - _ => view.Y - }; + { + 0 => Pos.Percent (_yVal), + 1 => Pos.AnchorEnd (), + 2 => Pos.Center (), + 3 => Pos.At (_yVal), + _ => view.Y + }; view.Width = _wRadioGroup.SelectedItem switch - { - 0 => Dim.Percent (_wVal), - 1 => Dim.Fill (_wVal), - 2 => Dim.Sized (_wVal), - _ => view.Width - }; + { + 0 => Dim.Auto (min: _wVal), + 1 => Dim.Percent (_wVal), + 2 => Dim.Fill (_wVal), + 3 => Dim.Sized (_wVal), + _ => view.Width + }; view.Height = _hRadioGroup.SelectedItem switch - { - 0 => Dim.Percent (_hVal), - 1 => Dim.Fill (_hVal), - 2 => Dim.Sized (_hVal), - _ => view.Height - }; + { + 0 => Dim.Auto (min: _hVal), + 1 => Dim.Percent (_hVal), + 2 => Dim.Fill (_hVal), + 3 => Dim.Sized (_hVal), + _ => view.Height + }; } catch (Exception e) { @@ -476,14 +480,17 @@ public class AllViewsTester : Scenario { var view = sender as View; - //view.X = Pos.Center (); - //view.Y = Pos.Center (); - if (view.Width == null || view.Frame.Width == 0) + if (view is null) + { + return; + } + + if (view.Width is not Dim.DimAuto && (view.Width is null || view.Frame.Width == 0)) { view.Width = Dim.Fill (); } - if (view.Height == null || view.Frame.Height == 0) + if (view.Width is not Dim.DimAuto && (view.Height is null || view.Frame.Height == 0)) { view.Height = Dim.Fill (); } diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index cb9685fa6..69c3ab1fe 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -972,7 +972,6 @@ internal class CharMap : View var errorLabel = new Label { Text = UcdApiClient.BaseUrl, - AutoSize = false, X = 0, Y = 1, Width = Dim.Fill (), diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index 68e75b99b..869d71226 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -44,7 +44,6 @@ public class Dialogs : Scenario label = new Label { - AutoSize = false, X = 0, Y = Pos.Bottom (label), Width = Dim.Width (numButtonsLabel), diff --git a/UnitTests/View/Layout/Dim.AutoTests.cs b/UnitTests/View/Layout/Dim.AutoTests.cs index 8d354e86d..ed2500877 100644 --- a/UnitTests/View/Layout/Dim.AutoTests.cs +++ b/UnitTests/View/Layout/Dim.AutoTests.cs @@ -850,38 +850,6 @@ public class DimAutoTests (ITestOutputHelper output) Assert.Equal (new Size (5, 1), view.ContentSize); } - [SetupFakeDriver] - [Fact] - public void DimAuto_ChangeNonDimAuto_Via_AutoSize_False_Resets_ContentSize () - { - View view = new () - { - Width = Auto (), - Height = Auto (), - Text = "01234" - }; - - Assert.Equal (new Rectangle (0, 0, 5, 1), view.Frame); - Assert.Equal (new Size (5, 1), view.ContentSize); - - // Change text to a longer string - view.Text = "0123456789"; - - Assert.Equal (new Rectangle (0, 0, 10, 1), view.Frame); - Assert.Equal (new Size (10, 1), view.ContentSize); - - // Cause Width/Height to be set to absolute. This should reset ContentSize - view.AutoSize = false; - - Assert.Equal (new Rectangle (0, 0, 10, 1), view.Frame); - Assert.Equal (new Size (10, 1), view.ContentSize); - - // If ContentSize was reset, these should cause it to update - view.Width = 5; - view.Height = 1; - - Assert.Equal (new Size (5, 1), view.ContentSize); - } // DimAutoStyle.Content tests [Fact] diff --git a/UnitTests/View/Layout/Dim.Tests.cs b/UnitTests/View/Layout/Dim.Tests.cs index 6e5e9bbd3..8f57602dd 100644 --- a/UnitTests/View/Layout/Dim.Tests.cs +++ b/UnitTests/View/Layout/Dim.Tests.cs @@ -406,7 +406,6 @@ public class DimTests var v1 = new Button { - AutoSize = false, X = Pos.X (f1) + 2, Y = Pos.Bottom (f1) + 2, Width = Dim.Width (f1) - 2, @@ -417,7 +416,6 @@ public class DimTests var v2 = new Button { - AutoSize = false, X = Pos.X (f2) + 2, Y = Pos.Bottom (f2) + 2, Width = Dim.Width (f2) - 2, @@ -428,7 +426,6 @@ public class DimTests var v3 = new Button { - AutoSize = false, Width = Dim.Percent (10), Height = Dim.Percent (10), ValidatePosDim = true, @@ -437,7 +434,6 @@ public class DimTests var v4 = new Button { - AutoSize = false, Width = Dim.Sized (50), Height = Dim.Sized (50), ValidatePosDim = true, @@ -446,7 +442,6 @@ public class DimTests var v5 = new Button { - AutoSize = false, Width = Dim.Width (v1) - Dim.Width (v3), Height = Dim.Height (v1) - Dim.Height (v3), ValidatePosDim = true, @@ -455,7 +450,6 @@ public class DimTests var v6 = new Button { - AutoSize = false, X = Pos.X (f2), Y = Pos.Bottom (f2) + 2, Width = Dim.Percent (20, true),