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

@@ -1077,6 +1077,11 @@ namespace Terminal.Gui {
/// </summary>
public Rune UnChecked = '\u2574';
/// <summary>
/// Null-checked checkmark.
/// </summary>
public Rune NullChecked = '\u2370';
/// <summary>
/// Selected mark.
/// </summary>

View File

@@ -13,9 +13,11 @@ namespace Terminal.Gui {
/// The <see cref="CheckBox"/> <see cref="View"/> shows an on/off toggle that the user can set
/// </summary>
public class CheckBox : View {
Rune charNullChecked;
Rune charChecked;
Rune charUnChecked;
bool @checked;
bool? @checked;
bool allowNullChecked;
/// <summary>
/// Toggled event, raised when the <see cref="CheckBox"/> is toggled.
@@ -25,12 +27,12 @@ namespace Terminal.Gui {
/// raised when the <see cref="CheckBox"/> is activated either with
/// the mouse or the keyboard. The passed <c>bool</c> contains the previous state.
/// </remarks>
public event Action<bool> Toggled;
public event Action<bool?> Toggled;
/// <summary>
/// Called when the <see cref="Checked"/> property changes. Invokes the <see cref="Toggled"/> event.
/// </summary>
public virtual void OnToggled (bool previousChecked)
public virtual void OnToggled (bool? previousChecked)
{
Toggled?.Invoke (previousChecked);
}
@@ -75,6 +77,7 @@ namespace Terminal.Gui {
void Initialize (ustring s, bool is_checked)
{
charNullChecked = new Rune (Driver != null ? Driver.NullChecked : '?');
charChecked = new Rune (Driver != null ? Driver.Checked : '√');
charUnChecked = new Rune (Driver != null ? Driver.UnChecked : '╴');
Checked = is_checked;
@@ -100,14 +103,23 @@ namespace Terminal.Gui {
case TextAlignment.Left:
case TextAlignment.Centered:
case TextAlignment.Justified:
TextFormatter.Text = ustring.Make (Checked ? charChecked : charUnChecked) + " " + GetFormatterText ();
TextFormatter.Text = ustring.Make (GetCheckedState ()) + " " + GetFormatterText ();
break;
case TextAlignment.Right:
TextFormatter.Text = GetFormatterText () + " " + ustring.Make (Checked ? charChecked : charUnChecked);
TextFormatter.Text = GetFormatterText () + " " + ustring.Make (GetCheckedState ());
break;
}
}
Rune GetCheckedState ()
{
switch (Checked) {
case true: return charChecked;
case false: return charUnChecked;
default: return charNullChecked;
}
}
ustring GetFormatterText ()
{
if (AutoSize || ustring.IsNullOrEmpty (Text) || Frame.Width <= 2) {
@@ -119,15 +131,32 @@ namespace Terminal.Gui {
/// <summary>
/// The state of the <see cref="CheckBox"/>
/// </summary>
public bool Checked {
public bool? Checked {
get => @checked;
set {
if (value == null && !AllowNullChecked) {
return;
}
@checked = value;
UpdateTextFormatterText ();
ProcessResizeView ();
}
}
/// <summary>
/// If <see langword="true"/> allows <see cref="Checked"/> to be null, true or false.
/// If <see langword="false"/> only allows <see cref="Checked"/> to be true or false.
/// </summary>
public bool AllowNullChecked {
get => allowNullChecked;
set {
allowNullChecked = value;
if (Checked == null) {
Checked = false;
}
}
}
///<inheritdoc/>
public override void PositionCursor ()
{
@@ -159,7 +188,21 @@ namespace Terminal.Gui {
SetFocus ();
}
var previousChecked = Checked;
Checked = !Checked;
if (AllowNullChecked) {
switch (previousChecked) {
case null:
Checked = true;
break;
case true:
Checked = false;
break;
case false:
Checked = null;
break;
}
} else {
Checked = !Checked;
}
OnToggled (previousChecked);
SetNeedsDisplay ();
return true;
@@ -171,11 +214,7 @@ namespace Terminal.Gui {
if (!me.Flags.HasFlag (MouseFlags.Button1Clicked) || !CanFocus)
return false;
SetFocus ();
var previousChecked = Checked;
Checked = !Checked;
OnToggled (previousChecked);
SetNeedsDisplay ();
ToggleChecked ();
return true;
}

View File

@@ -45,7 +45,7 @@ namespace UICatalog.Scenarios {
Application.Init ();
// Don't create a sub-win; just use Applicatiion.Top
}
public override void Setup ()
{
var statusBar = new StatusBar (new StatusItem [] {
@@ -103,7 +103,7 @@ namespace UICatalog.Scenarios {
_computedCheckBox = new CheckBox ("Computed Layout", true) { X = 0, Y = 0 };
_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

@@ -60,7 +60,7 @@ namespace UICatalog.Scenarios {
Y = Pos.Center () + 5,
Checked = labelH.AutoSize = labelV.AutoSize
};
ckbAutoSize.Toggled += (_) => labelH.AutoSize = labelV.AutoSize = ckbAutoSize.Checked;
ckbAutoSize.Toggled += (_) => labelH.AutoSize = labelV.AutoSize = (bool)ckbAutoSize.Checked;
Win.Add (ckbAutoSize);
var ckbPreserveTrailingSpaces = new CheckBox ("Preserve Trailing Spaces") {
@@ -69,7 +69,7 @@ namespace UICatalog.Scenarios {
Checked = labelH.PreserveTrailingSpaces = labelV.PreserveTrailingSpaces
};
ckbPreserveTrailingSpaces.Toggled += (_) =>
labelH.PreserveTrailingSpaces = labelV.PreserveTrailingSpaces = ckbPreserveTrailingSpaces.Checked;
labelH.PreserveTrailingSpaces = labelV.PreserveTrailingSpaces = (bool)ckbPreserveTrailingSpaces.Checked;
Win.Add (ckbPreserveTrailingSpaces);
var ckbWideText = new CheckBox ("Use wide runes") {
@@ -77,7 +77,7 @@ namespace UICatalog.Scenarios {
Y = Pos.Center () + 9
};
ckbWideText.Toggled += (_) => {
if (ckbWideText.Checked) {
if (ckbWideText.Checked == true) {
labelH.Text = labelV.Text = editText.Text = wideText;
labelH.Width = 14;
labelV.Height = 13;

View File

@@ -206,7 +206,7 @@ namespace UICatalog.Scenarios {
Y = Pos.Y (replacePadding) + 3,
Checked = smartPanel.UsePanelFrame
};
cbUseUsePanelFrame.Toggled += (e) => smartPanel.UsePanelFrame = !e;
cbUseUsePanelFrame.Toggled += (e) => smartPanel.UsePanelFrame = (bool)!e;
Win.Add (cbUseUsePanelFrame);
Win.Add (new Label ("Border:") {
@@ -339,8 +339,8 @@ namespace UICatalog.Scenarios {
};
cbDrawMarginFrame.Toggled += (e) => {
try {
smartPanel.Child.Border.DrawMarginFrame = cbDrawMarginFrame.Checked;
smartView.Border.DrawMarginFrame = cbDrawMarginFrame.Checked;
smartPanel.Child.Border.DrawMarginFrame = (bool)cbDrawMarginFrame.Checked;
smartView.Border.DrawMarginFrame = (bool)cbDrawMarginFrame.Checked;
if (cbDrawMarginFrame.Checked != smartView.Border.DrawMarginFrame) {
cbDrawMarginFrame.Checked = smartView.Border.DrawMarginFrame;
}
@@ -423,7 +423,7 @@ namespace UICatalog.Scenarios {
cbEffect3D.Toggled += (e) => {
try {
smartPanel.Child.Border.Effect3D = smartView.Border.Effect3D = effect3DOffsetX.Enabled =
effect3DOffsetY.Enabled = cbEffect3D.Checked;
effect3DOffsetY.Enabled = (bool)cbEffect3D.Checked;
} catch { }
};

View File

@@ -267,7 +267,7 @@ namespace UICatalog.Scenarios {
};
cbDrawMarginFrame.Toggled += (e) => {
try {
smartView.Border.DrawMarginFrame = cbDrawMarginFrame.Checked;
smartView.Border.DrawMarginFrame = (bool)cbDrawMarginFrame.Checked;
if (cbDrawMarginFrame.Checked != smartView.Border.DrawMarginFrame) {
cbDrawMarginFrame.Checked = smartView.Border.DrawMarginFrame;
}
@@ -343,7 +343,7 @@ namespace UICatalog.Scenarios {
cbEffect3D.Toggled += (e) => {
try {
smartView.Border.Effect3D = effect3DOffsetX.Enabled =
effect3DOffsetY.Enabled = cbEffect3D.Checked;
effect3DOffsetY.Enabled = (bool)cbEffect3D.Checked;
} catch { }
};

View File

@@ -267,7 +267,7 @@ namespace UICatalog.Scenarios {
};
cbDrawMarginFrame.Toggled += (e) => {
try {
smartView.Border.DrawMarginFrame = cbDrawMarginFrame.Checked;
smartView.Border.DrawMarginFrame = (bool)cbDrawMarginFrame.Checked;
if (cbDrawMarginFrame.Checked != smartView.Border.DrawMarginFrame) {
cbDrawMarginFrame.Checked = smartView.Border.DrawMarginFrame;
}
@@ -343,7 +343,7 @@ namespace UICatalog.Scenarios {
cbEffect3D.Toggled += (e) => {
try {
smartView.Border.Effect3D = effect3DOffsetX.Enabled =
effect3DOffsetY.Enabled = cbEffect3D.Checked;
effect3DOffsetY.Enabled = (bool)cbEffect3D.Checked;
} catch { }
};

View File

@@ -267,7 +267,7 @@ namespace UICatalog.Scenarios {
};
cbDrawMarginFrame.Toggled += (e) => {
try {
smartView.Border.DrawMarginFrame = cbDrawMarginFrame.Checked;
smartView.Border.DrawMarginFrame = (bool)cbDrawMarginFrame.Checked;
if (cbDrawMarginFrame.Checked != smartView.Border.DrawMarginFrame) {
cbDrawMarginFrame.Checked = smartView.Border.DrawMarginFrame;
}
@@ -343,7 +343,7 @@ namespace UICatalog.Scenarios {
cbEffect3D.Toggled += (e) => {
try {
smartView.Border.Effect3D = effect3DOffsetX.Enabled =
effect3DOffsetY.Enabled = cbEffect3D.Checked;
effect3DOffsetY.Enabled = (bool)cbEffect3D.Checked;
} catch { }
};

View File

@@ -92,7 +92,7 @@ namespace UICatalog.Scenarios {
};
frame.Add (numButtonsEdit);
var glyphsNotWords = new CheckBox ($"Add {Char.ConvertFromUtf32(CODE_POINT)} to button text to stress wide char support", false) {
var glyphsNotWords = new CheckBox ($"Add {Char.ConvertFromUtf32 (CODE_POINT)} to button text to stress wide char support", false) {
X = Pos.Left (numButtonsEdit),
Y = Pos.Bottom (label),
TextAlignment = Terminal.Gui.TextAlignment.Right,
@@ -115,7 +115,7 @@ namespace UICatalog.Scenarios {
void Top_Loaded ()
{
frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit)
+ Dim.Height (numButtonsEdit) + Dim.Height (styleRadioGroup) + Dim.Height(glyphsNotWords) + 2;
+ Dim.Height (numButtonsEdit) + Dim.Height (styleRadioGroup) + Dim.Height (glyphsNotWords) + 2;
Application.Top.Loaded -= Top_Loaded;
}
Application.Top.Loaded += Top_Loaded;
@@ -160,7 +160,7 @@ namespace UICatalog.Scenarios {
for (int i = 0; i < numButtons; i++) {
int buttonId = i;
Button button = null;
if (glyphsNotWords.Checked) {
if (glyphsNotWords.Checked == true) {
buttonId = i;
button = new Button (NumberToWords.Convert (buttonId) + " " + Char.ConvertFromUtf32 (buttonId + CODE_POINT),
is_default: buttonId == 0);
@@ -196,7 +196,7 @@ namespace UICatalog.Scenarios {
add.Clicked += () => {
var buttonId = buttons.Count;
Button button;
if (glyphsNotWords.Checked) {
if (glyphsNotWords.Checked == true) {
button = new Button (NumberToWords.Convert (buttonId) + " " + Char.ConvertFromUtf32 (buttonId + CODE_POINT),
is_default: buttonId == 0);
} else {
@@ -216,7 +216,7 @@ namespace UICatalog.Scenarios {
};
dialog.Add (add);
var addChar = new Button ($"Add a {Char.ConvertFromUtf32(CODE_POINT)} to each button") {
var addChar = new Button ($"Add a {Char.ConvertFromUtf32 (CODE_POINT)} to each button") {
X = Pos.Center (),
Y = Pos.Center () + 1
};

View File

@@ -310,8 +310,8 @@ namespace UICatalog.Scenarios {
} else if (_currentEditMenuBarItem != null) {
var menuItem = new DynamicMenuItem (_frmMenuDetails._txtTitle.Text, _frmMenuDetails._txtHelp.Text,
_frmMenuDetails._txtAction.Text,
_frmMenuDetails._ckbIsTopLevel != null ? _frmMenuDetails._ckbIsTopLevel.Checked : false,
_frmMenuDetails._ckbSubMenu != null ? _frmMenuDetails._ckbSubMenu.Checked : false,
_frmMenuDetails._ckbIsTopLevel != null ? (bool)_frmMenuDetails._ckbIsTopLevel.Checked : false,
_frmMenuDetails._ckbSubMenu != null ? (bool)_frmMenuDetails._ckbSubMenu.Checked : false,
_frmMenuDetails._rbChkStyle.SelectedItem == 0 ? MenuItemCheckStyle.NoCheck :
_frmMenuDetails._rbChkStyle.SelectedItem == 1 ? MenuItemCheckStyle.Checked :
MenuItemCheckStyle.Radio,
@@ -780,18 +780,18 @@ namespace UICatalog.Scenarios {
Add (_btnShortcut);
_ckbIsTopLevel.Toggled += (e) => {
if ((_menuItem != null && _menuItem.Parent != null && _ckbIsTopLevel.Checked) ||
_menuItem == null && hasParent && _ckbIsTopLevel.Checked) {
if ((_menuItem != null && _menuItem.Parent != null && (bool)_ckbIsTopLevel.Checked) ||
_menuItem == null && hasParent && (bool)_ckbIsTopLevel.Checked) {
MessageBox.ErrorQuery ("Invalid IsTopLevel", "Only menu bar can have top level menu item!", "Ok");
_ckbIsTopLevel.Checked = false;
return;
}
if (_ckbIsTopLevel.Checked) {
if (_ckbIsTopLevel.Checked == true) {
_ckbSubMenu.Checked = false;
_ckbSubMenu.SetNeedsDisplay ();
_txtHelp.Enabled = true;
_txtAction.Enabled = true;
_txtShortcut.Enabled = !_ckbIsTopLevel.Checked && !_ckbSubMenu.Checked;
_txtShortcut.Enabled = _ckbIsTopLevel.Checked == false && _ckbSubMenu.Checked == false;
} else {
if (_menuItem == null && !hasParent || _menuItem.Parent == null) {
_ckbSubMenu.Checked = true;
@@ -805,7 +805,7 @@ namespace UICatalog.Scenarios {
}
};
_ckbSubMenu.Toggled += (e) => {
if (_ckbSubMenu.Checked) {
if ((bool)_ckbSubMenu.Checked) {
_ckbIsTopLevel.Checked = false;
_ckbIsTopLevel.SetNeedsDisplay ();
_txtHelp.Text = "";
@@ -822,7 +822,7 @@ namespace UICatalog.Scenarios {
}
_txtHelp.Enabled = true;
_txtAction.Enabled = true;
_txtShortcut.Enabled = !_ckbIsTopLevel.Checked && !_ckbSubMenu.Checked;
_txtShortcut.Enabled = _ckbIsTopLevel.Checked == false && _ckbSubMenu.Checked == false;
}
};
@@ -876,8 +876,8 @@ namespace UICatalog.Scenarios {
if (valid) {
return new DynamicMenuItem (_txtTitle.Text, _txtHelp.Text, _txtAction.Text,
_ckbIsTopLevel != null ? _ckbIsTopLevel.Checked : false,
_ckbSubMenu != null ? _ckbSubMenu.Checked : false,
_ckbIsTopLevel != null ? (bool)_ckbIsTopLevel.Checked : false,
_ckbSubMenu != null ? (bool)_ckbSubMenu.Checked : false,
_rbChkStyle.SelectedItem == 0 ? MenuItemCheckStyle.NoCheck :
_rbChkStyle.SelectedItem == 1 ? MenuItemCheckStyle.Checked : MenuItemCheckStyle.Radio,
_txtShortcut.Text);
@@ -903,11 +903,11 @@ namespace UICatalog.Scenarios {
_txtAction.Text = menuItem != null && menuItem.Action != null ? GetTargetAction (menuItem.Action) : ustring.Empty;
_ckbIsTopLevel.Checked = IsTopLevel (menuItem);
_ckbSubMenu.Checked = HasSubMenus (menuItem);
_txtHelp.Enabled = !_ckbSubMenu.Checked;
_txtAction.Enabled = !_ckbSubMenu.Checked;
_txtHelp.Enabled = (bool)!_ckbSubMenu.Checked;
_txtAction.Enabled = (bool)!_ckbSubMenu.Checked;
_rbChkStyle.SelectedItem = (int)(menuItem?.CheckType ?? MenuItemCheckStyle.NoCheck);
_txtShortcut.Text = menuItem?.ShortcutTag ?? "";
_txtShortcut.Enabled = !_ckbIsTopLevel.Checked && !_ckbSubMenu.Checked;
_txtShortcut.Enabled = _ckbIsTopLevel.Checked == false && _ckbSubMenu.Checked == false;
}
void CleanEditMenuBarItem ()

View File

@@ -837,7 +837,7 @@ namespace UICatalog.Scenarios {
Y = Pos.Top (txtToFind) + 2,
Checked = _matchCase
};
ckbMatchCase.Toggled += (e) => _matchCase = ckbMatchCase.Checked;
ckbMatchCase.Toggled += (e) => _matchCase = (bool)ckbMatchCase.Checked;
d.Add (ckbMatchCase);
var ckbMatchWholeWord = new CheckBox ("Match _whole word") {
@@ -845,7 +845,7 @@ namespace UICatalog.Scenarios {
Y = Pos.Top (ckbMatchCase) + 1,
Checked = _matchWholeWord
};
ckbMatchWholeWord.Toggled += (e) => _matchWholeWord = ckbMatchWholeWord.Checked;
ckbMatchWholeWord.Toggled += (e) => _matchWholeWord = (bool)ckbMatchWholeWord.Checked;
d.Add (ckbMatchWholeWord);
d.Width = label.Width + txtToFind.Width + btnFindNext.Width + 2;
@@ -958,7 +958,7 @@ namespace UICatalog.Scenarios {
Y = Pos.Top (txtToFind) + 2,
Checked = _matchCase
};
ckbMatchCase.Toggled += (e) => _matchCase = ckbMatchCase.Checked;
ckbMatchCase.Toggled += (e) => _matchCase = (bool)ckbMatchCase.Checked;
d.Add (ckbMatchCase);
var ckbMatchWholeWord = new CheckBox ("Match _whole word") {
@@ -966,7 +966,7 @@ namespace UICatalog.Scenarios {
Y = Pos.Top (ckbMatchCase) + 1,
Checked = _matchWholeWord
};
ckbMatchWholeWord.Toggled += (e) => _matchWholeWord = ckbMatchWholeWord.Checked;
ckbMatchWholeWord.Toggled += (e) => _matchWholeWord = (bool)ckbMatchWholeWord.Checked;
d.Add (ckbMatchWholeWord);
d.Width = lblWidth + txtToFind.Width + btnFindNext.Width + 2;

View File

@@ -43,7 +43,7 @@ namespace UICatalog.Scenarios {
X = Pos.Right (_allowMarkingCB) + 1,
Y = 0,
Height = 1,
Visible = _allowMarkingCB.Checked
Visible = (bool)_allowMarkingCB.Checked
};
Win.Add (_allowMultipleCB);
_allowMultipleCB.Toggled += AllowMultipleCB_Toggled;
@@ -93,7 +93,7 @@ namespace UICatalog.Scenarios {
X = Pos.AnchorEnd (k.Length + 3),
Y = 0,
};
keepCheckBox.Toggled += (_) => _scrollBar.KeepContentAlwaysInViewport = keepCheckBox.Checked;
keepCheckBox.Toggled += (_) => _scrollBar.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked;
Win.Add (keepCheckBox);
}
@@ -113,9 +113,9 @@ namespace UICatalog.Scenarios {
}
}
private void _customRenderCB_Toggled (bool prev)
private void _customRenderCB_Toggled (bool? prev)
{
if (prev) {
if (prev == true) {
_listView.SetSource (_scenarios);
} else {
_listView.Source = new ScenarioListDataSource (_scenarios);
@@ -124,16 +124,16 @@ namespace UICatalog.Scenarios {
Win.SetNeedsDisplay ();
}
private void AllowMarkingCB_Toggled (bool prev)
private void AllowMarkingCB_Toggled (bool? prev)
{
_listView.AllowsMarking = !prev;
_listView.AllowsMarking = (bool)!prev;
_allowMultipleCB.Visible = _listView.AllowsMarking;
Win.SetNeedsDisplay ();
}
private void AllowMultipleCB_Toggled (bool prev)
private void AllowMultipleCB_Toggled (bool? prev)
{
_listView.AllowsMultipleSelection = !prev;
_listView.AllowsMultipleSelection = (bool)!prev;
Win.SetNeedsDisplay ();
}

View File

@@ -148,7 +148,7 @@ namespace UICatalog.Scenarios {
Y = Pos.Top (label) + 2
};
ckbEffect3D.Toggled += (e) => {
border.Effect3D = !e;
border.Effect3D = (bool)!e;
};
frame.Add (ckbEffect3D);

View File

@@ -121,7 +121,7 @@ namespace UICatalog.Scenarios {
};
ckbBidirectional.Toggled += (e) => {
ckbBidirectional.Checked = marqueesBlocksPB.BidirectionalMarquee = marqueesContinuousPB.BidirectionalMarquee = !e;
ckbBidirectional.Checked = marqueesBlocksPB.BidirectionalMarquee = marqueesContinuousPB.BidirectionalMarquee = (bool)!e;
};
_pulseTimer = new Timer ((_) => {

View File

@@ -237,29 +237,29 @@ namespace UICatalog.Scenarios {
Y = Pos.Bottom (scrollView) + 4,
};
hCheckBox.Toggled += (_) => {
if (!ahCheckBox.Checked) {
scrollView.ShowHorizontalScrollIndicator = hCheckBox.Checked;
if (ahCheckBox.Checked == false) {
scrollView.ShowHorizontalScrollIndicator = (bool)hCheckBox.Checked;
} else {
hCheckBox.Checked = true;
MessageBox.Query ("Message", "Disable Auto Hide Scrollbars first.", "Ok");
}
};
vCheckBox.Toggled += (_) => {
if (!ahCheckBox.Checked) {
scrollView.ShowVerticalScrollIndicator = vCheckBox.Checked;
if (ahCheckBox.Checked == false) {
scrollView.ShowVerticalScrollIndicator = (bool)vCheckBox.Checked;
} else {
vCheckBox.Checked = true;
MessageBox.Query ("Message", "Disable Auto Hide Scrollbars first.", "Ok");
}
};
ahCheckBox.Toggled += (_) => {
scrollView.AutoHideScrollBars = ahCheckBox.Checked;
scrollView.AutoHideScrollBars = (bool)ahCheckBox.Checked;
hCheckBox.Checked = true;
vCheckBox.Checked = true;
};
Win.Add (ahCheckBox);
keepCheckBox.Toggled += (_) => scrollView.KeepContentAlwaysInViewport = keepCheckBox.Checked;
keepCheckBox.Toggled += (_) => scrollView.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked;
Win.Add (keepCheckBox);
var scrollView2 = new ScrollView (new Rect (55, 2, 20, 8)) {

View File

@@ -106,8 +106,8 @@ namespace UICatalog.Scenarios {
foreach (var r in txtInput.Text.ToString ()) {
var ck = char.IsLetter (r)
? (ConsoleKey)char.ToUpper (r) : (ConsoleKey)r;
Application.Driver.SendKeys (r, ck, ckbShift.Checked,
ckbAlt.Checked, ckbControl.Checked);
Application.Driver.SendKeys (r, ck, (bool)ckbShift.Checked,
(bool)ckbAlt.Checked, (bool)ckbControl.Checked);
}
lblShippedKeys.Text = rKeys;
lblShippedControlKeys.Text = rControlKeys;

View File

@@ -52,7 +52,7 @@ namespace UICatalog.Scenarios {
Width = Dim.Percent (50) - 1,
Height = Dim.Percent (30),
};
textView.Text = "TextView with some more test text. Unicode shouldn't 𝔹A𝔽!" ;
textView.Text = "TextView with some more test text. Unicode shouldn't 𝔹A𝔽!";
textView.DrawContent += TextView_DrawContent;
// This shows how to enable autocomplete in TextView.
@@ -84,17 +84,17 @@ namespace UICatalog.Scenarios {
// single-line mode.
var chxMultiline = new CheckBox ("Multiline") {
X = Pos.Left (textView),
Y = Pos.Bottom (textView),
Y = Pos.Bottom (textView),
Checked = true
};
chxMultiline.Toggled += (b) => textView.Multiline = b;
chxMultiline.Toggled += (b) => textView.Multiline = (bool)b;
Win.Add (chxMultiline);
var chxWordWrap = new CheckBox ("Word Wrap") {
X = Pos.Right (chxMultiline) + 2,
Y = Pos.Top (chxMultiline)
};
chxWordWrap.Toggled += (b) => textView.WordWrap = b;
chxWordWrap.Toggled += (b) => textView.WordWrap = (bool)b;
Win.Add (chxWordWrap);
// TextView captures Tabs (so users can enter /t into text) by default;
@@ -108,15 +108,15 @@ namespace UICatalog.Scenarios {
Key keyTab = textView.GetKeyFromCommand (Command.Tab);
Key keyBackTab = textView.GetKeyFromCommand (Command.BackTab);
chxCaptureTabs.Toggled += (b) => {
if (b) {
chxCaptureTabs.Toggled += (b) => {
if (b == true) {
textView.AddKeyBinding (keyTab, Command.Tab);
textView.AddKeyBinding (keyBackTab, Command.BackTab);
} else {
textView.ClearKeybinding (keyTab);
textView.ClearKeybinding (keyBackTab);
}
textView.WordWrap = b;
textView.WordWrap = (bool)b;
};
Win.Add (chxCaptureTabs);
@@ -138,7 +138,7 @@ namespace UICatalog.Scenarios {
labelMirroringHexEditor.Text = Encoding.UTF8.GetString (array, 0, array.Length);
hexEditor.Edited += (kv) => {
hexEditor.ApplyEdits ();
var array = ((MemoryStream)hexEditor.Source).ToArray ();
var array = ((MemoryStream)hexEditor.Source).ToArray ();
labelMirroringHexEditor.Text = Encoding.UTF8.GetString (array, 0, array.Length);
};
Win.Add (labelMirroringHexEditor);

View File

@@ -60,12 +60,12 @@ namespace UICatalog.Scenarios {
var update = new Button ("_Update") {
X = Pos.Right (edit) + 1,
Y = Pos.Bottom (edit) - 1,
};
update.Clicked += () => {
foreach (var alignment in alignments) {
singleLines [(int) alignment].Text = edit.Text;
multipleLines [(int) alignment].Text = edit.Text;
singleLines [(int)alignment].Text = edit.Text;
multipleLines [(int)alignment].Text = edit.Text;
}
};
Win.Add (update);
@@ -100,8 +100,8 @@ namespace UICatalog.Scenarios {
enableHotKeyCheckBox.Toggled += (previous) => {
foreach (var alignment in alignments) {
singleLines [(int)alignment].HotKeySpecifier = previous ? (Rune)0xffff : (Rune)'_';
multipleLines [(int)alignment].HotKeySpecifier = previous ? (Rune)0xffff : (Rune)'_';
singleLines [(int)alignment].HotKeySpecifier = previous == true ? (Rune)0xffff : (Rune)'_';
multipleLines [(int)alignment].HotKeySpecifier = previous == true ? (Rune)0xffff : (Rune)'_';
}
Win.SetNeedsDisplay ();
Win.LayoutSubviews ();

View File

@@ -142,7 +142,7 @@ namespace UICatalog.Scenarios {
};
justifyCheckbox.Toggled += (prevtoggled) => {
if (prevtoggled) {
if (prevtoggled == true) {
foreach (var t in mtxts) {
t.TextAlignment = (TextAlignment)((dynamic)t.Data).h;
t.VerticalTextAlignment = (VerticalTextAlignment)((dynamic)t.Data).v;

View File

@@ -38,7 +38,7 @@ namespace UICatalog.Scenarios {
block.AppendLine (" ░ ░ ░░▒░ ░ ░ ▒ ░ ░▒ ░ ▒ ░ ░▒ ░ ░");
block.AppendLine ("░ ░ ░ ░░░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ");
block.AppendLine (" ░ ░ ░ ░ ░ ░ ░ ");
block.AppendLine (" ░ ░ ");
block.AppendLine (" ░ ░ ");
blockText.Text = ustring.Make (block.ToString ()); // .Replace(" ", "\u00A0"); // \u00A0 is 'non-breaking space
Win.Add (blockText);
@@ -82,8 +82,8 @@ namespace UICatalog.Scenarios {
unicodeCheckBox.Toggled += (previous) => {
foreach (var alignment in alignments) {
singleLines [(int)alignment].Text = previous ? text : unicode;
multipleLines [(int)alignment].Text = previous ? text : unicode;
singleLines [(int)alignment].Text = previous == true ? text : unicode;
multipleLines [(int)alignment].Text = previous == true ? text : unicode;
}
};
}

View File

@@ -50,7 +50,7 @@ namespace UICatalog.Scenarios {
label = new Label ("Label (CanFocus):") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
Win.Add (label);
testlabel = new Label ("Стоял &он, дум великих полн") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), CanFocus = true, HotKeySpecifier = new System.Rune('&') };
testlabel = new Label ("Стоял &он, дум великих полн") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), CanFocus = true, HotKeySpecifier = new System.Rune ('&') };
Win.Add (testlabel);
label = new Label ("Button:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
@@ -61,7 +61,9 @@ namespace UICatalog.Scenarios {
label = new Label ("CheckBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
Win.Add (label);
var checkBox = new CheckBox (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
Win.Add (checkBox);
var ckbAllowNull = new CheckBox ("Allow null checked") { X = Pos.Right (checkBox) + 1, Y = Pos.Y (label) };
ckbAllowNull.Toggled += (e) => checkBox.AllowNullChecked = (bool)!e;
Win.Add (checkBox, ckbAllowNull);
label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
Win.Add (label);

View File

@@ -201,9 +201,9 @@ namespace UICatalog.Scenarios {
Fraction = 0.42F
};
thirdStep.Add (progLbl, progressBar);
thirdStep.Enabled = thirdStepEnabledCeckBox.Checked;
thirdStep.Enabled = (bool)thirdStepEnabledCeckBox.Checked;
thirdStepEnabledCeckBox.Toggled += (args) => {
thirdStep.Enabled = thirdStepEnabledCeckBox.Checked;
thirdStep.Enabled = (bool)thirdStepEnabledCeckBox.Checked;
};
// Add 4th step
@@ -276,9 +276,9 @@ namespace UICatalog.Scenarios {
var finalFinalStep = new Wizard.WizardStep ("The VERY last step");
wizard.AddStep (finalFinalStep);
finalFinalStep.HelpText = "This step only shows if it was enabled on the other last step.";
finalFinalStep.Enabled = thirdStepEnabledCeckBox.Checked;
finalFinalStep.Enabled = (bool)thirdStepEnabledCeckBox.Checked;
finalFinalStepEnabledCeckBox.Toggled += (args) => {
finalFinalStep.Enabled = finalFinalStepEnabledCeckBox.Checked;
finalFinalStep.Enabled = (bool)finalFinalStepEnabledCeckBox.Checked;
};
Application.Run (wizard);

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);
}
}
}