diff --git a/Example/demo.cs b/Example/demo.cs index 9d839b8d06..adcc42f8e9 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -202,8 +202,8 @@ 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 (); } }); + new Button ("Ok", is_default: true) { Clicked = (o, e) => { Application.RequestStop (); } }, + new Button ("Cancel") { Clicked = (o, e) => { Application.RequestStop (); } }); ml2 = new Label (1, 1, "Mouse Debug Line"); d.Add (ml2); Application.Run (d); @@ -391,8 +391,8 @@ static void Save () 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 (); } }); + new Button ("Ok", is_default: true) { Clicked = (o, e) => { Application.RequestStop (); } }, + new Button ("Cancel") { Clicked = (o, e) => { Application.RequestStop (); } }); var animals = new List () { "Alpaca", "Llama", "Lion", "Shark", "Goat" }; var msg = new Label ("Use space bar or control-t to toggle selection") { @@ -450,7 +450,7 @@ private static void OnKeyDownPressUpDemo () { var container = new Dialog ( "KeyDown & KeyPress & KeyUp demo", 80, 20, - new Button ("Close") { Clicked = () => { Application.RequestStop (); } }) { + new Button ("Close") { Clicked = (o, e) => { Application.RequestStop (); } }) { Width = Dim.Fill (), Height = Dim.Fill (), }; diff --git a/FSharpExample/Program.fs b/FSharpExample/Program.fs index 62202bd220..30e515a30b 100644 --- a/FSharpExample/Program.fs +++ b/FSharpExample/Program.fs @@ -84,8 +84,8 @@ type Demo() = class end let ShowTextAlignments() = let mutable container = new Dialog( ustr "Text Alignments", 50, 20, - new Button (ustr "Ok", true, Clicked = Action(Application.RequestStop)), - new Button (ustr "Cancel", true, Clicked = Action(Application.RequestStop)) + new Button (ustr "Ok", true, Clicked = fun o e -> Application.RequestStop ()), + new Button (ustr "Cancel", true, Clicked = fun o e -> Application.RequestStop ()) ) let mutable (i : int) = 0 let mutable (txt : string) = "Hello world, how are you doing today" @@ -166,8 +166,8 @@ type Demo() = class end () let NewFile() = let mutable d = new Dialog (ustr "New File", 50, 20, - new Button (ustr "Ok", true, Clicked = Action(Application.RequestStop)), - new Button (ustr "Cancel", true, Clicked = Action(Application.RequestStop)) + new Button (ustr "Ok", true, Clicked = fun o e -> Application.RequestStop ()), + new Button (ustr "Cancel", true, Clicked = fun o e -> Application.RequestStop ()) ) ml2 <- new Label(1, 1, ustr "Mouse Debug Line") d.Add (ml2) @@ -202,18 +202,18 @@ type Demo() = class end Application.Run (ntop) let Quit() = - let mutable n = MessageBox.Query (50, 7, "Quit Demo", "Are you sure you want to quit this demo?", "Yes", "No") + let mutable n = MessageBox.Query (50, 7, ustr "Quit Demo", ustr "Are you sure you want to quit this demo?", ustr "Yes", ustr "No") n = 0 let Close() = - MessageBox.ErrorQuery (50, 7, "Error", "There is nothing to close", "Ok") + MessageBox.ErrorQuery (50, 7, ustr "Error", ustr "There is nothing to close", ustr "Ok") |> ignore let Open() = let mutable d = new OpenDialog (ustr "Open", ustr "Open a file", AllowsMultipleSelection = true) Application.Run (d) if not d.Canceled - then MessageBox.Query (50, 7, "Selected File", (String.Join (", ", d.FilePaths)), "Ok") |> ignore + then MessageBox.Query (50, 7, ustr "Selected File", ustr (String.Join (", ", d.FilePaths)), ustr "Ok") |> ignore let ShowHex(top : Toplevel) = let mutable tframe = top.Frame @@ -255,14 +255,14 @@ type Demo() = class end let mutable (flags : BindingFlags) = BindingFlags.Public ||| BindingFlags.Static let mutable (minfo : MethodInfo) = typeof.GetMethod ("Instance", flags) let mutable (mid : Delegate) = Delegate.CreateDelegate (typeof, minfo) - MessageBox.Query (70, 7, (mi.Title.ToString ()), - ((sprintf "%O selected. Is from submenu: %O" (mi.Title.ToString ())) (mi.GetMenuBarItem ())), "Ok") + MessageBox.Query (70, 7, ustr (mi.Title.ToString ()), + ustr ((sprintf "%O selected. Is from submenu: %O" (mi.Title.ToString ())) (mi.GetMenuBarItem ())), ustr "Ok") |> ignore - let MenuKeysStyle_Toggled(e : EventArgs) = + let MenuKeysStyle_Toggled(e : bool) = menu.UseKeysUpDownAsKeysLeftRight <- menuKeysStyle.Checked - let MenuAutoMouseNav_Toggled(e : EventArgs) = + let MenuAutoMouseNav_Toggled(e : bool) = menu.WantMousePositionReports <- menuAutoMouseNav.Checked let Copy() = @@ -284,13 +284,13 @@ type Demo() = class end () let Help() = - MessageBox.Query (50, 7, "Help", "This is a small help\nBe kind.", "Ok") + MessageBox.Query (50, 7, ustr "Help", ustr "This is a small help\nBe kind.", ustr "Ok") |> ignore let ListSelectionDemo(multiple : System.Boolean) = let mutable d = new Dialog (ustr "Selection Demo", 60, 20, - new Button (ustr "Ok", true, Clicked = fun () -> Application.RequestStop ()), - new Button (ustr "Cancel", Clicked = fun () -> Application.RequestStop ()) + new Button (ustr "Ok", true, Clicked = fun o e -> Application.RequestStop ()), + new Button (ustr "Cancel", Clicked = fun o e -> Application.RequestStop ()) ) let mutable animals = new List () animals.AddRange([|"Alpaca"; "Llama"; "Lion"; "Shark"; "Goat"|]) @@ -319,11 +319,11 @@ type Demo() = class end i <- i + 1 i () - MessageBox.Query (60, 10, "Selected Animals", (if result = "" then "No animals selected" else result), "Ok") |> ignore + MessageBox.Query (60, 10, ustr "Selected Animals", ustr (if result = "" then "No animals selected" else result), ustr "Ok") |> ignore let OnKeyDownPressUpDemo() = let mutable container = new Dialog (ustr "KeyDown & KeyPress & KeyUp demo", 80, 20, - new Button (ustr "Close", Clicked = fun () -> Application.RequestStop ()), + new Button (ustr "Close", Clicked = fun o e -> Application.RequestStop ()), Width = Dim.Fill (), Height = Dim.Fill () ) @@ -395,11 +395,11 @@ type Demo() = class end [|new MenuItem(ustr "SubMenu1Item_1", new MenuBarItem([|new MenuItem(ustr "SubMenu2Item_1", new MenuBarItem([|new MenuItem(ustr "SubMenu3Item_1", new MenuBarItem([|(menuItems.[2])|]))|]))|]))|]); new MenuBarItem(ustr "_About...", "Demonstrates top-level menu item", - (fun () -> MessageBox.ErrorQuery (50, 7, "About Demo", "This is a demo app for gui.cs", "Ok") |> ignore))|]) + (fun () -> MessageBox.ErrorQuery (50, 7, ustr "About Demo", ustr "This is a demo app for gui.cs", ustr "Ok") |> ignore))|]) menuKeysStyle <- new CheckBox(3, 25, ustr "UseKeysUpDownAsKeysLeftRight", true) - menuKeysStyle.Toggled.Add(MenuKeysStyle_Toggled) + menuKeysStyle.Toggled.Add (MenuKeysStyle_Toggled) menuAutoMouseNav <- new CheckBox(40, 25, ustr "UseMenuAutoNavigation", true) - menuAutoMouseNav.Toggled.Add(MenuAutoMouseNav_Toggled) + menuAutoMouseNav.Toggled.Add (MenuAutoMouseNav_Toggled) ShowEntries (win) let mutable (count : int) = 0 ml <- new Label(new Rect(3, 17, 47, 1), ustr "Mouse: ") diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 4bd53a68a8..c5ba80b2f1 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -30,6 +30,7 @@ public class Button : View { Rune hot_key; int hot_pos = -1; bool is_default; + TextAlignment textAlignment = TextAlignment.Centered; /// /// Gets or sets whether the is the default action to activate in a dialog. @@ -45,14 +46,14 @@ public bool IsDefault { } /// - /// Clicked , raised when the button is clicked. + /// Clicked , raised when the button is clicked. /// /// /// Client code can hook up to this event, it is /// raised when the button is activated either with /// the mouse or the keyboard. /// - public Action Clicked; + public EventHandler Clicked; /// /// Initializes a new instance of using layout. @@ -145,6 +146,15 @@ public ustring Text { } } + /// + public TextAlignment TextAlignment { + get => textAlignment; + set { + textAlignment = value; + SetNeedsDisplay (); + } + } + internal void Update () { if (IsDefault) @@ -176,31 +186,91 @@ internal void Update () SetNeedsDisplay (); } + int c_hot_pos; + /// public override void Redraw (Rect bounds) { Driver.SetAttribute (HasFocus ? ColorScheme.Focus : ColorScheme.Normal); Move (0, 0); - Driver.AddStr (shown_text); - if (hot_pos != -1) { - Move (hot_pos, 0); + var caption = shown_text; + c_hot_pos = hot_pos; + int start; + + if (Frame.Width > shown_text.Length + 1) { + switch (TextAlignment) { + case TextAlignment.Left: + caption += new string (' ', Frame.Width - caption.Length); + break; + case TextAlignment.Right: + start = Frame.Width - caption.Length; + caption = $"{new string (' ', Frame.Width - caption.Length)}{caption}"; + if (c_hot_pos > -1) { + c_hot_pos += start; + } + break; + case TextAlignment.Centered: + start = Frame.Width / 2 - caption.Length / 2; + caption = $"{new string (' ', start)}{caption}{new string (' ', Frame.Width - caption.Length - start)}"; + if (c_hot_pos > -1) { + c_hot_pos += start; + } + break; + case TextAlignment.Justified: + var words = caption.ToString ().Split (new string [] { " " }, StringSplitOptions.RemoveEmptyEntries); + var wLen = GetWordsLength (words); + var space = (Frame.Width - wLen) / (caption.Length - wLen); + caption = ""; + for (int i = 0; i < words.Length; i++) { + if (i == words.Length - 1) { + caption += new string (' ', Frame.Width - caption.Length - 1); + caption += words [i]; + } else { + caption += words [i]; + } + if (i < words.Length - 1) { + caption += new string (' ', space); + } + } + if (c_hot_pos > -1) { + c_hot_pos += space - 1; + } + break; + } + } + + Driver.AddStr (caption); + + if (c_hot_pos != -1) { + Move (c_hot_pos, 0); Driver.SetAttribute (HasFocus ? ColorScheme.HotFocus : ColorScheme.HotNormal); Driver.AddRune (hot_key); } } + int GetWordsLength (string[] words) + { + int length = 0; + + for (int i = 0; i < words.Length; i++) { + length += words [i].Length; + } + + return length; + } + /// public override void PositionCursor () { - Move (hot_pos == -1 ? 1 : hot_pos, 0); + Move (c_hot_pos == -1 ? 1 : c_hot_pos, 0); } bool CheckKey (KeyEvent key) { if (Char.ToUpper ((char)key.KeyValue) == hot_key) { this.SuperView.SetFocus (this); - Clicked?.Invoke (); + OnClicked (); return true; } return false; @@ -219,8 +289,7 @@ public override bool ProcessHotKey (KeyEvent kb) public override bool ProcessColdKey (KeyEvent kb) { if (IsDefault && kb.KeyValue == '\n') { - if (Clicked != null) - Clicked (); + OnClicked (); return true; } return CheckKey (kb); @@ -231,8 +300,7 @@ public override bool ProcessKey (KeyEvent kb) { var c = kb.KeyValue; if (c == '\n' || c == ' ' || Rune.ToUpper ((uint)c) == hot_key) { - if (Clicked != null) - Clicked (); + OnClicked (); return true; } return base.ProcessKey (kb); @@ -242,14 +310,23 @@ public override bool ProcessKey (KeyEvent kb) public override bool MouseEvent (MouseEvent me) { if (me.Flags == MouseFlags.Button1Clicked) { - SuperView.SetFocus (this); - SetNeedsDisplay (); + if (!HasFocus) { + SuperView.SetFocus (this); + SetNeedsDisplay (); + } - if (Clicked != null) - Clicked (); + OnClicked (); return true; } return false; } + + /// + /// Virtual method that will invoke the Clicked event handler. + /// + public virtual void OnClicked () + { + Clicked?.Invoke (this, EventArgs.Empty); + } } } diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index f558b13e82..88d81bf6d0 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -260,7 +260,7 @@ public static int MeasureLines (ustring text, int width) } /// - /// Computes the the max width of a line or multilines needed to render by the Label control + /// Computes the max width of a line or multilines needed to render by the Label control /// /// Max width of lines. /// Text, may contain newlines. @@ -285,7 +285,7 @@ public virtual ustring Text { } /// - /// Controls the text-alignemtn property of the label, changing it will redisplay the . + /// Controls the text-alignment property of the label, changing it will redisplay the . /// /// The text alignment. public TextAlignment TextAlignment { diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index 974cfd61a8..0b20b1c148 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -477,7 +477,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameFieldLabel, ustrin dirListView.FileChanged = (file) => nameEntry.Text = file; this.cancel = new Button ("Cancel"); - this.cancel.Clicked += () => { + this.cancel.Clicked += (o, e) => { canceled = true; Application.RequestStop (); }; @@ -486,7 +486,7 @@ public FileDialog (ustring title, ustring prompt, ustring nameFieldLabel, ustrin this.prompt = new Button (prompt) { IsDefault = true, }; - this.prompt.Clicked += () => { + this.prompt.Clicked += (o, e) => { dirListView.ExecuteSelection (); canceled = false; Application.RequestStop (); diff --git a/Terminal.Gui/Windows/MessageBox.cs b/Terminal.Gui/Windows/MessageBox.cs index 3ade88f57a..26f7c1b67e 100644 --- a/Terminal.Gui/Windows/MessageBox.cs +++ b/Terminal.Gui/Windows/MessageBox.cs @@ -142,7 +142,7 @@ static int QueryFull (bool useErrorColors, int width, int height, ustring title, int clicked = -1; for (int n = 0; n < buttonList.Count; n++) { int buttonId = n; - buttonList [n].Clicked += () => { + buttonList [n].Clicked += (o, e) => { clicked = buttonId; Application.RequestStop (); }; diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index ebb69639c9..e8bdc87ebe 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -1,5 +1,6 @@ using NStack; using System; +using System.Collections.Generic; using Terminal.Gui; namespace UICatalog { @@ -26,13 +27,13 @@ public override void Setup () //TODO: Change to use Pos.AnchorEnd() Y = Pos.Bottom (Win) - 3, IsDefault = true, - Clicked = () => Application.RequestStop (), + Clicked = (o, e) => Application.RequestStop (), }; Win.Add (defaultButton); static void DoMessage (Button button, ustring txt) { - button.Clicked = () => { + button.Clicked = (o, e) => { var btnText = button.Text.ToString (); MessageBox.Query (30, 7, "Message", $"Did you click {txt.ToString ()}?", "Yes", "No"); }; @@ -77,7 +78,7 @@ static void DoMessage (Button button, ustring txt) 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") + Clicked = (o, e) => MessageBox.Query (30, 7, "Message", "Question?", "Yes", "No") }); y += 2; @@ -87,7 +88,7 @@ static void DoMessage (Button button, ustring txt) Y = y }); - button.Clicked = () => button.Text += "!"; + button.Clicked = (o, e) => button.Text += "!"; Win.Add (new Button ("Lets see if this will move as \"Text Changer\" grows") { X = Pos.Right (button) + 10, @@ -97,12 +98,12 @@ static void DoMessage (Button button, ustring txt) y += 2; Win.Add (new Button (10, y, "Delete") { ColorScheme = Colors.Error, - Clicked = () => Win.Remove (button) + Clicked = (o, e) => Win.Remove (button) }); y += 2; Win.Add (new Button (10, y, "Change Default") { - Clicked = () => { + Clicked = (o, e) => { defaultButton.IsDefault = !defaultButton.IsDefault; button.IsDefault = !button.IsDefault; }, @@ -113,7 +114,7 @@ static void DoMessage (Button button, ustring txt) var moveBtn = new Button (10, y, "Move This Button via Frame") { ColorScheme = Colors.Error, }; - moveBtn.Clicked = () => { + moveBtn.Clicked = (o, e) => { moveBtn.Frame = new Rect (moveBtn.Frame.X + 5, moveBtn.Frame.Y, moveBtn.Frame.Width, moveBtn.Frame.Height); }; Win.Add (moveBtn); @@ -121,13 +122,52 @@ static void DoMessage (Button button, ustring txt) // Demonstrates how changing the View.Frame property can SIZE Views (#583) y += 2; var sizeBtn = new Button (10, y, "Size This Button via Frame") { - ColorScheme = Colors.Error, + ColorScheme = Colors.Error }; - moveBtn.Clicked = () => { + moveBtn.Clicked = (o, e) => { sizeBtn.Frame = new Rect (sizeBtn.Frame.X, sizeBtn.Frame.Y, sizeBtn.Frame.Width + 5, sizeBtn.Frame.Height); }; Win.Add (sizeBtn); + Win.Add (new Label ("Size This Button via Frame 'Text Alignment'") { + X = Pos.Right (moveBtn) + 20, + Y = Pos.Top (moveBtn) - 4, + }); + + List txtAligs = new List () { + "Left", + "Right", + "Centered", + "Justified" + }; + + var lvTextAlig = new ListView (txtAligs) { + X = Pos.Right (moveBtn) + 20, + Y = Pos.Top (moveBtn) - 3, + Width = 20, + Height = 4, + ColorScheme = Colors.TopLevel + }; + + lvTextAlig.SelectedChanged += (o, e) => { + switch (e.Value) { + case "Left": + sizeBtn.TextAlignment = TextAlignment.Left; + break; + case "Right": + sizeBtn.TextAlignment = TextAlignment.Right; + break; + case "Centered": + sizeBtn.TextAlignment = TextAlignment.Centered; + break; + case "Justified": + sizeBtn.TextAlignment = TextAlignment.Justified; + break; + } + }; + + Win.Add (lvTextAlig); + // Demo changing hotkey ustring MoveHotkey (ustring txt) { @@ -153,7 +193,7 @@ ustring MoveHotkey (ustring txt) var moveHotKeyBtn = new Button (10, y, "Click to Change th_is Button's Hotkey") { ColorScheme = Colors.TopLevel, }; - moveHotKeyBtn.Clicked = () => { + moveHotKeyBtn.Clicked = (o, e) => { moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); }; Win.Add (moveHotKeyBtn); diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index 96288504df..9f28acec28 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -26,7 +26,7 @@ Button CreateBlock(Window win, ustring title, int start, int end, View align) var button = new Button ($"{title} (U+{start:x5}-{end:x5})") { X = Pos.X (align), Y = Pos.Bottom (align), - Clicked = () => { + Clicked = (o, e) => { charMap.Start = start; }, }; diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs index f5e87df87a..bd7a36f80c 100644 --- a/UICatalog/Scenarios/ComputedLayout.cs +++ b/UICatalog/Scenarios/ComputedLayout.cs @@ -125,7 +125,7 @@ public override void Setup () }; // 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 = (o, e) => { // 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 @@ public override void Setup () var leftButton = new Button ("Left") { Y = Pos.Bottom (Win) - 3 }; - leftButton.Clicked = () => { + leftButton.Clicked = (o, e) => { // 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 @@ public override void Setup () X = Pos.Center (), Y = Pos.AnchorEnd () - 1 }; - centerButton.Clicked = () => { + centerButton.Clicked = (o, e) => { // 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 @@ public override void Setup () var rightButton = new Button ("Right") { Y = Pos.Y (centerButton) }; - rightButton.Clicked = () => { + rightButton.Clicked = (o, e) => { // 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 @@ -199,6 +199,101 @@ public override void Setup () Win.Add (rightButton); } + /// + /// Displays a Dialog that uses a wizard (next/prev) idom to step through each class derived from View + /// testing various Computed layout scenarios + /// + private void DemoAllViewClasses () + { + List GetAllViewClassesCollection () + { + List objects = new List (); + foreach (Type type in typeof (View).Assembly.GetTypes () + .Where (myType => myType.IsClass && !myType.IsAbstract && myType.IsPublic && myType.IsSubclassOf (typeof (View)))) { + objects.Add (type); + } + return objects; + } + + var viewClasses = GetAllViewClassesCollection ().OrderByDescending (c => c.Name).ToList (); + var curClass = 0; + + var closeBtn = new Button ("_Close") { + Clicked = (o, e) => { + Application.RequestStop (); + }, + }; + var nextBtn = new Button ("_Next"); + var prevBtn = new Button ("_Previous"); + var dialog = new Dialog ("Demoing all View classs", new [] { prevBtn, nextBtn, closeBtn }); + + var label = new Label ("Class:") { + X = 0, + Y = 0, + }; + dialog.Add (label); + var currentClassLabel = new Label ("") { + X = Pos.Right (label) + 1, + Y = Pos.Y (label), + }; + dialog.Add (currentClassLabel); + + View curView = null; + void SetCurrentClass () + { + currentClassLabel.Text = $"{viewClasses [curClass].Name}"; + + // Remove existing class, if any + if (curView != null) { + dialog.Remove (curView); + curView = null; + } + + // Instantiate view + curView = (View)Activator.CreateInstance (viewClasses [curClass]); + + curView.X = Pos.Center (); + curView.Y = Pos.Center (); + curView.Width = Dim.Fill (5); + curView.Height = Dim.Fill (5); + + // If the view supports a Text property, set it so we have something to look at + if (viewClasses [curClass].GetProperty("Text") != null) { + curView.GetType ().GetProperty ("Text")?.GetSetMethod ()?.Invoke (curView, new [] { ustring.Make("09/10/1966") }); + } + + // If the view supports a Title property, set it so we have something to look at + if (viewClasses [curClass].GetProperty ("Title") != null) { + curView.GetType ().GetProperty ("Title")?.GetSetMethod ()?.Invoke (curView, new [] { ustring.Make ("Test Title") }); + } + + + dialog.Add (curView); + dialog.LayoutSubviews (); + } + + nextBtn.Clicked = (o, e) => { + curClass++; + if (curClass >= viewClasses.Count) { + curClass = 0; + } + SetCurrentClass (); + }; + + prevBtn.Clicked = (o, e) => { + if (curClass == 0) { + curClass = viewClasses.Count - 1; + } else { + curClass--; + } + SetCurrentClass (); + }; + + SetCurrentClass (); + + Application.Run (dialog); + } + public override void Run () { base.Run (); diff --git a/UICatalog/Scenarios/Dialogs.cs b/UICatalog/Scenarios/Dialogs.cs index 7aa6f52fde..d503a2702a 100644 --- a/UICatalog/Scenarios/Dialogs.cs +++ b/UICatalog/Scenarios/Dialogs.cs @@ -116,7 +116,7 @@ public override void Setup () X = Pos.Center(), Y = Pos.Bottom (frame) + 2 , IsDefault = true, - Clicked = () => { + Clicked = (o, e) => { try { int width = int.Parse (widthEdit.Text.ToString ()); int height = int.Parse (heightEdit.Text.ToString ()); @@ -127,7 +127,7 @@ public override void Setup () for (int i = 0; i < numButtons; i++) { var buttonId = i; var button = new Button (btnText [buttonId % 10], is_default: buttonId == 0) { - Clicked = () => { + Clicked = (o, e) => { clicked = buttonId; Application.RequestStop (); }, @@ -141,10 +141,10 @@ public override void Setup () var add = new Button ("Add a button") { X = Pos.Center (), Y = Pos.Center (), - Clicked = () => { + Clicked = (o, e) => { var buttonId = buttons.Count; var button = new Button (btnText [buttonId % 10], is_default: buttonId == 0) { - Clicked = () => { + Clicked = (o, e) => { clicked = buttonId; Application.RequestStop (); }, diff --git a/UICatalog/Scenarios/Generic.cs b/UICatalog/Scenarios/Generic.cs index 5502958bf5..f693f878f8 100644 --- a/UICatalog/Scenarios/Generic.cs +++ b/UICatalog/Scenarios/Generic.cs @@ -10,7 +10,7 @@ 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") + Clicked = (o, e) => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No") }); } } diff --git a/UICatalog/Scenarios/MessageBoxes.cs b/UICatalog/Scenarios/MessageBoxes.cs index 24dafb2922..b72930422f 100644 --- a/UICatalog/Scenarios/MessageBoxes.cs +++ b/UICatalog/Scenarios/MessageBoxes.cs @@ -148,7 +148,7 @@ public override void Setup () X = Pos.Center(), Y = Pos.Bottom (frame) + 2 , IsDefault = true, - Clicked = () => { + Clicked = (o, e) => { try { int width = int.Parse (widthEdit.Text.ToString ()); int height = int.Parse (heightEdit.Text.ToString ()); diff --git a/UICatalog/Scenarios/Progress.cs b/UICatalog/Scenarios/Progress.cs index 1db61a335c..4864ede048 100644 --- a/UICatalog/Scenarios/Progress.cs +++ b/UICatalog/Scenarios/Progress.cs @@ -58,17 +58,17 @@ internal ProgressDemo (ustring title) : base (title) var startButton = new Button ("Start Timer") { X = Pos.Right (LeftFrame) + 1, Y = 0, - Clicked = () => Start() + Clicked = (o, e) => Start() }; var pulseButton = new Button ("Pulse") { X = Pos.Right (startButton) + 2, Y = Pos.Y (startButton), - Clicked = () => Pulse() + Clicked = (o, e) => Pulse() }; var stopbutton = new Button ("Stop Timer") { X = Pos.Right (pulseButton) + 2, Y = Pos.Top (pulseButton), - Clicked = () => Stop() + Clicked = (o, e) => Stop() }; Add (startButton); @@ -225,7 +225,7 @@ public override void Setup () X = Pos.Center (), Y = Pos.Bottom(mainLoopTimeoutDemo) + 1, }; - startBoth.Clicked = () => { + startBoth.Clicked = (o, e) => { systemTimerDemo.Start (); mainLoopTimeoutDemo.Start (); }; diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 27425d61de..e71b2856d7 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -131,14 +131,14 @@ public override void Setup () scrollView.Add (new Button ("Press me!") { X = 3, Y = 3, - Clicked = () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No") + Clicked = (o, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No") }); scrollView.Add (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") + Clicked = (o, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No") }); scrollView.Add (new TextField ("This is a test of...") { @@ -168,7 +168,7 @@ public override void Setup () }; // 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 = (o, e) => { // 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 diff --git a/UICatalog/Scenarios/SystemConsole.cs b/UICatalog/Scenarios/SystemConsole.cs index a27ce57891..0f0bfee203 100644 --- a/UICatalog/Scenarios/SystemConsole.cs +++ b/UICatalog/Scenarios/SystemConsole.cs @@ -27,7 +27,7 @@ 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") + Clicked = (o, e) => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No") }); } } diff --git a/UICatalog/Scenarios/Threading.cs b/UICatalog/Scenarios/Threading.cs index 37fbe12a7e..b8c5c9baec 100644 --- a/UICatalog/Scenarios/Threading.cs +++ b/UICatalog/Scenarios/Threading.cs @@ -46,7 +46,7 @@ public override void Setup () _btnActionCancel = new Button (1, 1, "Cancelable Load Items"); - _btnActionCancel.Clicked += () => Application.MainLoop.Invoke (CallLoadItemsAsync); + _btnActionCancel.Clicked += (o, e) => Application.MainLoop.Invoke (CallLoadItemsAsync); Win.Add (new Label ("Data Items:") { X = Pos.X (_btnActionCancel), @@ -77,19 +77,19 @@ public override void Setup () var text = new TextField (1, 3, 100, "Type anything after press the button"); var _btnAction = new Button (80, 10, "Load Data Action"); - _btnAction.Clicked += () => _action.Invoke (); + _btnAction.Clicked += (o, e) => _action.Invoke (); var _btnLambda = new Button (80, 12, "Load Data Lambda"); - _btnLambda.Clicked += () => _lambda.Invoke (); + _btnLambda.Clicked += (o, e) => _lambda.Invoke (); var _btnHandler = new Button (80, 14, "Load Data Handler"); - _btnHandler.Clicked += () => _handler.Invoke (null, new EventArgs ()); + _btnHandler.Clicked += (o, e) => _handler.Invoke (null, new EventArgs ()); var _btnSync = new Button (80, 16, "Load Data Synchronous"); - _btnSync.Clicked += () => _sync.Invoke (); + _btnSync.Clicked += (o, e) => _sync.Invoke (); var _btnMethod = new Button (80, 18, "Load Data Method"); - _btnMethod.Clicked += async () => await MethodAsync (); + _btnMethod.Clicked += async (o, e) => await MethodAsync (); var _btnClearData = new Button (80, 20, "Clear Data"); - _btnClearData.Clicked += () => { _itemsList.Source = null; LogJob ("Cleaning Data"); }; + _btnClearData.Clicked += (o, e) => { _itemsList.Source = null; LogJob ("Cleaning Data"); }; var _btnQuit = new Button (80, 22, "Quit"); - _btnQuit.Clicked += Application.RequestStop; + _btnQuit.Clicked += (o, e) => Application.RequestStop (); Win.Add (_itemsList, _btnActionCancel, _logJob, text, _btnAction, _btnLambda, _btnHandler, _btnSync, _btnMethod, _btnClearData, _btnQuit); diff --git a/UICatalog/Scenarios/TimeAndDate.cs b/UICatalog/Scenarios/TimeAndDate.cs index d24aab005c..69225f7dfe 100644 --- a/UICatalog/Scenarios/TimeAndDate.cs +++ b/UICatalog/Scenarios/TimeAndDate.cs @@ -43,7 +43,7 @@ public override void Setup () Win.Add (new Button ("Swap Long/Short & Read/Read Only") { X = Pos.Center (), Y = Pos.Bottom (Win) - 5, - Clicked = () => { + Clicked = (o, e) => { longTime.ReadOnly = !longTime.ReadOnly; shortTime.ReadOnly = !shortTime.ReadOnly; diff --git a/UICatalog/Scenarios/WindowsAndFrameViews.cs b/UICatalog/Scenarios/WindowsAndFrameViews.cs index 4ffbf2c3c3..0527263c2d 100644 --- a/UICatalog/Scenarios/WindowsAndFrameViews.cs +++ b/UICatalog/Scenarios/WindowsAndFrameViews.cs @@ -64,7 +64,7 @@ static int About () X = Pos.Center (), Y = 0, ColorScheme = Colors.Error, - Clicked = () => About() + Clicked = (o, e) => About() }); Win.Add (new Button ("Press ME! (Y = Pos.AnchorEnd(1))") { X = Pos.Center (), @@ -87,7 +87,7 @@ static int About () X = Pos.Center (), Y = 0, ColorScheme = Colors.Error, - Clicked = () => MessageBox.ErrorQuery (win.Title.ToString (), "Neat?", "Yes", "No") + Clicked = (o, e) => MessageBox.ErrorQuery (win.Title.ToString (), "Neat?", "Yes", "No") }); var subWin = new Window ("Sub Window") { X = Pos.Percent (0),