diff --git a/UICatalog/Scenarios/PosJustification.cs b/UICatalog/Scenarios/PosJustification.cs index 9e7ccaff1..14a687100 100644 --- a/UICatalog/Scenarios/PosJustification.cs +++ b/UICatalog/Scenarios/PosJustification.cs @@ -1,8 +1,7 @@ -using System.Collections.Generic; using System; -using Terminal.Gui; +using System.Collections.Generic; using System.Linq; -using System.Reflection.Emit; +using Terminal.Gui; namespace UICatalog.Scenarios; @@ -10,11 +9,10 @@ namespace UICatalog.Scenarios; [ScenarioCategory ("Layout")] public sealed class PosJustification : Scenario { - - private Justifier _horizJustifier = new Justifier (); - private int _leftMargin = 0; - private Justifier _vertJustifier = new Justifier (); - private int _topMargin = 0; + private readonly Justifier _horizJustifier = new (); + private int _leftMargin; + private readonly Justifier _vertJustifier = new (); + private int _topMargin; public override void Main () { @@ -31,6 +29,8 @@ public sealed class PosJustification : Scenario SetupVerticalControls (appWindow); + Setup3by3Grid (appWindow); + // Run - Start the application. Application.Run (appWindow); appWindow.Dispose (); @@ -42,6 +42,7 @@ public sealed class PosJustification : Scenario private void SetupHorizontalControls (Window appWindow) { ColorScheme colorScheme = Colors.ColorSchemes ["Toplevel"]; + RadioGroup justification = new () { X = Pos.Justify (_horizJustifier.Justification), @@ -51,23 +52,25 @@ public sealed class PosJustification : Scenario }; justification.SelectedItemChanged += (s, e) => - { - _horizJustifier.Justification = (Justification)Enum.Parse (typeof (Justification), justification.SelectedItem.ToString ()); - foreach (var view in appWindow.Subviews.Where (v => v.X is Pos.PosJustify)) - { - if (view.X is Pos.PosJustify j) - { - var newJust = new Pos.PosJustify (_horizJustifier.Justification) - { - Justifier = - { - PutSpaceBetweenItems = _horizJustifier.PutSpaceBetweenItems - } - }; - view.X = newJust; - } - } - }; + { + _horizJustifier.Justification = + (Justification)Enum.Parse (typeof (Justification), justification.SelectedItem.ToString ()); + + foreach (View view in appWindow.Subviews.Where (v => v.X is Pos.PosJustify)) + { + if (view.X is Pos.PosJustify j) + { + var newJust = new Pos.PosJustify (_horizJustifier.Justification) + { + Justifier = + { + PutSpaceBetweenItems = _horizJustifier.PutSpaceBetweenItems + } + }; + view.X = newJust; + } + } + }; appWindow.Add (justification); CheckBox putSpaces = new () @@ -75,12 +78,14 @@ public sealed class PosJustification : Scenario X = Pos.Justify (_horizJustifier.Justification), Y = Pos.Top (justification), ColorScheme = colorScheme, - Text = "Spaces", + Text = "Spaces" }; + putSpaces.Toggled += (s, e) => { _horizJustifier.PutSpaceBetweenItems = e.NewValue is { } && e.NewValue.Value; - foreach (var view in appWindow.Subviews.Where (v => v.X is Pos.PosJustify)) + + foreach (View view in appWindow.Subviews.Where (v => v.X is Pos.PosJustify)) { if (view.X is Pos.PosJustify j) { @@ -95,33 +100,37 @@ public sealed class PosJustification : Scenario X = Pos.Left (putSpaces), Y = Pos.Bottom (putSpaces), ColorScheme = colorScheme, - Text = "Margin", + Text = "Margin" }; - margin.Toggled += (s, e) => - { - _leftMargin = e.NewValue is { } && e.NewValue.Value ? 1 : 0; - foreach (var view in appWindow.Subviews.Where (v => v.X is Pos.PosJustify)) - { - // Skip the justification radio group - if (view != justification) - { - view.Margin.Thickness = new Thickness (_leftMargin, 0, 0, 0); - } - } - appWindow.LayoutSubviews (); - }; + margin.Toggled += (s, e) => + { + _leftMargin = e.NewValue is { } && e.NewValue.Value ? 1 : 0; + + foreach (View view in appWindow.Subviews.Where (v => v.X is Pos.PosJustify)) + { + // Skip the justification radio group + if (view != justification) + { + view.Margin.Thickness = new (_leftMargin, 0, 0, 0); + } + } + + appWindow.LayoutSubviews (); + }; appWindow.Add (margin); - var addedViews = new List