Button.Clicked as a C# event

This commit is contained in:
Artyom
2020-09-23 01:01:53 +03:00
parent b4b58d7c64
commit 6aef632633
15 changed files with 188 additions and 168 deletions

View File

@@ -225,10 +225,11 @@ static class Demo {
static void NewFile ()
{
var d = new Dialog (
"New File", 50, 20,
new Button ("Ok", is_default: true) { Clicked = () => { Application.RequestStop (); } },
new Button ("Cancel") { Clicked = () => { Application.RequestStop (); } });
var ok = new Button ("Ok", is_default: true);
ok.Clicked += () => { Application.RequestStop (); };
var cancel = new Button ("Cancel");
cancel.Clicked += () => { Application.RequestStop (); };
var d = new Dialog ("New File", 50, 20, ok, cancel);
ml2 = new Label (1, 1, "Mouse Debug Line");
d.Add (ml2);
Application.Run (d);
@@ -423,9 +424,11 @@ static class Demo {
static void ListSelectionDemo (bool multiple)
{
var d = new Dialog ("Selection Demo", 60, 20,
new Button ("Ok", is_default: true) { Clicked = () => { Application.RequestStop (); } },
new Button ("Cancel") { Clicked = () => { Application.RequestStop (); } });
var ok = new Button ("Ok", is_default: true);
ok.Clicked += () => { Application.RequestStop (); };
var cancel = new Button ("Cancel");
cancel.Clicked += () => { Application.RequestStop (); };
var d = new Dialog ("Selection Demo", 60, 20, ok, cancel);
var animals = new List<string> () { "Alpaca", "Llama", "Lion", "Shark", "Goat" };
var msg = new Label ("Use space bar or control-t to toggle selection") {
@@ -483,9 +486,9 @@ static class Demo {
#region KeyDown / KeyPress / KeyUp Demo
private static void OnKeyDownPressUpDemo ()
{
var container = new Dialog (
"KeyDown & KeyPress & KeyUp demo", 80, 20,
new Button ("Close") { Clicked = () => { Application.RequestStop (); } }) {
var close = new Button ("Close");
close.Clicked += () => { Application.RequestStop (); };
var container = new Dialog ("KeyDown & KeyPress & KeyUp demo", 80, 20, close) {
Width = Dim.Fill (),
Height = Dim.Fill (),
};

View File

@@ -201,7 +201,7 @@ namespace Terminal.Gui {
/// raised when the button is activated either with
/// the mouse or the keyboard.
/// </remarks>
public Action Clicked;
public event Action Clicked;
///<inheritdoc/>
public override bool MouseEvent (MouseEvent me)

View File

@@ -29,12 +29,12 @@ namespace UICatalog {
//TODO: Change to use Pos.AnchorEnd()
Y = Pos.Bottom (Win) - 3,
IsDefault = true,
Clicked = () => Application.RequestStop (),
};
defaultButton.Clicked += () => Application.RequestStop ();
Win.Add (defaultButton);
var swapButton = new Button (50, 0, "Swap Default (Absolute Layout)");
swapButton.Clicked = () => {
swapButton.Clicked += () => {
defaultButton.IsDefault = !defaultButton.IsDefault;
swapButton.IsDefault = !swapButton.IsDefault;
};
@@ -42,7 +42,7 @@ namespace UICatalog {
static void DoMessage (Button button, ustring txt)
{
button.Clicked = () => {
button.Clicked += () => {
var btnText = button.Text.ToString ();
MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No");
};
@@ -82,15 +82,15 @@ namespace UICatalog {
Win.Add (button = new Button ("a Newline\nin the button") {
X = 2,
Y = Pos.Bottom (button) + 1,
Clicked = () => MessageBox.Query ("Message", "Question?", "Yes", "No")
});
button.Clicked += () => MessageBox.Query ("Message", "Question?", "Yes", "No");
var textChanger = new Button ("Te_xt Changer") {
X = 2,
Y = Pos.Bottom (button) + 1,
};
Win.Add (textChanger);
textChanger.Clicked = () => textChanger.Text += "!";
textChanger.Clicked += () => textChanger.Text += "!";
Win.Add (button = new Button ("Lets see if this will move as \"Text Changer\" grows") {
X = Pos.Right (textChanger) + 2,
@@ -104,7 +104,7 @@ namespace UICatalog {
};
Win.Add (removeButton);
// This in intresting test case because `moveBtn` and below are laid out relative to this one!
removeButton.Clicked = () => Win.Remove (removeButton);
removeButton.Clicked += () => Win.Remove (removeButton);
var computedFrame = new FrameView ("Computed Layout") {
X = 0,
@@ -121,7 +121,7 @@ namespace UICatalog {
Width = 30,
ColorScheme = Colors.Error,
};
moveBtn.Clicked = () => {
moveBtn.Clicked += () => {
moveBtn.X = moveBtn.Frame.X + 5;
// This is already fixed with the call to SetNeedDisplay() in the Pos Dim.
//computedFrame.LayoutSubviews (); // BUGBUG: This call should not be needed. View.X is not causing relayout correctly
@@ -135,7 +135,7 @@ namespace UICatalog {
Width = 30,
ColorScheme = Colors.Error,
};
sizeBtn.Clicked = () => {
sizeBtn.Clicked += () => {
sizeBtn.Width = sizeBtn.Frame.Width + 5;
//computedFrame.LayoutSubviews (); // FIXED: This call should not be needed. View.X is not causing relayout correctly
};
@@ -153,7 +153,7 @@ namespace UICatalog {
var moveBtnA = new Button (0, 0, "Move This Button via Frame") {
ColorScheme = Colors.Error,
};
moveBtnA.Clicked = () => {
moveBtnA.Clicked += () => {
moveBtnA.Frame = new Rect (moveBtnA.Frame.X + 5, moveBtnA.Frame.Y, moveBtnA.Frame.Width, moveBtnA.Frame.Height);
};
absoluteFrame.Add (moveBtnA);
@@ -162,7 +162,7 @@ namespace UICatalog {
var sizeBtnA = new Button (0, 2, " ~  s  gui.cs   master ↑10 = Со_хранить") {
ColorScheme = Colors.Error,
};
sizeBtnA.Clicked = () => {
sizeBtnA.Clicked += () => {
sizeBtnA.Frame = new Rect (sizeBtnA.Frame.X, sizeBtnA.Frame.Y, sizeBtnA.Frame.Width + 5, sizeBtnA.Frame.Height);
};
absoluteFrame.Add (sizeBtnA);
@@ -213,7 +213,7 @@ namespace UICatalog {
Width = Dim.Width (computedFrame) - 2,
ColorScheme = Colors.TopLevel,
};
moveHotKeyBtn.Clicked = () => {
moveHotKeyBtn.Clicked += () => {
moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text);
};
Win.Add (moveHotKeyBtn);
@@ -225,7 +225,7 @@ namespace UICatalog {
Width = Dim.Width (absoluteFrame) - 2, // BUGBUG: Not always the width isn't calculated correctly.
ColorScheme = Colors.TopLevel,
};
moveUnicodeHotKeyBtn.Clicked = () => {
moveUnicodeHotKeyBtn.Clicked += () => {
moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text);
};
Win.Add (moveUnicodeHotKeyBtn);

View File

@@ -69,11 +69,12 @@ namespace UICatalog {
Height = Dim.Fill (3),
ColorScheme = Colors.TopLevel
};
embedded3.Add (new Button (2, 2, "click me") {
Clicked = () => {
MessageBox.Query (10, 5, "Test", "test message", "Ok");
}
});
var testButton = new Button (2, 2, "click me");
testButton.Clicked += () => {
MessageBox.Query (10, 5, "Test", "test message", "Ok");
};
embedded3.Add (testButton);
embedded2.Add (embedded3);
scrollView.Add (embedded1);

View File

@@ -125,7 +125,7 @@ namespace UICatalog {
};
// TODO: Use Pos.Width instead of (Right-Left) when implemented (#502)
anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
anchorButton.Clicked = () => {
anchorButton.Clicked += () => {
// Ths demonstrates how to have a dynamically sized button
// Each time the button is clicked the button's text gets longer
// The call to Win.LayoutSubviews causes the Computed layout to
@@ -152,7 +152,7 @@ namespace UICatalog {
var leftButton = new Button ("Left") {
Y = Pos.Bottom (Win) - 3
};
leftButton.Clicked = () => {
leftButton.Clicked += () => {
// Ths demonstrates how to have a dynamically sized button
// Each time the button is clicked the button's text gets longer
// The call to Win.LayoutSubviews causes the Computed layout to
@@ -167,7 +167,7 @@ namespace UICatalog {
X = Pos.Center (),
Y = Pos.AnchorEnd () - 1
};
centerButton.Clicked = () => {
centerButton.Clicked += () => {
// Ths demonstrates how to have a dynamically sized button
// Each time the button is clicked the button's text gets longer
// The call to Win.LayoutSubviews causes the Computed layout to
@@ -180,7 +180,7 @@ namespace UICatalog {
var rightButton = new Button ("Right") {
Y = Pos.Y (centerButton)
};
rightButton.Clicked = () => {
rightButton.Clicked += () => {
// Ths demonstrates how to have a dynamically sized button
// Each time the button is clicked the button's text gets longer
// The call to Win.LayoutSubviews causes the Computed layout to

View File

@@ -116,52 +116,54 @@ namespace UICatalog {
X = Pos.Center(),
Y = Pos.Bottom (frame) + 2 ,
IsDefault = true,
Clicked = () => {
try {
int width = int.Parse (widthEdit.Text.ToString ());
int height = int.Parse (heightEdit.Text.ToString ());
int numButtons = int.Parse (numButtonsEdit.Text.ToString ());
};
showDialogButton.Clicked += () => {
try {
int width = int.Parse (widthEdit.Text.ToString ());
int height = int.Parse (heightEdit.Text.ToString ());
int numButtons = int.Parse (numButtonsEdit.Text.ToString ());
var buttons = new List<Button> ();
var clicked = -1;
for (int i = 0; i < numButtons; i++) {
var buttonId = i;
var button = new Button (btnText [buttonId % 10], is_default: buttonId == 0) {
Clicked = () => {
clicked = buttonId;
Application.RequestStop ();
},
};
buttons.Add(button);
}
// This tests dynamically adding buttons; ensuring the dialog resizes if needed and
// the buttons are laid out correctly
var dialog = new Dialog (titleEdit.Text, width, height, buttons.ToArray ());
var add = new Button ("Add a button") {
X = Pos.Center (),
Y = Pos.Center (),
Clicked = () => {
var buttonId = buttons.Count;
var button = new Button (btnText [buttonId % 10], is_default: buttonId == 0) {
Clicked = () => {
clicked = buttonId;
Application.RequestStop ();
},
};
buttons.Add (button);
dialog.AddButton (button);
},
var buttons = new List<Button> ();
var clicked = -1;
for (int i = 0; i < numButtons; i++) {
var buttonId = i;
var button = new Button (btnText [buttonId % 10],
is_default: buttonId == 0);
button.Clicked += () => {
clicked = buttonId;
Application.RequestStop ();
};
dialog.Add (add);
Application.Run (dialog);
buttonPressedLabel.Text = $"{clicked}";
} catch (FormatException) {
buttonPressedLabel.Text = "Invalid Options";
buttons.Add (button);
}
},
// This tests dynamically adding buttons; ensuring the dialog resizes if needed and
// the buttons are laid out correctly
var dialog = new Dialog (titleEdit.Text, width, height,
buttons.ToArray ());
var add = new Button ("Add a button") {
X = Pos.Center (),
Y = Pos.Center (),
};
add.Clicked += () => {
var buttonId = buttons.Count;
var button = new Button (btnText [buttonId % 10],
is_default: buttonId == 0);
button.Clicked += () => {
clicked = buttonId;
Application.RequestStop ();
};
buttons.Add (button);
dialog.AddButton (button);
};
dialog.Add (add);
Application.Run (dialog);
buttonPressedLabel.Text = $"{clicked}";
} catch (FormatException) {
buttonPressedLabel.Text = "Invalid Options";
}
};
Win.Add (showDialogButton);

View File

@@ -270,13 +270,19 @@ namespace UICatalog {
var _btnOk = new Button ("Ok") {
X = Pos.Left (_lblTitle) + 20,
Y = Pos.Bottom (_rbChkStyle) + 1,
Clicked = () => {
if (ustring.IsNullOrEmpty (_txtTitle.Text) && _currentEditMenuBarItem != null) {
MessageBox.ErrorQuery ("Invalid title", "Must enter a valid title!.", "Ok");
} else if (_currentEditMenuBarItem != null) {
var menuItem = new DynamicMenuItem (_txtTitle.Text, _txtHelp.Text, _txtAction.Text, _ckbIsTopLevel != null ? _ckbIsTopLevel.Checked : false, _ckbSubMenu != null ? _ckbSubMenu.Checked : false, _rbChkStyle.SelectedItem == 0 ? MenuItemCheckStyle.NoCheck : _rbChkStyle.SelectedItem == 1 ? MenuItemCheckStyle.Checked : MenuItemCheckStyle.Radio);
UpdateMenuItem (_currentEditMenuBarItem, menuItem, _lstMenus.SelectedItem);
}
};
_btnOk.Clicked += () => {
if (ustring.IsNullOrEmpty (_txtTitle.Text) && _currentEditMenuBarItem != null) {
MessageBox.ErrorQuery ("Invalid title", "Must enter a valid title!.", "Ok");
} else if (_currentEditMenuBarItem != null) {
var menuItem = new DynamicMenuItem (_txtTitle.Text, _txtHelp.Text,
_txtAction.Text,
_ckbIsTopLevel != null ? _ckbIsTopLevel.Checked : false,
_ckbSubMenu != null ? _ckbSubMenu.Checked : false,
_rbChkStyle.SelectedItem == 0 ? MenuItemCheckStyle.NoCheck :
_rbChkStyle.SelectedItem == 1 ? MenuItemCheckStyle.Checked :
MenuItemCheckStyle.Radio);
UpdateMenuItem (_currentEditMenuBarItem, menuItem, _lstMenus.SelectedItem);
}
};
_frmMenuDetails.Add (_btnOk);
@@ -284,15 +290,15 @@ namespace UICatalog {
var _btnCancel = new Button ("Cancel") {
X = Pos.Right (_btnOk) + 3,
Y = Pos.Top (_btnOk),
Clicked = () => {
_txtTitle.Text = ustring.Empty;
}
};
_btnCancel.Clicked += () => {
_txtTitle.Text = ustring.Empty;
};
_frmMenuDetails.Add (_btnCancel);
Add (_frmMenuDetails);
_btnAdd.Clicked = () => {
_btnAdd.Clicked += () => {
if (MenuBar == null) {
MessageBox.ErrorQuery ("Menu Bar Error", "Must add a MenuBar first!", "Ok");
_btnAddMenuBar.SetFocus ();
@@ -328,7 +334,7 @@ namespace UICatalog {
}
};
_btnRemove.Clicked = () => {
_btnRemove.Clicked += () => {
var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [_lstMenus.SelectedItem].MenuItem : null;
if (menuItem != null) {
var childrens = ((MenuBarItem)_currentMenuBarItem).Children;
@@ -355,7 +361,7 @@ namespace UICatalog {
}
};
_btnMenuBarUp.Clicked = () => {
_btnMenuBarUp.Clicked += () => {
var i = _currentSelectedMenuBar;
var menuItem = _menuBar != null && _menuBar.Menus.Length > 0 ? _menuBar.Menus [i] : null;
if (menuItem != null) {
@@ -369,7 +375,7 @@ namespace UICatalog {
}
};
_btnMenuBarDown.Clicked = () => {
_btnMenuBarDown.Clicked += () => {
var i = _currentSelectedMenuBar;
var menuItem = _menuBar != null && _menuBar.Menus.Length > 0 ? _menuBar.Menus [i] : null;
if (menuItem != null) {
@@ -383,7 +389,7 @@ namespace UICatalog {
}
};
_btnUp.Clicked = () => {
_btnUp.Clicked += () => {
var i = _lstMenus.SelectedItem;
var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [i].MenuItem : null;
if (menuItem != null) {
@@ -398,7 +404,7 @@ namespace UICatalog {
}
};
_btnDown.Clicked = () => {
_btnDown.Clicked += () => {
var i = _lstMenus.SelectedItem;
var menuItem = DataContext.Menus.Count > 0 ? DataContext.Menus [i].MenuItem : null;
if (menuItem != null) {
@@ -413,7 +419,7 @@ namespace UICatalog {
}
};
_btnAddMenuBar.Clicked = () => {
_btnAddMenuBar.Clicked += () => {
var item = EnterMenuItem (null);
if (ustring.IsNullOrEmpty (item.title)) {
return;
@@ -439,7 +445,7 @@ namespace UICatalog {
_menuBar.SetNeedsDisplay ();
};
_btnRemoveMenuBar.Clicked = () => {
_btnRemoveMenuBar.Clicked += () => {
if (_menuBar != null && _menuBar.Menus.Length > 0) {
_menuBar.Menus [_currentSelectedMenuBar] = null;
int i = 0;
@@ -478,14 +484,14 @@ namespace UICatalog {
}
};
_btnPrevious.Clicked = () => {
_btnPrevious.Clicked += () => {
if (_currentSelectedMenuBar - 1 > -1) {
_currentSelectedMenuBar--;
}
SelectCurrentMenuBarItem ();
};
_btnNext.Clicked = () => {
_btnNext.Clicked += () => {
if (_menuBar != null && _currentSelectedMenuBar + 1 < _menuBar.Menus.Length) {
_currentSelectedMenuBar++;
}
@@ -506,7 +512,7 @@ namespace UICatalog {
EditMenuBarItem (menuBarItem);
};
_btnPreviowsParent.Clicked = () => {
_btnPreviowsParent.Clicked += () => {
if (_currentMenuBarItem != null && _currentMenuBarItem.Parent != null) {
var mi = _currentMenuBarItem;
_currentMenuBarItem = _currentMenuBarItem.Parent as MenuBarItem;
@@ -770,20 +776,19 @@ namespace UICatalog {
};
var _btnOk = new Button ("Ok") {
IsDefault = true,
Clicked = () => {
if (ustring.IsNullOrEmpty (_txtTitle.Text)) {
MessageBox.ErrorQuery ("Invalid title", "Must enter a valid title!.", "Ok");
} else {
Application.RequestStop ();
}
}
};
var _btnCancel = new Button ("Cancel") {
Clicked = () => {
_txtTitle.Text = ustring.Empty;
_btnOk.Clicked += () => {
if (ustring.IsNullOrEmpty (_txtTitle.Text)) {
MessageBox.ErrorQuery ("Invalid title", "Must enter a valid title!.", "Ok");
} else {
Application.RequestStop ();
}
};
var _btnCancel = new Button ("Cancel");
_btnCancel.Clicked += () => {
_txtTitle.Text = ustring.Empty;
Application.RequestStop ();
};
var _dialog = new Dialog ("Please enter the menu details.", _btnOk, _btnCancel);
_dialog.Add (_lblTitle, _txtTitle, _lblHelp, _txtHelp, _lblAction, _txtAction, _ckbIsTopLevel, _ckbSubMenu, _rbChkStyle);
_txtTitle.SetFocus ();

View File

@@ -7,11 +7,12 @@ namespace UICatalog {
public override void Setup ()
{
// Put your scenario code here, e.g.
Win.Add (new Button ("Press me!") {
var button = new Button ("Press me!") {
X = Pos.Center (),
Y = Pos.Center (),
Clicked = () => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No")
});
};
button.Clicked += () => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No");
Win.Add (button);
}
}
}

View File

@@ -148,25 +148,25 @@ namespace UICatalog {
X = Pos.Center(),
Y = Pos.Bottom (frame) + 2 ,
IsDefault = true,
Clicked = () => {
try {
int width = int.Parse (widthEdit.Text.ToString ());
int height = int.Parse (heightEdit.Text.ToString ());
int numButtons = int.Parse (numButtonsEdit.Text.ToString ());
};
showMessageBoxButton.Clicked += () => {
try {
int width = int.Parse (widthEdit.Text.ToString ());
int height = int.Parse (heightEdit.Text.ToString ());
int numButtons = int.Parse (numButtonsEdit.Text.ToString ());
var btns = new List<ustring> ();
for (int i = 0; i < numButtons; i++) {
btns.Add(btnText[i % 10]);
}
if (styleRadioGroup.SelectedItem == 0) {
buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
} else {
buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
}
} catch (FormatException) {
buttonPressedLabel.Text = "Invalid Options";
var btns = new List<ustring> ();
for (int i = 0; i < numButtons; i++) {
btns.Add(btnText[i % 10]);
}
},
if (styleRadioGroup.SelectedItem == 0) {
buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
} else {
buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), btns.ToArray ())}";
}
} catch (FormatException) {
buttonPressedLabel.Text = "Invalid Options";
}
};
Win.Add (showMessageBoxButton);

View File

@@ -58,18 +58,18 @@ namespace UICatalog {
var startButton = new Button ("Start Timer") {
X = Pos.Right (LeftFrame) + 1,
Y = 0,
Clicked = () => Start()
};
startButton.Clicked += () => Start ();
var pulseButton = new Button ("Pulse") {
X = Pos.Right (startButton) + 2,
Y = Pos.Y (startButton),
Clicked = () => Pulse()
};
pulseButton.Clicked += () => Pulse ();
var stopbutton = new Button ("Stop Timer") {
X = Pos.Right (pulseButton) + 2,
Y = Pos.Top (pulseButton),
Clicked = () => Stop()
};
stopbutton.Clicked += () => Stop ();
Add (startButton);
Add (pulseButton);
@@ -225,7 +225,7 @@ namespace UICatalog {
X = Pos.Center (),
Y = Pos.Bottom(mainLoopTimeoutDemo) + 1,
};
startBoth.Clicked = () => {
startBoth.Clicked += () => {
systemTimerDemo.Start ();
mainLoopTimeoutDemo.Start ();
};

View File

@@ -149,18 +149,20 @@ namespace UICatalog {
verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)];
};
scrollView.Add (new Button ("Press me!") {
var pressMeButton = new Button ("Press me!") {
X = 3,
Y = 3,
Clicked = () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No")
});
};
pressMeButton.Clicked += () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No");
scrollView.Add (pressMeButton);
scrollView.Add (new Button ("A very long button. Should be wide enough to demo clipping!") {
var aLongButton = new Button ("A very long button. Should be wide enough to demo clipping!") {
X = 3,
Y = 4,
Width = Dim.Fill (6),
Clicked = () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No")
});
};
aLongButton.Clicked += () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No");
scrollView.Add (aLongButton);
scrollView.Add (new TextField ("This is a test of...") {
X = 3,
@@ -189,7 +191,7 @@ namespace UICatalog {
};
// TODO: Use Pos.Width instead of (Right-Left) when implemented (#502)
anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
anchorButton.Clicked = () => {
anchorButton.Clicked += () => {
// Ths demonstrates how to have a dynamically sized button
// Each time the button is clicked the button's text gets longer
// The call to Win.LayoutSubviews causes the Computed layout to

View File

@@ -24,11 +24,12 @@ namespace UICatalog {
public override void Setup ()
{
Win.Add (new Button ("Press me!") {
X = Pos.Center (),
Y = Pos.Center (),
Clicked = () => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No")
});
var pressMe = new Button ("Press me!") {
X = Pos.Center (),
Y = Pos.Center (),
};
pressMe.Clicked += () => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No");
Win.Add (pressMe);
}
}
}

View File

@@ -51,20 +51,21 @@ namespace UICatalog {
var unicodeSample = new Button ("Unicode Sample") {
X = Pos.Right (edit) + 1,
Y = 0,
Clicked = () => {
edit.Text = unicodeSampleText;
}
};
unicodeSample.Clicked += () => {
edit.Text = unicodeSampleText;
};
Win.Add (unicodeSample);
var update = new Button ("_Update") {
X = Pos.Right (edit) + 1,
Y = Pos.Bottom (edit) - 1,
Clicked = () => {
foreach (var alignment in alignments) {
singleLines [(int)alignment].Text = edit.Text;
multipleLines [(int)alignment].Text = edit.Text;
}
};
update.Clicked += () => {
foreach (var alignment in alignments) {
singleLines [(int) alignment].Text = edit.Text;
multipleLines [(int) alignment].Text = edit.Text;
}
};
Win.Add (update);

View File

@@ -99,23 +99,24 @@ namespace UICatalog {
};
Win.Add (lblDateFmt);
Win.Add (new Button ("Swap Long/Short & Read/Read Only") {
var swapButton = new Button ("Swap Long/Short & Read/Read Only") {
X = Pos.Center (),
Y = Pos.Bottom (Win) - 5,
Clicked = () => {
longTime.ReadOnly = !longTime.ReadOnly;
shortTime.ReadOnly = !shortTime.ReadOnly;
};
swapButton.Clicked += () => {
longTime.ReadOnly = !longTime.ReadOnly;
shortTime.ReadOnly = !shortTime.ReadOnly;
longTime.IsShortFormat = !longTime.IsShortFormat;
shortTime.IsShortFormat = !shortTime.IsShortFormat;
longTime.IsShortFormat = !longTime.IsShortFormat;
shortTime.IsShortFormat = !shortTime.IsShortFormat;
longDate.ReadOnly = !longDate.ReadOnly;
shortDate.ReadOnly = !shortDate.ReadOnly;
longDate.ReadOnly = !longDate.ReadOnly;
shortDate.ReadOnly = !shortDate.ReadOnly;
longDate.IsShortFormat = !longDate.IsShortFormat;
shortDate.IsShortFormat = !shortDate.IsShortFormat;
}
});
longDate.IsShortFormat = !longDate.IsShortFormat;
shortDate.IsShortFormat = !shortDate.IsShortFormat;
};
Win.Add (swapButton);
}
private void TimeChanged (DateTimeEventArgs<TimeSpan> e)

View File

@@ -60,12 +60,13 @@ namespace UICatalog {
Height = Dim.Percent (15)
};
Win.ColorScheme = Colors.Dialog;
Win.Add (new Button ($"Padding of container is {padding}") {
var paddingButton = new Button ($"Padding of container is {padding}") {
X = Pos.Center (),
Y = 0,
ColorScheme = Colors.Error,
Clicked = () => About ()
});
};
paddingButton.Clicked += () => About ();
Win.Add (paddingButton);
Win.Add (new Button ("Press ME! (Y = Pos.AnchorEnd(1))") {
X = Pos.Center (),
Y = Pos.AnchorEnd (1),
@@ -83,12 +84,14 @@ namespace UICatalog {
Height = contentHeight + (i * 2) + 2,
};
win.ColorScheme = Colors.Dialog;
win.Add (new Button ("Press me! (Y = 0)") {
var pressMeButton = new Button ("Press me! (Y = 0)") {
X = Pos.Center (),
Y = 0,
ColorScheme = Colors.Error,
Clicked = () => MessageBox.ErrorQuery (win.Title.ToString (), "Neat?", "Yes", "No")
});
};
pressMeButton.Clicked += () =>
MessageBox.ErrorQuery (win.Title.ToString (), "Neat?", "Yes", "No");
win.Add (pressMeButton);
var subWin = new Window ("Sub Window") {
X = Pos.Percent (0),
Y = 1,