From af0efb3c647addf32c622fed8cdf6d75de30ce7d Mon Sep 17 00:00:00 2001 From: Tig Date: Fri, 19 Dec 2025 20:02:04 -0700 Subject: [PATCH] Partially modernizes Scenarios (#4512) --- Examples/UICatalog/Scenarios/Bars.cs | 334 +++++----- Examples/UICatalog/Scenarios/Buttons.cs | 402 +++++++----- .../Scenarios/CharacterMap/CharacterMap.cs | 6 +- .../Scenarios/EditorsAndHelpers/EditorBase.cs | 10 +- .../Scenarios/EditorsAndHelpers/EventLog.cs | 1 - Examples/UICatalog/Scenarios/Keys.cs | 1 - Examples/UICatalog/Scenarios/LineDrawing.cs | 36 +- Examples/UICatalog/Scenarios/Mouse.cs | 369 ----------- Examples/UICatalog/Scenarios/MouseTester.cs | 604 ++++++++++++++++++ .../UICatalog/Scenarios/NumericUpDownDemo.cs | 365 +++++------ .../UICatalog/Scenarios/RegionScenario.cs | 192 +++--- Examples/UICatalog/Scenarios/TableEditor.cs | 12 +- .../Scenarios/TextAlignmentAndDirection.cs | 2 +- Examples/UICatalog/Scenarios/Transparent.cs | 2 +- .../UICatalog/Scenarios/TreeViewFileSystem.cs | 10 +- .../UICatalog/Scenarios/ViewportSettings.cs | 2 +- Examples/UICatalog/UICatalogRunnable.cs | 4 +- 17 files changed, 1307 insertions(+), 1045 deletions(-) delete mode 100644 Examples/UICatalog/Scenarios/Mouse.cs create mode 100644 Examples/UICatalog/Scenarios/MouseTester.cs diff --git a/Examples/UICatalog/Scenarios/Bars.cs b/Examples/UICatalog/Scenarios/Bars.cs index 19a561631..616b31684 100644 --- a/Examples/UICatalog/Scenarios/Bars.cs +++ b/Examples/UICatalog/Scenarios/Bars.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Text; namespace UICatalog.Scenarios; @@ -14,24 +9,27 @@ public class Bars : Scenario public override void Main () { Application.Init (); - Runnable app = new (); + using IApplication app = Application.Instance; - app.IsModalChanged += App_Loaded; + using Runnable mainWindow = new (); - Application.Run (app); - app.Dispose (); - Application.Shutdown (); + mainWindow.IsModalChanged += App_Loaded; + + app.Run (mainWindow); } - // Setting everything up in Loaded handler because we change the - // QuitKey and it only sticks if changed after init + // QuitKey it only sticks if changed after init private void App_Loaded (object sender, EventArgs e) { - Application.TopRunnableView!.Title = GetQuitKeyAndName (); + if (sender is not Runnable mainWindow) + { + return; + } ObservableCollection eventSource = new (); - ListView eventLog = new ListView () + + ListView eventLog = new () { Title = "Event Log", X = Pos.AnchorEnd (), @@ -41,7 +39,7 @@ public class Bars : Scenario Source = new ListWrapper (eventSource) }; eventLog.Border!.Thickness = new (0, 1, 0, 0); - Application.TopRunnableView.Add (eventLog); + mainWindow.Add (eventLog); FrameView menuBarLikeExamples = new () { @@ -49,30 +47,30 @@ public class Bars : Scenario X = 0, Y = 0, Width = Dim.Fill () - Dim.Width (eventLog), - Height = Dim.Percent(33), + Height = Dim.Percent (33) }; - Application.TopRunnableView.Add (menuBarLikeExamples); + mainWindow.Add (menuBarLikeExamples); - Label label = new Label () + Label label = new () { Title = " Bar:", X = 0, - Y = 0, + Y = 0 }; menuBarLikeExamples.Add (label); - Bar bar = new Bar + Bar bar = new () { Id = "menuBar-like", X = Pos.Right (label), Y = Pos.Top (label), - Width = Dim.Fill (), + Width = Dim.Fill () }; ConfigMenuBar (bar); menuBarLikeExamples.Add (bar); - label = new Label () + label = new () { Title = " MenuBar:", X = 0, @@ -96,80 +94,171 @@ public class Bars : Scenario X = 0, Y = Pos.Center (), Width = Dim.Fill () - Dim.Width (eventLog), - Height = Dim.Percent (33), + Height = Dim.Percent (33) }; - Application.TopRunnableView.Add (menuLikeExamples); + mainWindow.Add (menuLikeExamples); - label = new Label () + label = new () { Title = "Bar:", X = 0, - Y = 0, + Y = 0 }; menuLikeExamples.Add (label); - bar = new Bar + bar = new () { Id = "menu-like", X = 0, - Y = Pos.Bottom(label), + Y = Pos.Bottom (label), + //Width = Dim.Percent (40), - Orientation = Orientation.Vertical, + Orientation = Orientation.Vertical }; ConfigureMenu (bar); menuLikeExamples.Add (bar); - label = new Label () + label = new () { Title = "Menu:", - X = Pos.Right(bar) + 1, - Y = Pos.Top (label), + X = Pos.Right (bar) + 1, + Y = Pos.Top (label) }; menuLikeExamples.Add (label); - bar = new Menu + bar = new () { Id = "menu", X = Pos.Left (label), - Y = Pos.Bottom (label), + Y = Pos.Bottom (label) }; ConfigureMenu (bar); bar.Arrangement = ViewArrangement.RightResizable; menuLikeExamples.Add (bar); - label = new Label () + label = new () { Title = "PopOver Menu (Right click to show):", X = Pos.Right (bar) + 1, - Y = Pos.Top (label), + Y = Pos.Top (label) }; menuLikeExamples.Add (label); - Menu popOverMenu = new Menu + Menu popOverMenu = new () { Id = "popupMenu", X = Pos.Left (label), - Y = Pos.Bottom (label), + Y = Pos.Bottom (label) }; ConfigureMenu (popOverMenu); popOverMenu.Arrangement = ViewArrangement.Overlapped; popOverMenu.Visible = false; + //popOverMenu.Enabled = false; - var toggleShortcut = new Shortcut + Shortcut toggleShortcut = new () { Title = "Toggle Hide", Text = "App", BindKeyToApplication = true, - Key = Key.F4.WithCtrl, + Key = Key.F4.WithCtrl }; popOverMenu.Add (toggleShortcut); popOverMenu.Accepting += PopOverMenuOnAccept; + menuLikeExamples.Add (popOverMenu); + + menuLikeExamples.MouseEvent += MenuLikeExamplesMouseEvent; + + FrameView statusBarLikeExamples = new () + { + Title = "StatusBar-Like Examples", + X = 0, + Y = Pos.AnchorEnd (), + Width = Dim.Width (menuLikeExamples), + Height = Dim.Percent (33) + }; + mainWindow.Add (statusBarLikeExamples); + + label = new () + { + Title = " Bar:", + X = 0, + Y = 0 + }; + statusBarLikeExamples.Add (label); + + bar = new() + { + Id = "statusBar-like", + X = Pos.Right (label), + Y = Pos.Top (label), + Width = Dim.Fill (), + Orientation = Orientation.Horizontal + }; + ConfigStatusBar (bar); + statusBarLikeExamples.Add (bar); + + label = new () + { + Title = "StatusBar:", + X = 0, + Y = Pos.Bottom (bar) + 1 + }; + statusBarLikeExamples.Add (label); + + bar = new () + { + Id = "statusBar", + X = Pos.Right (label), + Y = Pos.Top (label), + Width = Dim.Fill () + }; + ConfigStatusBar (bar); + statusBarLikeExamples.Add (bar); + + foreach (FrameView frameView in mainWindow.SubViews.OfType ()) + { + foreach (Bar barView in frameView.SubViews.OfType ()) + { + foreach (Shortcut sh in barView.SubViews.OfType ()) + { + sh.Accepting += (_, _) => + { + eventSource.Add ($"Accept: {sh!.SuperView!.Id} {sh!.CommandView.Text}"); + eventLog.MoveDown (); + + //args.Handled = true; + }; + } + } + } + + return; + + void MenuLikeExamplesMouseEvent (object _, MouseEventArgs mouse) + { + if (mouse.Flags.HasFlag (MouseFlags.Button3Clicked)) + { + popOverMenu.X = mouse.Position.X; + popOverMenu.Y = mouse.Position.Y; + popOverMenu.Visible = true; + + //popOverMenu.Enabled = popOverMenu.Visible; + popOverMenu.SetFocus (); + } + else + { + popOverMenu.Visible = false; + + //popOverMenu.Enabled = popOverMenu.Visible; + } + } + void PopOverMenuOnAccept (object o, CommandEventArgs args) { if (popOverMenu.Visible) @@ -182,91 +271,8 @@ public class Bars : Scenario popOverMenu.SetFocus (); } } - - menuLikeExamples.Add (popOverMenu); - - menuLikeExamples.MouseEvent += MenuLikeExamplesMouseEvent; - - void MenuLikeExamplesMouseEvent (object _, MouseEventArgs e) - { - if (e.Flags.HasFlag (MouseFlags.Button3Clicked)) - { - popOverMenu.X = e.Position.X; - popOverMenu.Y = e.Position.Y; - popOverMenu.Visible = true; - //popOverMenu.Enabled = popOverMenu.Visible; - popOverMenu.SetFocus (); - } - else - { - popOverMenu.Visible = false; - //popOverMenu.Enabled = popOverMenu.Visible; - } - } - - FrameView statusBarLikeExamples = new () - { - Title = "StatusBar-Like Examples", - X = 0, - Y = Pos.AnchorEnd (), - Width = Dim.Width (menuLikeExamples), - Height = Dim.Percent (33), - }; - Application.TopRunnableView.Add (statusBarLikeExamples); - - label = new Label () - { - Title = " Bar:", - X = 0, - Y = 0, - }; - statusBarLikeExamples.Add (label); - bar = new Bar - { - Id = "statusBar-like", - X = Pos.Right (label), - Y = Pos.Top (label), - Width = Dim.Fill (), - Orientation = Orientation.Horizontal, - }; - ConfigStatusBar (bar); - statusBarLikeExamples.Add (bar); - - label = new Label () - { - Title = "StatusBar:", - X = 0, - Y = Pos.Bottom (bar) + 1, - }; - statusBarLikeExamples.Add (label); - bar = new StatusBar () - { - Id = "statusBar", - X = Pos.Right (label), - Y = Pos.Top (label), - Width = Dim.Fill (), - }; - ConfigStatusBar (bar); - statusBarLikeExamples.Add (bar); - - foreach (FrameView frameView in Application.TopRunnableView.SubViews.Where (f => f is FrameView)!) - { - foreach (Bar barView in frameView.SubViews.Where (b => b is Bar)!) - { - foreach (Shortcut sh in barView.SubViews.Where (s => s is Shortcut)!) - { - sh.Accepting += (o, args) => - { - eventSource.Add ($"Accept: {sh!.SuperView.Id} {sh!.CommandView.Text}"); - eventLog.MoveDown (); - //args.Handled = true; - }; - } - } - } } - //private void SetupContentMenu () //{ // Application.TopRunnable.Add (new Label { Text = "Right Click for Context Menu", X = Pos.Center (), Y = 4 }); @@ -407,10 +413,9 @@ public class Bars : Scenario // Application.MouseEvent -= Application_MouseEvent; //} - private void ConfigMenuBar (Bar bar) { - var fileMenuBarItem = new Shortcut + Shortcut fileMenuBarItem = new () { Title = "_File", HelpText = "File Menu", @@ -418,7 +423,7 @@ public class Bars : Scenario HighlightStates = MouseState.In }; - var editMenuBarItem = new Shortcut + Shortcut editMenuBarItem = new () { Title = "_Edit", HelpText = "Edit Menu", @@ -426,7 +431,7 @@ public class Bars : Scenario HighlightStates = MouseState.In }; - var helpMenuBarItem = new Shortcut + Shortcut helpMenuBarItem = new () { Title = "_Help", HelpText = "Halp Menu", @@ -439,8 +444,7 @@ public class Bars : Scenario private void ConfigureMenu (Bar bar) { - - var shortcut1 = new Shortcut + Shortcut shortcut1 = new () { Title = "Z_igzag", Key = Key.I.WithCtrl, @@ -448,7 +452,7 @@ public class Bars : Scenario HighlightStates = MouseState.In }; - var shortcut2 = new Shortcut + Shortcut shortcut2 = new () { Title = "Za_G", Text = "Gonna zag", @@ -456,7 +460,7 @@ public class Bars : Scenario HighlightStates = MouseState.In }; - var shortcut3 = new Shortcut + Shortcut shortcut3 = new () { Title = "_Three", Text = "The 3rd item", @@ -464,13 +468,13 @@ public class Bars : Scenario HighlightStates = MouseState.In }; - var line = new Line () + Line line = new () { X = -1, Width = Dim.Fill ()! + 1 }; - var shortcut4 = new Shortcut + Shortcut shortcut4 = new () { Title = "_Four", Text = "Below the line", @@ -478,39 +482,40 @@ public class Bars : Scenario HighlightStates = MouseState.In }; - shortcut4.CommandView = new CheckBox () + shortcut4.CommandView = new CheckBox { Title = shortcut4.Title, HighlightStates = MouseState.None, CanFocus = false }; + // This ensures the checkbox state toggles when the hotkey of Title is pressed. - shortcut4.Accepting += (sender, args) => args.Handled = true; + shortcut4.Accepting += (_, args) => args.Handled = true; bar.Add (shortcut1, shortcut2, shortcut3, line, shortcut4); } public void ConfigStatusBar (Bar bar) { - var shortcut = new Shortcut + Shortcut shortcut = new () { Text = "Quit", Title = "Q_uit", - Key = Key.Z.WithCtrl, + Key = Key.Z.WithCtrl }; bar.Add (shortcut); - shortcut = new Shortcut + shortcut = new () { Text = "Help Text", Title = "Help", - Key = Key.F1, + Key = Key.F1 }; bar.Add (shortcut); - shortcut = new Shortcut + shortcut = new () { Title = "_Show/Hide", Key = Key.F10, @@ -518,45 +523,48 @@ public class Bars : Scenario { CanFocus = false, Text = "_Show/Hide" - }, + } }; bar.Add (shortcut); - var button1 = new Button + Button button1 = new () { - Text = "I'll Hide", + Text = "I'll Hide" + // Visible = false }; - button1.Accepting += Button_Clicked; + button1.Accepting += ButtonClicked; bar.Add (button1); - shortcut.Accepting += (s, e) => - { - button1.Visible = !button1.Visible; - button1.Enabled = button1.Visible; - e.Handled = true; - }; + shortcut.Accepting += (_, e) => + { + button1.Visible = !button1.Visible; + button1.Enabled = button1.Visible; + e.Handled = true; + }; - bar.Add (new Label - { - HotKeySpecifier = new Rune ('_'), - Text = "Fo_cusLabel", - CanFocus = true - }); + bar.Add ( + new Label + { + HotKeySpecifier = new ('_'), + Text = "Fo_cusLabel", + CanFocus = true + }); - var button2 = new Button + Button middleButton = new () { - Text = "Or me!", + Text = "Or me!" }; - button2.Accepting += (s, e) => Application.RequestStop (); + middleButton.Accepting += (s, _) => (s as View)?.App!.RequestStop (); - bar.Add (button2); + bar.Add (middleButton); return; - void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ((sender as View)?.App, "Hi", $"You clicked {sender}"); } - + static void ButtonClicked (object sender, EventArgs e) + { + MessageBox.Query ((sender as View)?.App!, "Hi", $"You clicked {sender}"); + } } - } diff --git a/Examples/UICatalog/Scenarios/Buttons.cs b/Examples/UICatalog/Scenarios/Buttons.cs index f0078564a..7b5c5f318 100644 --- a/Examples/UICatalog/Scenarios/Buttons.cs +++ b/Examples/UICatalog/Scenarios/Buttons.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Text; -using JetBrains.Annotations; +using System.Text; namespace UICatalog.Scenarios; @@ -14,30 +10,29 @@ public class Buttons : Scenario public override void Main () { Application.Init (); + using IApplication app = Application.Instance; - Window main = new () - { - Title = GetQuitKeyAndName () - }; + using Window main = new (); + main.Title = GetQuitKeyAndName (); // Add a label & text field so we can demo IsDefault - var editLabel = new Label { X = 0, Y = 0, Text = "TextField (to demo IsDefault):" }; + Label editLabel = new () { X = 0, Y = 0, Text = "TextField (to demo IsDefault):" }; main.Add (editLabel); - // Add a TextField using Absolute layout. - var edit = new TextField { X = 31, Width = 15, HotKey = Key.Y.WithAlt }; + // Add a TextField using Absolute layout. + TextField edit = new () { X = 31, Width = 15, HotKey = Key.Y.WithAlt }; main.Add (edit); // This is the default button (IsDefault = true); if user presses ENTER in the TextField // the scenario will quit - var defaultButton = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (), IsDefault = true, Text = "_Quit" }; + Button defaultButton = new () { X = Pos.Center (), Y = Pos.AnchorEnd (), IsDefault = true, Text = "_Quit" }; main.Add (defaultButton); // Note we handle Accept on main, not defaultButton - main.Accepting += (s, e) => Application.RequestStop (); + main.Accepting += (s, _) => (s as View)?.App!.RequestStop (); - var swapButton = new Button + Button swapButton = new () { X = 50, Width = 45, @@ -46,47 +41,41 @@ public class Buttons : Scenario SchemeName = "Error" }; - swapButton.Accepting += (s, e) => - { - e.Handled = !swapButton.IsDefault; - defaultButton.IsDefault = !defaultButton.IsDefault; - swapButton.IsDefault = !swapButton.IsDefault; - }; + swapButton.Accepting += (_, e) => + { + e.Handled = !swapButton.IsDefault; + defaultButton.IsDefault = !defaultButton.IsDefault; + swapButton.IsDefault = !swapButton.IsDefault; + }; defaultButton.Accepting += (s, e) => - { - e.Handled = !defaultButton.IsDefault; + { + e.Handled = !defaultButton.IsDefault; - if (e.Handled) - { - MessageBox.ErrorQuery ((s as View)?.App, "Error", "This button is no longer the Quit button; the Swap Default button is.", "_Ok"); - } - }; + if (e.Handled) + { + MessageBox.ErrorQuery ( + (s as View)?.App!, + "Error", + "This button is no longer the Quit button; the Swap Default button is.", + "_Ok"); + } + }; main.Add (swapButton); - static void DoMessage (Button button, string txt) - { - button.Accepting += (s, e) => - { - string btnText = button.Text; - MessageBox.Query ((s as View)?.App, "Message", $"Did you click {txt}?", "Yes", "No"); - e.Handled = true; - }; - } - - var colorButtonsLabel = new Label { X = 0, Y = Pos.Bottom (swapButton) + 1, Text = "Color Buttons: " }; + Label colorButtonsLabel = new () { X = 0, Y = Pos.Bottom (swapButton) + 1, Text = "Color Buttons: " }; main.Add (colorButtonsLabel); View prev = colorButtonsLabel; foreach (KeyValuePair scheme in SchemeManager.GetSchemesForCurrentTheme ()) { - var colorButton = new Button + Button colorButton = new () { X = Pos.Right (prev), Y = Pos.Y (colorButtonsLabel), Text = $"_{scheme.Key}", - SchemeName = scheme.Key, + SchemeName = scheme.Key }; DoMessage (colorButton, colorButton.Text); main.Add (colorButton); @@ -108,59 +97,62 @@ public class Buttons : Scenario // Note the 'N' in 'Newline' will be the hotkey main.Add ( - button = new () { X = 2, Y = Pos.Bottom (button) + 1, Height = 2, Text = "a Newline\nin the button" } + button = new () { X = 2, Y = Pos.Bottom (button), Height = 2, Text = "a Newline\nin the button" } ); - button.Accepting += (s, e) => - { - MessageBox.Query ((s as View)?.App, "Message", "Question?", "Yes", "No"); - e.Handled = true; - }; - var textChanger = new Button { X = 2, Y = Pos.Bottom (button) + 1, Text = "Te_xt Changer" }; + button.Accepting += (s, e) => + { + MessageBox.Query ((s as View)?.App!, "Message", "Is There A Question?", "Yes", "No"); + e.Handled = true; + }; + + var textChanger = new Button { X = 2, Y = Pos.Bottom (button), Text = "Te_xt Changer" }; main.Add (textChanger); - textChanger.Accepting += (s, e) => - { - textChanger.Text += "!"; - e.Handled = true; - }; + + textChanger.Accepting += (_, e) => + { + textChanger.Text += "!"; + e.Handled = true; + }; main.Add ( button = new () { X = Pos.Right (textChanger) + 2, Y = Pos.Y (textChanger), - Text = "Lets see if this will move as \"Text Changer\" grows" + Text = """This will move as "Text Changer" grows""" } ); - button.Accepting += (sender, args) => { args.Handled = true; }; - var removeButton = new Button + button.Accepting += (_, args) => { args.Handled = true; }; + + Button removeButton = new () { - X = 2, Y = Pos.Bottom (button) + 1, + X = 2, Y = Pos.Bottom (button), SchemeName = SchemeManager.SchemesToSchemeName (Schemes.Error), - Text = "Remove this button" + Title = "Press to remove this button" }; main.Add (removeButton); // This in interesting test case because `moveBtn` and below are laid out relative to this one! - removeButton.Accepting += (s, e) => - { - removeButton.Visible = false; - e.Handled = true; - }; + removeButton.Accepting += (_, e) => + { + removeButton.Visible = false; + e.Handled = true; + }; - var computedFrame = new FrameView + FrameView computedFrame = new () { X = 0, - Y = Pos.Bottom (removeButton) + 1, + Y = Pos.Bottom (removeButton), Width = Dim.Percent (50), Height = 6, - Title = "Computed Layout" + Title = "Frame (Width = 50%)" }; main.Add (computedFrame); // Demonstrates how changing the View.Frame property can move Views - var moveBtn = new Button + Button moveBtn = new () { X = 0, Y = Pos.Center () - 1, @@ -169,88 +161,82 @@ public class Buttons : Scenario Text = "Move This \u263b Button v_ia Pos" }; - moveBtn.Accepting += (s, e) => - { - moveBtn.X = moveBtn.Frame.X + 5; - e.Handled = true; - }; + moveBtn.Accepting += (_, e) => + { + moveBtn.X = moveBtn.Frame.X + 5; + e.Handled = true; + }; computedFrame.Add (moveBtn); // Demonstrates how changing the View.Frame property can SIZE Views (#583) - var sizeBtn = new Button + Button sizeBtn = new () { Y = Pos.Center () + 1, X = 0, Width = 30, Text = "Grow This \u263a Button _via Pos", - SchemeName = "Error", + SchemeName = "Error" }; - sizeBtn.Accepting += (s, e) => - { - sizeBtn.Width = sizeBtn.Frame.Width + 5; - e.Handled = true; - }; + sizeBtn.Accepting += (_, e) => + { + sizeBtn.Width = sizeBtn.Frame.Width + 5; + e.Handled = true; + }; computedFrame.Add (sizeBtn); - var absoluteFrame = new FrameView + FrameView absoluteFrame = new () { X = Pos.Right (computedFrame), - Y = Pos.Bottom (removeButton) + 1, + Y = Pos.Top (computedFrame), Width = Dim.Fill (), - Height = 6, - Title = "Absolute Layout" + Height = Dim.Height (computedFrame), + Title = "Frame (Width = Fill)" }; main.Add (absoluteFrame); // Demonstrates how changing the View.Frame property can move Views - var moveBtnA = new Button { SchemeName = "Error", Text = "Move This Button via Frame" }; + Button moveBtnA = new () { SchemeName = "Error", Text = "Move This Button via Frame" }; - moveBtnA.Accepting += (s, e) => - { - moveBtnA.Frame = new ( - moveBtnA.Frame.X + 5, - moveBtnA.Frame.Y, - moveBtnA.Frame.Width, - moveBtnA.Frame.Height - ); - e.Handled = true; - }; + moveBtnA.Accepting += (_, e) => + { + moveBtnA.Frame = moveBtnA.Frame with { X = moveBtnA.Frame.X + 5 }; + e.Handled = true; + }; absoluteFrame.Add (moveBtnA); // Demonstrates how changing the View.Frame property can SIZE Views (#583) - var sizeBtnA = new Button + Button sizeBtnA = new () { - Y = 2, SchemeName = "Error", Text = " ~  s  gui.cs   master ↑_10 = Сохранить" + Y = 2, SchemeName = "Error", Text = " ~  s  gui.cs   main ↑_10 = Сохранить" }; - sizeBtnA.Accepting += (s, e) => - { - sizeBtnA.Frame = new ( - sizeBtnA.Frame.X, - sizeBtnA.Frame.Y, - sizeBtnA.Frame.Width + 5, - sizeBtnA.Frame.Height - ); - e.Handled = true; - }; + sizeBtnA.Accepting += (_, e) => + { + sizeBtnA.Frame = sizeBtnA.Frame with { Width = sizeBtnA.Frame.Width + 5 }; + e.Handled = true; + }; absoluteFrame.Add (sizeBtnA); - var label = new Label + Label label = new () { - X = 2, Y = Pos.Bottom (computedFrame) + 1, - Text = "Text Ali_gnment (changes the four buttons above): " + X = 2, Y = Pos.Bottom (computedFrame), + + // ReSharper disable once StringLiteralTypo + Text = "Text Ali_gnment (changes all buttons): " }; main.Add (label); OptionSelector osAlignment = new () { - X = 4, - Y = Pos.Bottom (label) + 1, + X = Pos.Right (label) + 1, + Y = Pos.Top (label), + Width = 20, Value = Alignment.Center, AssignHotKeys = true, Title = "_9 OptionSelector", - BorderStyle = LineStyle.Dotted, + BorderStyle = LineStyle.Dotted + // CanFocus = false }; main.Add (osAlignment); @@ -287,143 +273,211 @@ public class Buttons : Scenario return start + '_' + StringExtensions.ToString (runes.GetRange (i, runes.Count - i)); } - var mhkb = "Click to Change th_is Button's Hotkey"; - - var moveHotKeyBtn = new Button + Button moveHotKeyBtn = new () { X = 2, - Y = Pos.Bottom (osAlignment) + 1, + Y = Pos.Bottom (osAlignment), Width = Dim.Width (computedFrame) - 2, SchemeName = "Runnable", - Text = mhkb + Text = "Click to Change th_is Button's Hotkey" }; - moveHotKeyBtn.Accepting += (s, e) => - { - moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); - e.Handled = true; - }; + + moveHotKeyBtn.Accepting += (_, e) => + { + moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text); + e.Handled = true; + }; main.Add (moveHotKeyBtn); - var muhkb = " ~  s  gui.cs   master ↑10 = Сохранить"; - - var moveUnicodeHotKeyBtn = new Button + Button moveUnicodeHotKeyBtn = new () { X = Pos.Left (absoluteFrame) + 1, - Y = Pos.Bottom (osAlignment) + 1, + Y = Pos.Bottom (osAlignment), Width = Dim.Width (absoluteFrame) - 2, SchemeName = "Runnable", - Text = muhkb + Text = " ~  s  gui.cs   main ↑10 = Сохранить" }; - moveUnicodeHotKeyBtn.Accepting += (s, e) => - { - moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); - e.Handled = true; - }; + + moveUnicodeHotKeyBtn.Accepting += (_, e) => + { + moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); + e.Handled = true; + }; main.Add (moveUnicodeHotKeyBtn); - osAlignment.ValueChanged += (s, args) => + osAlignment.ValueChanged += (_, args) => { if (args.Value is null) { return; } - Alignment newValue = args.Value.Value; - moveBtn.TextAlignment = newValue; - sizeBtn.TextAlignment = newValue; - moveBtnA.TextAlignment = newValue; - sizeBtnA.TextAlignment = newValue; - moveHotKeyBtn.TextAlignment = newValue; - moveUnicodeHotKeyBtn.TextAlignment = newValue; + // ReSharper disable once AccessToDisposedClosure + SetTextAlignmentForAllButtons (main, args.Value.Value); }; label = new () { X = 0, Y = Pos.Bottom (moveUnicodeHotKeyBtn) + 1, - Title = "_Numeric Up/Down (press-and-hold):", + Title = "Numeric Up/Down (press-and-_hold):" }; - var numericUpDown = new NumericUpDown + NumericUpDown numericUpDown = new () { Value = 69, X = Pos.Right (label) + 1, - Y = Pos.Top (label), + Y = Pos.Top (label) }; - numericUpDown.ValueChanged += NumericUpDown_ValueChanged; + numericUpDown.ValueChanged += NumericUpDownValueChanged; - void NumericUpDown_ValueChanged (object sender, EventArgs e) { } + void NumericUpDownValueChanged (object sender, EventArgs e) { } main.Add (label, numericUpDown); label = new () { X = 0, - Y = Pos.Bottom (numericUpDown) + 1, - Title = "_No Repeat:" + Y = Pos.Bottom (numericUpDown), + + // ReSharper disable once StringLiteralTypo + Title = "No Repea_t:" }; var noRepeatAcceptCount = 0; - var noRepeatButton = new Button + Button noRepeatButton = new () { X = Pos.Right (label) + 1, Y = Pos.Top (label), - Title = $"Accept Cou_nt: {noRepeatAcceptCount}", + Title = $"Accepting Count: {noRepeatAcceptCount}", WantContinuousButtonPressed = false }; - noRepeatButton.Accepting += (s, e) => - { - noRepeatButton.Title = $"Accept Cou_nt: {++noRepeatAcceptCount}"; - e.Handled = true; - }; + + noRepeatButton.Accepting += (_, e) => + { + noRepeatButton.Title = $"Accepting Count: {++noRepeatAcceptCount}"; + Logging.Trace ("noRepeatButton Button Pressed"); + e.Handled = true; + }; main.Add (label, noRepeatButton); label = new () { - X = 0, - Y = Pos.Bottom (label) + 1, - Title = "_Repeat (press-and-hold):" + X = Pos.Right (noRepeatButton) + 1, + Y = Pos.Top (label), + Title = "N_o Repeat (no highlight):" }; - var acceptCount = 0; + var noRepeatNoHighlightAcceptCount = 0; - var repeatButton = new Button + Button noRepeatNoHighlight = new () + { + X = Pos.Right (label) + 1, + Y = Pos.Top (label), + Title = $"Accepting Count: {noRepeatNoHighlightAcceptCount}", + WantContinuousButtonPressed = false, + HighlightStates = MouseState.None + }; + + noRepeatNoHighlight.Accepting += (_, e) => + { + noRepeatNoHighlight.Title = $"Accepting Count: {++noRepeatNoHighlightAcceptCount}"; + Logging.Trace ("noRepeatNoHighlight Button Pressed"); + e.Handled = true; + }; + main.Add (label, noRepeatNoHighlight); + + label = new () + { + X = 0, + Y = Pos.Bottom (noRepeatNoHighlight), + Title = "Repeat (_press-and-hold):" + }; + + var repeatButtonAcceptingCount = 0; + + Button repeatButton = new () { Id = "repeatButton", X = Pos.Right (label) + 1, Y = Pos.Top (label), - Title = $"Accept Co_unt: {acceptCount}", + Title = $"Accepting Co_unt: {repeatButtonAcceptingCount}", WantContinuousButtonPressed = true }; - repeatButton.Accepting += (s, e) => - { - repeatButton.Title = $"Accept Co_unt: {++acceptCount}"; - e.Handled = true; - }; - var enableCB = new CheckBox + repeatButton.Accepting += (_, e) => + { + repeatButton.Title = $"Accepting Co_unt: {++repeatButtonAcceptingCount}"; + e.Handled = true; + }; + + CheckBox enableCb = new () { X = Pos.Right (repeatButton) + 1, Y = Pos.Top (repeatButton), Title = "Enabled", CheckedState = CheckState.Checked }; - enableCB.CheckedStateChanging += (s, e) => { repeatButton.Enabled = !repeatButton.Enabled; }; - main.Add (label, repeatButton, enableCB); + enableCb.CheckedStateChanging += (_, _) => { repeatButton.Enabled = !repeatButton.Enabled; }; + main.Add (label, repeatButton, enableCb); - var decNumericUpDown = new NumericUpDown + NumericUpDown decNumericUpDown = new () { + // ReSharper disable once StringLiteralTypo + Title = "Hexadecima_l", Value = 911, Increment = 1, Format = "{0:X}", X = 0, - Y = Pos.Bottom (enableCB) + 1, + Y = Pos.Bottom (repeatButton), + BorderStyle = LineStyle.Single, + Width = 15 }; main.Add (decNumericUpDown); - Application.Run (main); - main.Dispose (); - Application.Shutdown (); + app.Run (main); + + return; + + static void DoMessage (Button button, string txt) + { + button.Accepting += (s, e) => + { + MessageBox.Query ((s as View)?.App!, "Message", $"Did you click {txt}?", "Yes", "No"); + e.Handled = true; + }; + } + } + + private static void SetTextAlignmentForAllButtons (View root, Alignment alignment) + { + foreach (Button button in GetAllSubViewsOfType