Implementing nullable bool checked on CheckBox.

This commit is contained in:
BDisp
2023-01-30 14:32:18 +00:00
parent 3d75be4ea6
commit 9d1a429676
24 changed files with 172 additions and 91 deletions

View File

@@ -299,7 +299,7 @@ namespace UICatalog.Tests {
_computedCheckBox.Toggled += (previousState) => {
if (_curView != null) {
_curView.LayoutStyle = previousState ? LayoutStyle.Absolute : LayoutStyle.Computed;
_curView.LayoutStyle = previousState == true ? LayoutStyle.Absolute : LayoutStyle.Computed;
_hostPane.LayoutSubviews ();
}
};

View File

@@ -21,6 +21,7 @@ namespace Terminal.Gui.ViewTests {
var ckb = new CheckBox ();
Assert.True (ckb.AutoSize);
Assert.False (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal (string.Empty, ckb.Text);
Assert.Equal ("╴ ", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
@@ -29,6 +30,7 @@ namespace Terminal.Gui.ViewTests {
ckb = new CheckBox ("Test", true);
Assert.True (ckb.AutoSize);
Assert.True (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
Assert.Equal ("√ Test", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
@@ -37,6 +39,7 @@ namespace Terminal.Gui.ViewTests {
ckb = new CheckBox (1, 2, "Test");
Assert.True (ckb.AutoSize);
Assert.False (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
Assert.Equal ("╴ Test", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
@@ -45,6 +48,7 @@ namespace Terminal.Gui.ViewTests {
ckb = new CheckBox (3, 4, "Test", true);
Assert.True (ckb.AutoSize);
Assert.True (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
Assert.Equal ("√ Test", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
@@ -532,5 +536,36 @@ namespace Terminal.Gui.ViewTests {
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
[Fact, AutoInitShutdown]
public void AllowNullChecked_Get_Set ()
{
var checkBox = new CheckBox ("Check this out 你");
var top = Application.Top;
top.Add (checkBox);
Application.Begin (top);
Assert.False (checkBox.Checked);
Assert.True (checkBox.ProcessKey (new KeyEvent (Key.Space, new KeyModifiers ())));
Assert.True (checkBox.Checked);
Assert.True (checkBox.MouseEvent (new MouseEvent () { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
Assert.False (checkBox.Checked);
checkBox.AllowNullChecked = true;
Assert.True (checkBox.ProcessKey (new KeyEvent (Key.Space, new KeyModifiers ())));
Assert.Null (checkBox.Checked);
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
⍰ Check this out 你", output);
Assert.True (checkBox.MouseEvent (new MouseEvent () { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
Assert.True (checkBox.Checked);
Assert.True (checkBox.ProcessKey (new KeyEvent (Key.Space, new KeyModifiers ())));
Assert.False (checkBox.Checked);
Assert.True (checkBox.MouseEvent (new MouseEvent () { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
Assert.Null (checkBox.Checked);
checkBox.AllowNullChecked = false;
Assert.False (checkBox.Checked);
}
}
}