diff --git a/Examples/UICatalog/NumberToWords.cs b/Examples/UICatalog/NumberToWords.cs index cfd658c3c..f31c12be0 100644 --- a/Examples/UICatalog/NumberToWords.cs +++ b/Examples/UICatalog/NumberToWords.cs @@ -1,16 +1,16 @@ -using System; +#nullable enable namespace UICatalog; public static class NumberToWords { - private static readonly string [] tens = - { + private static readonly string [] _tens = + [ "", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" - }; + ]; - private static readonly string [] units = - { + private static readonly string [] _units = + [ "Zero", "One", "Two", @@ -31,23 +31,23 @@ public static class NumberToWords "Seventeen", "Eighteen", "Nineteen" - }; + ]; public static string Convert (long i) { if (i < 20) { - return units [i]; + return _units [i]; } if (i < 100) { - return tens [i / 10] + (i % 10 > 0 ? " " + Convert (i % 10) : ""); + return _tens [i / 10] + (i % 10 > 0 ? " " + Convert (i % 10) : ""); } if (i < 1000) { - return units [i / 100] + return _units [i / 100] + " Hundred" + (i % 100 > 0 ? " And " + Convert (i % 100) : ""); } @@ -77,24 +77,4 @@ public static class NumberToWords + " Arab " + (i % 1000000000 > 0 ? " " + Convert (i % 1000000000) : ""); } - - public static string ConvertAmount (double amount) - { - try - { - var amount_int = (long)amount; - var amount_dec = (long)Math.Round ((amount - amount_int) * 100); - - if (amount_dec == 0) - { - return Convert (amount_int) + " Only."; - } - - return Convert (amount_int) + " Point " + Convert (amount_dec) + " Only."; - } - catch (Exception e) - { - throw new ArgumentOutOfRangeException (e.Message); - } - } } diff --git a/Examples/UICatalog/Scenarios/Dialogs.cs b/Examples/UICatalog/Scenarios/Dialogs.cs index fb4a4fbd6..a8fa4e679 100644 --- a/Examples/UICatalog/Scenarios/Dialogs.cs +++ b/Examples/UICatalog/Scenarios/Dialogs.cs @@ -1,25 +1,22 @@ -using System; -using System.Collections.Generic; -using System.Linq; - +#nullable enable namespace UICatalog.Scenarios; [ScenarioMetadata ("Dialogs", "Demonstrates how to the Dialog class")] [ScenarioCategory ("Dialogs")] public class Dialogs : Scenario { - private static readonly int CODE_POINT = '你'; // We know this is a wide char + private const int CODE_POINT = '你'; // We know this is a wide char public override void Main () { Application.Init (); - Window app = new () - { - Title = GetQuitKeyAndName () - }; + using IApplication app = Application.Instance; - var frame = new FrameView + using Window mainWindow = new (); + mainWindow.Title = GetQuitKeyAndName (); + + FrameView frame = new () { TabStop = TabBehavior.TabStop, // FrameView normally sets to TabGroup X = Pos.Center (), @@ -29,14 +26,14 @@ public class Dialogs : Scenario Title = "Dialog Options" }; - var numButtonsLabel = new Label + Label numButtonsLabel = new () { X = 0, TextAlignment = Alignment.End, Text = "_Number of Buttons:" }; - var label = new Label + Label label = new () { X = 0, Y = 0, @@ -47,7 +44,7 @@ public class Dialogs : Scenario }; frame.Add (label); - var widthEdit = new TextField + TextField widthEdit = new () { X = Pos.Right (numButtonsLabel) + 1, Y = Pos.Top (label), @@ -68,7 +65,7 @@ public class Dialogs : Scenario }; frame.Add (label); - var heightEdit = new TextField + TextField heightEdit = new () { X = Pos.Right (numButtonsLabel) + 1, Y = Pos.Top (label), @@ -107,7 +104,7 @@ public class Dialogs : Scenario }; frame.Add (label); - var titleEdit = new TextField + TextField titleEdit = new () { X = Pos.Right (label) + 1, Y = Pos.Top (label), @@ -120,7 +117,7 @@ public class Dialogs : Scenario numButtonsLabel.Y = Pos.Bottom (label); frame.Add (numButtonsLabel); - var numButtonsEdit = new TextField + TextField numButtonsEdit = new () { X = Pos.Right (numButtonsLabel) + 1, Y = Pos.Top (numButtonsLabel), @@ -130,7 +127,7 @@ public class Dialogs : Scenario }; frame.Add (numButtonsEdit); - var glyphsNotWords = new CheckBox + CheckBox glyphsNotWords = new () { X = Pos.Right (numButtonsLabel) + 1, Y = Pos.Bottom (numButtonsLabel), @@ -163,51 +160,55 @@ public class Dialogs : Scenario frame.ValidatePosDim = true; - app.Add (frame); + mainWindow.Add (frame); label = new () { X = Pos.Center (), Y = Pos.Bottom (frame) + 4, TextAlignment = Alignment.End, Text = "Button Pressed:" }; - app.Add (label); + mainWindow.Add (label); - var buttonPressedLabel = new Label + Label buttonPressedLabel = new () { X = Pos.Center (), Y = Pos.Bottom (frame) + 5, SchemeName = "Error", Text = " " }; - var showDialogButton = new Button + Button showDialogButton = new () { X = Pos.Center (), Y = Pos.Bottom (frame) + 2, IsDefault = true, Text = "_Show Dialog" }; - app.Accepting += (s, e) => + mainWindow.Accepting += (s, e) => { - Dialog dlg = CreateDemoDialog ( - widthEdit, - heightEdit, - titleEdit, - numButtonsEdit, - glyphsNotWords, - alignmentOptionSelector, - buttonPressedLabel - ); - Application.Run (dlg); - dlg.Dispose (); + Dialog? dlg = CreateDemoDialog ( + widthEdit, + heightEdit, + titleEdit, + numButtonsEdit, + glyphsNotWords, + alignmentOptionSelector, + buttonPressedLabel + ); + + if (dlg is null) + { + MessageBox.ErrorQuery ((s as View)!.App!, "Error", "Could not create Dialog. Invalid options.", "_Ok"); + } + else + { + app.Run (dlg); + dlg.Dispose (); + } + e.Handled = true; }; - app.Add (showDialogButton); + mainWindow.Add (showDialogButton, buttonPressedLabel); - app.Add (buttonPressedLabel); - - Application.Run (app); - app.Dispose (); - - Application.Shutdown (); + app.Run (mainWindow); } - private Dialog CreateDemoDialog ( + private static Dialog? CreateDemoDialog ( TextField widthEdit, TextField heightEdit, TextField titleEdit, @@ -217,157 +218,90 @@ public class Dialogs : Scenario Label buttonPressedLabel ) { - Dialog dialog = null; - - try + if (!int.TryParse (widthEdit.Text, out int width) + || !int.TryParse (heightEdit.Text, out int height) + || !int.TryParse (numButtonsEdit.Text, out int numButtons)) { - var width = 0; - int.TryParse (widthEdit.Text, out width); - var height = 0; - int.TryParse (heightEdit.Text, out height); - var numButtons = 3; - int.TryParse (numButtonsEdit.Text, out numButtons); + return null; + } - List