Fixed AllViewsTester

This commit is contained in:
Tig
2024-05-03 13:32:33 -06:00
parent be8f7fadc6
commit 7dedfb83e8
8 changed files with 53 additions and 79 deletions

View File

@@ -79,7 +79,7 @@ public class LoginView : Window, IViewFor<LoginViewModel>
var loginProgressLabel = new Label 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 ViewModel

View File

@@ -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 _max = max;
internal readonly Dim _min = min; internal readonly Dim _min = min;

View File

@@ -136,7 +136,14 @@ public partial class View
/// <para>Gets the thickness describing the sum of the Adornments' thicknesses.</para> /// <para>Gets the thickness describing the sum of the Adornments' thicknesses.</para>
/// </summary> /// </summary>
/// <returns>A thickness that describes the sum of the Adornments' thicknesses.</returns> /// <returns>A thickness that describes the sum of the Adornments' thicknesses.</returns>
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;
}
/// <summary>Lays out the Adornments of the View.</summary> /// <summary>Lays out the Adornments of the View.</summary>
/// <remarks> /// <remarks>

View File

@@ -208,7 +208,7 @@ public class AllViewsTester : Scenario
Title = "Size (Dim)" 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:" }; label = new Label { X = 0, Y = 0, Text = "Width:" };
_sizeFrame.Add (label); _sizeFrame.Add (label);
_wRadioGroup = new RadioGroup { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems }; _wRadioGroup = new RadioGroup { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems };
@@ -221,12 +221,13 @@ public class AllViewsTester : Scenario
{ {
switch (_wRadioGroup.SelectedItem) switch (_wRadioGroup.SelectedItem)
{ {
case 0: case 1:
_wVal = Math.Min (int.Parse (_wText.Text), 100); _wVal = Math.Min (int.Parse (_wText.Text), 100);
break; break;
case 1: case 0:
case 2: case 2:
case 3:
_wVal = int.Parse (_wText.Text); _wVal = int.Parse (_wText.Text);
break; break;
@@ -240,7 +241,7 @@ public class AllViewsTester : Scenario
_sizeFrame.Add (_wText); _sizeFrame.Add (_wText);
_sizeFrame.Add (_wRadioGroup); _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:" }; label = new Label { X = Pos.Right (_wRadioGroup) + 1, Y = 0, Text = "Height:" };
_sizeFrame.Add (label); _sizeFrame.Add (label);
_hText = new TextField { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_hVal}" }; _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) switch (_hRadioGroup.SelectedItem)
{ {
case 0: case 1:
_hVal = Math.Min (int.Parse (_hText.Text), 100); _hVal = Math.Min (int.Parse (_hText.Text), 100);
break; break;
case 1: case 0:
case 2: case 2:
case 3:
_hVal = int.Parse (_hText.Text); _hVal = int.Parse (_hText.Text);
break; break;
@@ -386,38 +388,40 @@ public class AllViewsTester : Scenario
//view.LayoutStyle = LayoutStyle.Absolute; //view.LayoutStyle = LayoutStyle.Absolute;
view.X = _xRadioGroup.SelectedItem switch view.X = _xRadioGroup.SelectedItem switch
{ {
0 => Pos.Percent (_xVal), 0 => Pos.Percent (_xVal),
1 => Pos.AnchorEnd (), 1 => Pos.AnchorEnd (),
2 => Pos.Center (), 2 => Pos.Center (),
3 => Pos.At (_xVal), 3 => Pos.At (_xVal),
_ => view.X _ => view.X
}; };
view.Y = _yRadioGroup.SelectedItem switch view.Y = _yRadioGroup.SelectedItem switch
{ {
0 => Pos.Percent (_yVal), 0 => Pos.Percent (_yVal),
1 => Pos.AnchorEnd (), 1 => Pos.AnchorEnd (),
2 => Pos.Center (), 2 => Pos.Center (),
3 => Pos.At (_yVal), 3 => Pos.At (_yVal),
_ => view.Y _ => view.Y
}; };
view.Width = _wRadioGroup.SelectedItem switch view.Width = _wRadioGroup.SelectedItem switch
{ {
0 => Dim.Percent (_wVal), 0 => Dim.Auto (min: _wVal),
1 => Dim.Fill (_wVal), 1 => Dim.Percent (_wVal),
2 => Dim.Sized (_wVal), 2 => Dim.Fill (_wVal),
_ => view.Width 3 => Dim.Sized (_wVal),
}; _ => view.Width
};
view.Height = _hRadioGroup.SelectedItem switch view.Height = _hRadioGroup.SelectedItem switch
{ {
0 => Dim.Percent (_hVal), 0 => Dim.Auto (min: _hVal),
1 => Dim.Fill (_hVal), 1 => Dim.Percent (_hVal),
2 => Dim.Sized (_hVal), 2 => Dim.Fill (_hVal),
_ => view.Height 3 => Dim.Sized (_hVal),
}; _ => view.Height
};
} }
catch (Exception e) catch (Exception e)
{ {
@@ -476,14 +480,17 @@ public class AllViewsTester : Scenario
{ {
var view = sender as View; var view = sender as View;
//view.X = Pos.Center (); if (view is null)
//view.Y = Pos.Center (); {
if (view.Width == null || view.Frame.Width == 0) return;
}
if (view.Width is not Dim.DimAuto && (view.Width is null || view.Frame.Width == 0))
{ {
view.Width = Dim.Fill (); 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 (); view.Height = Dim.Fill ();
} }

View File

@@ -972,7 +972,6 @@ internal class CharMap : View
var errorLabel = new Label var errorLabel = new Label
{ {
Text = UcdApiClient.BaseUrl, Text = UcdApiClient.BaseUrl,
AutoSize = false,
X = 0, X = 0,
Y = 1, Y = 1,
Width = Dim.Fill (), Width = Dim.Fill (),

View File

@@ -44,7 +44,6 @@ public class Dialogs : Scenario
label = new Label label = new Label
{ {
AutoSize = false,
X = 0, X = 0,
Y = Pos.Bottom (label), Y = Pos.Bottom (label),
Width = Dim.Width (numButtonsLabel), Width = Dim.Width (numButtonsLabel),

View File

@@ -850,38 +850,6 @@ public class DimAutoTests (ITestOutputHelper output)
Assert.Equal (new Size (5, 1), view.ContentSize); 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 // DimAutoStyle.Content tests
[Fact] [Fact]

View File

@@ -406,7 +406,6 @@ public class DimTests
var v1 = new Button var v1 = new Button
{ {
AutoSize = false,
X = Pos.X (f1) + 2, X = Pos.X (f1) + 2,
Y = Pos.Bottom (f1) + 2, Y = Pos.Bottom (f1) + 2,
Width = Dim.Width (f1) - 2, Width = Dim.Width (f1) - 2,
@@ -417,7 +416,6 @@ public class DimTests
var v2 = new Button var v2 = new Button
{ {
AutoSize = false,
X = Pos.X (f2) + 2, X = Pos.X (f2) + 2,
Y = Pos.Bottom (f2) + 2, Y = Pos.Bottom (f2) + 2,
Width = Dim.Width (f2) - 2, Width = Dim.Width (f2) - 2,
@@ -428,7 +426,6 @@ public class DimTests
var v3 = new Button var v3 = new Button
{ {
AutoSize = false,
Width = Dim.Percent (10), Width = Dim.Percent (10),
Height = Dim.Percent (10), Height = Dim.Percent (10),
ValidatePosDim = true, ValidatePosDim = true,
@@ -437,7 +434,6 @@ public class DimTests
var v4 = new Button var v4 = new Button
{ {
AutoSize = false,
Width = Dim.Sized (50), Width = Dim.Sized (50),
Height = Dim.Sized (50), Height = Dim.Sized (50),
ValidatePosDim = true, ValidatePosDim = true,
@@ -446,7 +442,6 @@ public class DimTests
var v5 = new Button var v5 = new Button
{ {
AutoSize = false,
Width = Dim.Width (v1) - Dim.Width (v3), Width = Dim.Width (v1) - Dim.Width (v3),
Height = Dim.Height (v1) - Dim.Height (v3), Height = Dim.Height (v1) - Dim.Height (v3),
ValidatePosDim = true, ValidatePosDim = true,
@@ -455,7 +450,6 @@ public class DimTests
var v6 = new Button var v6 = new Button
{ {
AutoSize = false,
X = Pos.X (f2), X = Pos.X (f2),
Y = Pos.Bottom (f2) + 2, Y = Pos.Bottom (f2) + 2,
Width = Dim.Percent (20, true), Width = Dim.Percent (20, true),