123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using Terminal.Gui;
- namespace UICatalog {
- [ScenarioMetadata (Name: "Buttons", Description: "Demonstrates all sorts of Buttons")]
- [ScenarioCategory ("Controls")]
- [ScenarioCategory ("Layout")]
- class Buttons : Scenario {
- public override void Setup ()
- {
- // Add a label & text field so we can demo IsDefault
- var editLabel = new Label ("TextField (to demo IsDefault):") {
- X = 0,
- Y = 0,
- };
- Win.Add (editLabel);
- var edit = new TextField ("") {
- X = Pos.Right (editLabel) + 1,
- Y = Pos.Top (editLabel),
- Width = Dim.Fill (2),
- };
- Win.Add (edit);
- // This is the default button (IsDefault = true); if user presses ENTER in the TextField
- // the scenario will quit
- var defaultButton = new Button ("Quit") {
- X = Pos.Center (),
- // BUGBUG: Throws an exception
- //Y= Pos.Bottom(Win),
- Y = 20,
- IsDefault = true,
- Clicked = () => Application.RequestStop (),
- };
- Win.Add (defaultButton);
- var y = 2;
- var button = new Button (10, y, "Base Color") {
- ColorScheme = Colors.Base,
- Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
- };
- Win.Add (button);
- y += 2;
- Win.Add (new Button (10, y, "Error Color") {
- ColorScheme = Colors.Error,
- Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
- });
- y += 2;
- Win.Add (new Button (10, y, "Dialog Color") {
- ColorScheme = Colors.Dialog,
- Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
- });
- y += 2;
- Win.Add (new Button (10, y, "Menu Color") {
- ColorScheme = Colors.Menu,
- Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
- });
- y += 2;
- Win.Add (new Button (10, y, "TopLevel Color") {
- ColorScheme = Colors.TopLevel,
- Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
- });
- y += 2;
- Win.Add (new Button (10, y, "A super long button that will probably expose a bug in clipping or wrapping of text. Will it?") {
- Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
- });
- y += 2;
- // Note the 'N' in 'Newline' will be the hotkey
- Win.Add (new Button (10, y, "a Newline\nin the button") {
- Clicked = () => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No")
- });
- y += 2;
- // BUGBUG: Buttons don't support specifying hotkeys with _?!?
- Win.Add (button = new Button (10, y, "Te_xt Changer") {
- });
- button.Clicked = () => button.Text += $"{y++}";
- Win.Add (new Button ("Lets see if this will move as \"Text Changer\" grows") {
- X = Pos.Right(button) + 10,
- Y = y,
- });
- y += 2;
- Win.Add (new Button (10, y, "Delete") {
- ColorScheme = Colors.Error,
- Clicked = () => Win.Remove (button)
- });
- y += 2;
- Win.Add (new Button (10, y, "Change Default") {
- Clicked = () => {
- defaultButton.IsDefault = !defaultButton.IsDefault;
- button.IsDefault = !button.IsDefault;
- },
- });
- }
- }
- }
|