瀏覽代碼

AnchorEnd() works! Cleaned up usages and modernized Sceanrios

Tig 1 年之前
父節點
當前提交
264ba87e73

+ 7 - 8
Terminal.Gui/View/Layout/PosDim.cs

@@ -125,16 +125,16 @@
 public class Pos
 {
     /// <summary>
-    ///     Creates a <see cref="Pos"/> object that has its end (right side or bottom) anchored to the end (right side or
-    ///     bottom)
-    ///     of the SuperView, useful to flush the layout from the right or bottom.
+    ///     Creates a <see cref="Pos"/> object that is anchored to the end (right side or
+    ///     bottom) of the SuperView, minus the respective dimension of the View. This is equivalent to using <see cref="Pos.AnchorEnd(int)"/>,
+    ///     with an offset equivalent to the View's respective dimension.
     /// </summary>
-    /// <returns>The <see cref="Pos"/> object anchored to the end (the bottom or the right side).</returns>
+    /// <returns>The <see cref="Pos"/> object anchored to the end (the bottom or the right side) minus the View's dimension.</returns>
     /// <example>
     ///     This sample shows how align a <see cref="Button"/> to the bottom-right the SuperView.
     /// <code>
-    /// anchorButton.X = Pos.AnchorEnd (0);
-    /// anchorButton.Y = Pos.AnchorEnd (0);
+    /// anchorButton.X = Pos.AnchorEnd ();
+    /// anchorButton.Y = Pos.AnchorEnd ();
     /// </code>
     /// </example>
     public static Pos AnchorEnd ()
@@ -149,8 +149,7 @@ public class Pos
     /// <returns>The <see cref="Pos"/> object anchored to the end (the bottom or the right side).</returns>
     /// <param name="offset">The view will be shifted left or up by the amount specified.</param>
     /// <example>
-    ///     This sample shows how align a <see cref="Button"/> such that its left side is offset 10 columns from
-    ///     the right edge of the SuperView.
+    ///     This sample shows how align a 10 column wide <see cref="Button"/> to the bottom-right the SuperView.
     /// <code>
     /// anchorButton.X = Pos.AnchorEnd (10);
     /// anchorButton.Y = 1

+ 1 - 1
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -1151,7 +1151,7 @@ public partial class View
                     newLocation = anchorEnd.Anchor (superviewDimension);
                     if (anchorEnd.UseDimForOffset)
                     {
-                        newLocation -= dim.Anchor (0);
+                        newLocation -= dim.Anchor (superviewDimension);
                     }
 
                     newDimension = Math.Max (

+ 9 - 8
UICatalog/Scenarios/Adornments.cs

@@ -38,7 +38,7 @@ public class Adornments : Scenario
         app.Add (window);
 
         var tf1 = new TextField { Width = 10, Text = "TextField" };
-        var color = new ColorPicker { Title = "BG", BoxHeight = 1, BoxWidth = 1, X = Pos.AnchorEnd (11) };
+        var color = new ColorPicker { Title = "BG", BoxHeight = 1, BoxWidth = 1, X = Pos.AnchorEnd () };
         color.BorderStyle = LineStyle.RoundedDotted;
 
         color.ColorChanged += (s, e) =>
@@ -68,15 +68,16 @@ public class Adornments : Scenario
         };
         label.Border.Thickness = new (1, 3, 1, 1);
 
-        var btnButtonInWindow = new Button { X = Pos.AnchorEnd (10), Y = Pos.AnchorEnd (1), Text = "Button" };
+        var btnButtonInWindow = new Button { X = Pos.AnchorEnd (), Y = Pos.AnchorEnd (), Text = "Button" };
 
-        var tv = new Label
+        var labelAnchorEnd = new Label
         {
             AutoSize = false,
-            Y = Pos.AnchorEnd (3),
-            Width = 25,
-            Height = Dim.Fill (),
-            Text = "Label\nY=AnchorEnd(3),Height=Dim.Fill()"
+            Y = Pos.AnchorEnd (),
+            Width = 40,
+            Height = Dim.Percent(20),
+            Text = "Label\nY=AnchorEnd(),Height=Dim.Percent(10)",
+            ColorScheme = Colors.ColorSchemes ["Error"]
         };
 
         window.Margin.Data = "Margin";
@@ -94,7 +95,7 @@ public class Adornments : Scenario
 
         };
         longLabel.TextFormatter.WordWrap = true;
-        window.Add (tf1, color, button, label, btnButtonInWindow, tv, longLabel);
+        window.Add (tf1, color, button, label, btnButtonInWindow, labelAnchorEnd, longLabel);
 
         editor.Initialized += (s, e) => { editor.ViewToEdit = window; };
 

+ 4 - 4
UICatalog/Scenarios/AllViewsTester.cs

@@ -147,7 +147,7 @@ public class AllViewsTester : Scenario
                                      };
         _settingsPane.Add (_computedCheckBox);
 
-        string [] radioItems = { "_Percent(x)", "_AnchorEnd(x)", "_Center", "A_t(x)" };
+        string [] radioItems = { "_Percent(x)", "_AnchorEnd", "_Center", "A_t(x)" };
 
         _locationFrame = new FrameView
         {
@@ -179,7 +179,7 @@ public class AllViewsTester : Scenario
 
         _locationFrame.Add (_xRadioGroup);
 
-        radioItems = new [] { "P_ercent(y)", "A_nchorEnd(y)", "C_enter", "At(_y)" };
+        radioItems = new [] { "P_ercent(y)", "A_nchorEnd", "C_enter", "At(_y)" };
         label = new Label { X = Pos.Right (_xRadioGroup) + 1, Y = 0, Text = "Y:" };
         _locationFrame.Add (label);
         _yText = new TextField { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_yVal}" };
@@ -388,7 +388,7 @@ public class AllViewsTester : Scenario
             view.X = _xRadioGroup.SelectedItem switch
                      {
                          0 => Pos.Percent (_xVal),
-                         1 => Pos.AnchorEnd (_xVal),
+                         1 => Pos.AnchorEnd (),
                          2 => Pos.Center (),
                          3 => Pos.At (_xVal),
                          _ => view.X
@@ -397,7 +397,7 @@ public class AllViewsTester : Scenario
             view.Y = _yRadioGroup.SelectedItem switch
                      {
                          0 => Pos.Percent (_yVal),
-                         1 => Pos.AnchorEnd (_yVal),
+                         1 => Pos.AnchorEnd (),
                          2 => Pos.Center (),
                          3 => Pos.At (_yVal),
                          _ => view.Y

+ 2 - 2
UICatalog/Scenarios/Animation.cs

@@ -34,12 +34,12 @@ public class Animation : Scenario
 
         win.Add (imageView);
 
-        var lbl = new Label { Y = Pos.AnchorEnd (2), Text = "Image by Wikiscient" };
+        var lbl = new Label { Y = Pos.AnchorEnd (), Text = "Image by Wikiscient" };
         win.Add (lbl);
 
         var lbl2 = new Label
         {
-            Y = Pos.AnchorEnd (1), Text = "https://commons.wikimedia.org/wiki/File:Spinning_globe.gif"
+           X = Pos.AnchorEnd(), Y = Pos.AnchorEnd (), Text = "https://commons.wikimedia.org/wiki/File:Spinning_globe.gif"
         };
         win.Add (lbl2);
 

+ 21 - 11
UICatalog/Scenarios/BasicColors.cs

@@ -8,8 +8,15 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Text and Formatting")]
 public class BasicColors : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+
+        Window app = new ()
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+        };
+
         var vx = 30;
         var x = 30;
         var y = 14;
@@ -31,7 +38,7 @@ public class BasicColors : Scenario
                 Text = bg.ToString (),
                 TextDirection = TextDirection.TopBottom_LeftRight
             };
-            Win.Add (vl);
+            app.Add (vl);
 
             var hl = new Label
             {
@@ -44,7 +51,7 @@ public class BasicColors : Scenario
                 ColorScheme = new ColorScheme { Normal = attr },
                 Text = bg.ToString ()
             };
-            Win.Add (hl);
+            app.Add (hl);
             vx++;
 
             foreach (ColorName fg in colors)
@@ -56,7 +63,7 @@ public class BasicColors : Scenario
                 {
                     ColorScheme = new ColorScheme { Normal = c }, X = x, Y = y, Text = t [^1].ToString ()
                 };
-                Win.Add (l);
+                app.Add (l);
                 x++;
             }
 
@@ -64,24 +71,24 @@ public class BasicColors : Scenario
             y++;
         }
 
-        Win.Add (
+        app.Add (
                  new Label { X = Pos.AnchorEnd (36), Text = "Mouse over to get the Attribute:" }
                 );
-        Win.Add (new Label { X = Pos.AnchorEnd (35), Y = 2, Text = "Foreground:" });
+        app.Add (new Label { X = Pos.AnchorEnd (35), Y = 2, Text = "Foreground:" });
 
         var lblForeground = new Label { X = Pos.AnchorEnd (23), Y = 2 };
-        Win.Add (lblForeground);
+        app.Add (lblForeground);
 
         var viewForeground = new View { X = Pos.AnchorEnd (2), Y = 2, ColorScheme = new ColorScheme (), Text = "  " };
-        Win.Add (viewForeground);
+        app.Add (viewForeground);
 
-        Win.Add (new Label { X = Pos.AnchorEnd (35), Y = 4, Text = "Background:" });
+        app.Add (new Label { X = Pos.AnchorEnd (35), Y = 4, Text = "Background:" });
 
         var lblBackground = new Label { X = Pos.AnchorEnd (23), Y = 4 };
-        Win.Add (lblBackground);
+        app.Add (lblBackground);
 
         var viewBackground = new View { X = Pos.AnchorEnd (2), Y = 4, ColorScheme = new ColorScheme (), Text = "  " };
-        Win.Add (viewBackground);
+        app.Add (viewBackground);
 
         Application.MouseEvent += (s, e) =>
                                   {
@@ -103,5 +110,8 @@ public class BasicColors : Scenario
                                               new ColorScheme (viewBackground.ColorScheme) { Normal = new Attribute (back, back) };
                                       }
                                   };
+
+        Application.Run (app);
+        app.Dispose ();
     }
 }

+ 2 - 2
UICatalog/Scenarios/Buttons.cs

@@ -29,7 +29,7 @@ public class Buttons : Scenario
 
         // 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 (1), IsDefault = true, Text = "_Quit" };
+        var defaultButton = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (), IsDefault = true, Text = "_Quit" };
         defaultButton.Accept += (s, e) => Application.RequestStop ();
         main.Add (defaultButton);
 
@@ -459,7 +459,7 @@ public class Buttons : Scenario
             _up = new ()
             {
                 AutoSize = false,
-                X = Pos.AnchorEnd (1),
+                X = Pos.AnchorEnd (),
                 Y = Pos.Top (_number),
                 Height = 1,
                 Width = 1,

+ 23 - 17
UICatalog/Scenarios/ColorPicker.cs

@@ -24,42 +24,45 @@ public class ColorPickers : Scenario
     private ColorPicker foregroundColorPicker;
 
     /// <summary>Setup the scenario.</summary>
-    public override void Setup ()
+    public override void Main ()
     {
-        // Scenario Window's.
-        Win.Title = GetName ();
+        Application.Init ();
+
+        Window app = new ()
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+        };
 
         // Foreground ColorPicker.
         foregroundColorPicker = new ColorPicker { Title = "Foreground Color", BorderStyle = LineStyle.Single };
         foregroundColorPicker.ColorChanged += ForegroundColor_ColorChanged;
-        Win.Add (foregroundColorPicker);
+        app.Add (foregroundColorPicker);
 
         _foregroundColorLabel = new Label
         {
             X = Pos.Left (foregroundColorPicker), Y = Pos.Bottom (foregroundColorPicker) + 1
         };
-        Win.Add (_foregroundColorLabel);
+        app.Add (_foregroundColorLabel);
 
         // Background ColorPicker.
         backgroundColorPicker = new ColorPicker
         {
             Title = "Background Color",
-            // TODO: Replace with Pos.AnchorEnd (0) when #2900 is done
-            X = Pos.AnchorEnd ((8 * 4) + 2), // 8 box * 4 width + 2 for border
+            X = Pos.AnchorEnd (),
             BoxHeight = 1,
             BoxWidth = 4,
-            BorderStyle = LineStyle.Single
+            BorderStyle = LineStyle.Single,
         };
 
-        //backgroundColorPicker.X = Pos.AnchorEnd (0) - (Pos.Right (backgroundColorPicker) - Pos.Left (backgroundColorPicker));
         backgroundColorPicker.ColorChanged += BackgroundColor_ColorChanged;
-        Win.Add (backgroundColorPicker);
-        _backgroundColorLabel = new Label ();
+        app.Add (backgroundColorPicker);
+        _backgroundColorLabel = new Label ()
+        {
+            X = Pos.AnchorEnd (),
+            Y = Pos.Bottom (backgroundColorPicker) + 1
+        };
 
-        _backgroundColorLabel.X =
-            Pos.AnchorEnd (0) - (Pos.Right (_backgroundColorLabel) - Pos.Left (_backgroundColorLabel));
-        _backgroundColorLabel.Y = Pos.Bottom (backgroundColorPicker) + 1;
-        Win.Add (_backgroundColorLabel);
+        app.Add (_backgroundColorLabel);
 
         // Demo Label.
         _demoView = new View
@@ -74,12 +77,15 @@ public class ColorPickers : Scenario
             Height = 5,
             Width = 20
         };
-        Win.Add (_demoView);
+        app.Add (_demoView);
 
         // Set default colors.
         foregroundColorPicker.SelectedColor = _demoView.SuperView.ColorScheme.Normal.Foreground.GetClosestNamedColor ();
         backgroundColorPicker.SelectedColor = _demoView.SuperView.ColorScheme.Normal.Background.GetClosestNamedColor ();
-        Win.Initialized += (s, e) => Win.LayoutSubviews ();
+        app.Initialized += (s, e) => app.LayoutSubviews ();
+
+        Application.Run (app);
+        app.Dispose ();
     }
 
     /// <summary>Fired when background color is changed.</summary>

+ 45 - 44
UICatalog/Scenarios/ComputedLayout.cs

@@ -13,17 +13,15 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Layout")]
 public class ComputedLayout : Scenario
 {
-    public override void Init ()
+    public override void Main ()
     {
         Application.Init ();
-        ConfigurationManager.Themes.Theme = Theme;
-        ConfigurationManager.Apply ();
-        Top = new ();
-        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
-    }
 
-    public override void Setup ()
-    {
+        Window app = new ()
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
+        };
+
         // Demonstrate using Dim to create a horizontal ruler that always measures the parent window's width
         const string rule = "|123456789";
 
@@ -38,7 +36,7 @@ public class ComputedLayout : Scenario
             Text = rule
         };
 
-        Top.Add (horizontalRuler);
+        app.Add (horizontalRuler);
 
         // Demonstrate using Dim to create a vertical ruler that always measures the parent window's height
         const string vrule = "|\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
@@ -54,7 +52,7 @@ public class ComputedLayout : Scenario
             Text = vrule
         };
 
-        Top.LayoutComplete += (s, a) =>
+        app.LayoutComplete += (s, a) =>
                                           {
                                               horizontalRuler.Text =
                                                   rule.Repeat ((int)Math.Ceiling (horizontalRuler.Viewport.Width / (double)rule.Length)) [
@@ -65,15 +63,15 @@ public class ComputedLayout : Scenario
                                                       [..(verticalRuler.Viewport.Height * 2)];
                                           };
 
-        Top.Add (verticalRuler);
+        app.Add (verticalRuler);
 
         // Demonstrate At - Using Pos.At to locate a view in an absolute location
         var atButton = new Button { Text = "At(2,1)", X = Pos.At (2), Y = Pos.At (1) };
-        Top.Add (atButton);
+        app.Add (atButton);
 
         // Throw in a literal absolute - Should function identically to above
         var absoluteButton = new Button { Text = "X = 30, Y = 1", X = 30, Y = 1 };
-        Top.Add (absoluteButton);
+        app.Add (absoluteButton);
 
         // Demonstrate using Dim to create a window that fills the parent with a margin
         var margin = 10;
@@ -84,7 +82,7 @@ public class ComputedLayout : Scenario
                                   subWin.Title =
                                       $"{subWin.GetType ().Name} {{X={subWin.X},Y={subWin.Y},Width={subWin.Width},Height={subWin.Height}}}";
                               };
-        Top.Add (subWin);
+        app.Add (subWin);
 
         var i = 1;
         var txt = "Resize the terminal to see computed layout in action.";
@@ -209,7 +207,7 @@ public class ComputedLayout : Scenario
                        }
                       );
         frameView.Add (labelList.ToArray ());
-        Top.Add (frameView);
+        app.Add (frameView);
 
         frameView = new FrameView
         {
@@ -223,7 +221,7 @@ public class ComputedLayout : Scenario
                                      fv.Title =
                                          $"{frameView.GetType ().Name} {{X={fv.X},Y={fv.Y},Width={fv.Width},Height={fv.Height}}}";
                                  };
-        Top.Add (frameView);
+        app.Add (frameView);
 
         // Demonstrate Dim & Pos using percentages - a TextField that is 30% height and 80% wide
         var textView = new TextView
@@ -237,7 +235,7 @@ public class ComputedLayout : Scenario
 
         textView.Text =
             "This TextView should horizontally & vertically centered and \n10% of the screeen height, and 80% of its width.";
-        Top.Add (textView);
+        app.Add (textView);
 
         var oddballButton = new Button
         {
@@ -245,7 +243,7 @@ public class ComputedLayout : Scenario
             X = Pos.Center (),
             Y = Pos.Bottom (textView) + 1
         };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         #region Issue2358
 
@@ -253,19 +251,19 @@ public class ComputedLayout : Scenario
         // Until https://github.com/gui-cs/Terminal.Gui/issues/2358 is fixed these won't work right
 
         oddballButton = new Button { Text = "Center + 0", X = Pos.Center () + 0, Y = Pos.Bottom (oddballButton) };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         oddballButton = new Button { Text = "Center + 1", X = Pos.Center () + 1, Y = Pos.Bottom (oddballButton) };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         oddballButton = new Button { Text = "0 + Center", X = 0 + Pos.Center (), Y = Pos.Bottom (oddballButton) };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         oddballButton = new Button { Text = "1 + Center", X = 1 + Pos.Center (), Y = Pos.Bottom (oddballButton) };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         oddballButton = new Button { Text = "Center - 1", X = Pos.Center () - 1, Y = Pos.Bottom (oddballButton) };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         // This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50)
         // The `- Pos.Percent(5)` is there so at least something is visible
@@ -275,7 +273,7 @@ public class ComputedLayout : Scenario
             X = Pos.Center () + Pos.Center () - Pos.Percent (50),
             Y = Pos.Bottom (oddballButton)
         };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         // This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50)
         // The `- Pos.Percent(5)` is there so at least something is visible
@@ -285,7 +283,7 @@ public class ComputedLayout : Scenario
             X = Pos.Percent (50) + Pos.Center () - Pos.Percent (50),
             Y = Pos.Bottom (oddballButton)
         };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         // This demonstrates nonsense: it the same as using Pos.AnchorEnd (100/2=50 + 100/2=50 = 100 - 50)
         // The `- Pos.Percent(5)` is there so at least something is visible
@@ -295,7 +293,7 @@ public class ComputedLayout : Scenario
             X = Pos.Center () + Pos.Percent (50) - Pos.Percent (50),
             Y = Pos.Bottom (oddballButton)
         };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         #endregion
 
@@ -306,29 +304,29 @@ public class ComputedLayout : Scenario
             X = Pos.Center () + Pos.Center () - Pos.Percent (50),
             Y = Pos.Bottom (oddballButton)
         };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         // This demonstrates combining Percents)
         oddballButton = new Button
         {
             Text = "Percent(40) + Percent(10)", X = Pos.Percent (40) + Pos.Percent (10), Y = Pos.Bottom (oddballButton)
         };
-        Top.Add (oddballButton);
+        app.Add (oddballButton);
 
         // Demonstrate AnchorEnd - Button is anchored to bottom/right
-        var anchorButton = new Button { Text = "Button using AnchorEnd", Y = Pos.AnchorEnd (0) - 1 };
-        anchorButton.X = Pos.AnchorEnd (0) - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
+        var anchorButton = new Button { Text = "Button using AnchorEnd", Y = Pos.AnchorEnd ()};
+        anchorButton.X = Pos.AnchorEnd ();
 
         anchorButton.Accept += (s, e) =>
                                 {
                                     // This demonstrates how to have a dynamically sized button
                                     // Each time the button is clicked the button's text gets longer
-                                    // The call to Top.LayoutSubviews causes the Computed layout to
+                                    // The call to app.LayoutSubviews causes the Computed layout to
                                     // get updated. 
                                     anchorButton.Text += "!";
-                                    Top.LayoutSubviews ();
+                                    app.LayoutSubviews ();
                                 };
-        Top.Add (anchorButton);
+        app.Add (anchorButton);
 
         // Demonstrate AnchorEnd(n) 
         // This is intentionally convoluted to illustrate potential bugs.
@@ -342,7 +340,7 @@ public class ComputedLayout : Scenario
             X = 5,
             Y = Pos.AnchorEnd (2)
         };
-        Top.Add (anchorEndLabel1);
+        app.Add (anchorEndLabel1);
 
         // Demonstrate DimCombine (via AnchorEnd(n) - 1)
         // This is intentionally convoluted to illustrate potential bugs.
@@ -357,7 +355,7 @@ public class ComputedLayout : Scenario
             X = 5,
             Y = Pos.AnchorEnd (2) - 1 // Pos.Combine
         };
-        Top.Add (anchorEndLabel2);
+        app.Add (anchorEndLabel2);
 
         // Show positioning vertically using Pos.AnchorEnd via Pos.Combine
         var leftButton = new Button
@@ -369,10 +367,10 @@ public class ComputedLayout : Scenario
                               {
                                   // This demonstrates how to have a dynamically sized button
                                   // Each time the button is clicked the button's text gets longer
-                                  // The call to Top.LayoutSubviews causes the Computed layout to
+                                  // The call to app.LayoutSubviews causes the Computed layout to
                                   // get updated. 
                                   leftButton.Text += "!";
-                                  Top.LayoutSubviews ();
+                                  app.LayoutSubviews ();
                               };
 
         // show positioning vertically using Pos.AnchorEnd
@@ -385,10 +383,10 @@ public class ComputedLayout : Scenario
                                 {
                                     // This demonstrates how to have a dynamically sized button
                                     // Each time the button is clicked the button's text gets longer
-                                    // The call to Top.LayoutSubviews causes the Computed layout to
+                                    // The call to app.LayoutSubviews causes the Computed layout to
                                     // get updated. 
                                     centerButton.Text += "!";
-                                    Top.LayoutSubviews ();
+                                    app.LayoutSubviews ();
                                 };
 
         // show positioning vertically using another window and Pos.Bottom
@@ -398,18 +396,21 @@ public class ComputedLayout : Scenario
                                {
                                    // This demonstrates how to have a dynamically sized button
                                    // Each time the button is clicked the button's text gets longer
-                                   // The call to Top.LayoutSubviews causes the Computed layout to
+                                   // The call to app.LayoutSubviews causes the Computed layout to
                                    // get updated. 
                                    rightButton.Text += "!";
-                                   Top.LayoutSubviews ();
+                                   app.LayoutSubviews ();
                                };
 
         // Center three buttons with 5 spaces between them
         leftButton.X = Pos.Left (centerButton) - (Pos.Right (leftButton) - Pos.Left (leftButton)) - 5;
         rightButton.X = Pos.Right (centerButton) + 5;
 
-        Top.Add (leftButton);
-        Top.Add (centerButton);
-        Top.Add (rightButton);
+        app.Add (leftButton);
+        app.Add (centerButton);
+        app.Add (rightButton);
+
+        Application.Run (app);
+        app.Dispose ();
     }
 }

+ 4 - 13
UICatalog/Scenarios/ContentScrolling.cs

@@ -319,7 +319,7 @@ public class ContentScrolling : Scenario
         // Add demo views to show that things work correctly
         var textField = new TextField { X = 20, Y = 7, Width = 15, Text = "Test TextField" };
 
-        var colorPicker = new ColorPicker { Title = "BG", BoxHeight = 1, BoxWidth = 1, X = Pos.AnchorEnd (11), Y = 10 };
+        var colorPicker = new ColorPicker { Title = "BG", BoxHeight = 1, BoxWidth = 1, X = Pos.AnchorEnd (), Y = 10 };
         colorPicker.BorderStyle = LineStyle.RoundedDotted;
 
         colorPicker.ColorChanged += (s, e) =>
@@ -356,18 +356,9 @@ public class ContentScrolling : Scenario
         charMap.Accept += (s, e) =>
                               MessageBox.Query (20, 7, "Hi", $"Am I a {view.GetType ().Name}?", "Yes", "No");
 
-        var buttonAnchoredRight = new Button
+        var buttonAnchored = new Button
         {
-            X = Pos.AnchorEnd (10), Y = 0, Text = "Button"
-        };
-
-        var labelAnchoredBottomLeft = new Label
-        {
-            AutoSize = false,
-            Y = Pos.AnchorEnd (3),
-            Width = 25,
-            Height = Dim.Fill (),
-            Text = "Label\nY=AnchorEnd(3),Height=Dim.Fill()"
+            X = Pos.AnchorEnd (), Y = Pos.AnchorEnd (), Text = "Bottom Right"
         };
 
         view.Margin.Data = "Margin";
@@ -378,7 +369,7 @@ public class ContentScrolling : Scenario
 
         view.Padding.Data = "Padding";
 
-        view.Add (buttonAnchoredRight, textField, colorPicker, charMap, textView, labelAnchoredBottomLeft);
+        view.Add (buttonAnchored, textField, colorPicker, charMap, textView);
 
         var longLabel = new Label
         {

+ 1 - 1
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -614,7 +614,7 @@ public class DynamicMenuBar : Scenario
             _frmMenu.Add (_btnPrevious);
 
             var _btnAdd = new Button { Y = Pos.Top (_btnPrevious) + 2, Text = " Add  " };
-            _btnAdd.X = Pos.AnchorEnd (0) - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
+            _btnAdd.X = Pos.AnchorEnd ();
             _frmMenu.Add (_btnAdd);
 
             var _btnNext = new Button { X = Pos.X (_btnAdd), Y = Pos.Top (_btnPrevious), Text = ">" };

+ 2 - 2
UICatalog/Scenarios/DynamicStatusBar.cs

@@ -371,11 +371,11 @@ public class DynamicStatusBar : Scenario
 
             var _btnRemoveStatusBar = new Button { Y = 1, Text = "Remove a StatusBar" };
 
-            _btnRemoveStatusBar.X = Pos.AnchorEnd (0) - (Pos.Right (_btnRemoveStatusBar) - Pos.Left (_btnRemoveStatusBar));
+            _btnRemoveStatusBar.X = Pos.AnchorEnd ();
             _frmStatusBar.Add (_btnRemoveStatusBar);
 
             var _btnAdd = new Button { Y = Pos.Top (_btnRemoveStatusBar) + 2, Text = " Add  " };
-            _btnAdd.X = Pos.AnchorEnd (0) - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
+            _btnAdd.X = Pos.AnchorEnd (0);
             _frmStatusBar.Add (_btnAdd);
 
             _lstItems = new ListView

+ 52 - 58
UICatalog/Scenarios/HotKeys.cs

@@ -4,108 +4,102 @@ namespace UICatalog.Scenarios;
 
 [ScenarioMetadata ("HotKeys", "Demonstrates how HotKeys work.")]
 [ScenarioCategory ("Controls")]
-[ScenarioCategory("Mouse and Keyboard")]
+[ScenarioCategory ("Mouse and Keyboard")]
 public class HotKeys : Scenario
 {
-    public override void Init ()
+    public override void Main ()
     {
         Application.Init ();
-        ConfigurationManager.Themes.Theme = Theme;
-        ConfigurationManager.Apply ();
-        Top = new ();
-        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
-        Top.BorderStyle = LineStyle.RoundedDotted;
-        Top.Title = $"{Application.QuitKey} to _Quit - Scenario: {GetName ()}";
-    }
 
-    public override void Run ()
-    {
+        Window app = new ()
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+        };
+
         var textViewLabel = new Label { Text = "_TextView:", X = 0, Y = 0 };
-        Top.Add (textViewLabel);
-        
-        var textField = new TextField (){ X = Pos.Right (textViewLabel) + 1, Y = 0, Width = 10 };
-        Top.Add (textField);
+        app.Add (textViewLabel);
+
+        var textField = new TextField { X = Pos.Right (textViewLabel) + 1, Y = 0, Width = 10 };
+        app.Add (textField);
 
         var viewLabel = new Label { Text = "_View:", X = 0, Y = Pos.Bottom (textField) + 1 };
-        Top.Add (viewLabel);
+        app.Add (viewLabel);
 
-        var view = new View () { 
-            Title = "View (_focusable)", 
-            Text = "Text renders _Underscore", 
+        var view = new View
+        {
+            Title = "View (_focusable)",
+            Text = "Text renders _Underscore",
             CanFocus = true,
             X = Pos.Right (viewLabel) + 1, Y = Pos.Top (viewLabel), Width = 30, Height = 3,
-            BorderStyle = LineStyle.Dashed,
+            BorderStyle = LineStyle.Dashed
         };
-        Top.Add (view);
+        app.Add (view);
 
-        viewLabel = new Label { Text = "Vi_ew:", X = 0, Y = Pos.Bottom (view) + 1 };
-        Top.Add (viewLabel);
+        viewLabel = new() { Text = "Vi_ew:", X = 0, Y = Pos.Bottom (view) + 1 };
+        app.Add (viewLabel);
 
-        view = new View ()
+        view = new()
         {
             Title = "View (n_ot focusable)",
             Text = "Text renders _Underscore",
             X = Pos.Right (viewLabel) + 1, Y = Pos.Top (viewLabel), Width = 30, Height = 3,
-            BorderStyle = LineStyle.Dashed,
+            BorderStyle = LineStyle.Dashed
         };
-        Top.Add (view);
+        app.Add (view);
 
         var labelWithFrameLabel = new Label { Text = "_Label with Frame:", X = 0, Y = Pos.Bottom (view) + 1 };
-        Top.Add (labelWithFrameLabel);
+        app.Add (labelWithFrameLabel);
 
-        var labelWithFrameFocusable = new Label ()
+        var labelWithFrameFocusable = new Label
         {
             AutoSize = false,
             Title = "Label _with Frame (focusable)",
             CanFocus = true,
             X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3,
-            BorderStyle = LineStyle.Dashed,
+            BorderStyle = LineStyle.Dashed
         };
-        Top.Add (labelWithFrameFocusable);
+        app.Add (labelWithFrameFocusable);
 
-        labelWithFrameLabel = new Label { Text = "L_abel with Frame:", X = 0, Y = Pos.Bottom (labelWithFrameFocusable) + 1 };
-        Top.Add (labelWithFrameLabel);
+        labelWithFrameLabel = new() { Text = "L_abel with Frame:", X = 0, Y = Pos.Bottom (labelWithFrameFocusable) + 1 };
+        app.Add (labelWithFrameLabel);
 
-        var labelWithFrame = new Label ()
+        var labelWithFrame = new Label
         {
             AutoSize = false,
             Title = "Label with Frame (_not focusable)",
             X = Pos.Right (labelWithFrameLabel) + 1, Y = Pos.Top (labelWithFrameLabel), Width = 40, Height = 3,
-            BorderStyle = LineStyle.Dashed,
+            BorderStyle = LineStyle.Dashed
         };
-        Top.Add (labelWithFrame);
+        app.Add (labelWithFrame);
 
-        
         var buttonWithFrameLabel = new Label { Text = "_Button with Frame:", X = 0, Y = Pos.Bottom (labelWithFrame) + 1 };
-        Top.Add (buttonWithFrameLabel);
+        app.Add (buttonWithFrameLabel);
 
-        var buttonWithFrameFocusable = new Button ()
+        var buttonWithFrameFocusable = new Button
         {
             AutoSize = false,
             Title = "B_utton with Frame (focusable)",
             CanFocus = true,
             X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40, Height = 3,
-            BorderStyle = LineStyle.Dashed,
+            BorderStyle = LineStyle.Dashed
         };
-        Top.Add (buttonWithFrameFocusable);
+        app.Add (buttonWithFrameFocusable);
 
-        buttonWithFrameLabel = new Label { Text = "Butt_on with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrameFocusable) + 1 };
-        Top.Add (buttonWithFrameLabel);
+        buttonWithFrameLabel = new() { Text = "Butt_on with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrameFocusable) + 1 };
+        app.Add (buttonWithFrameLabel);
 
-        var buttonWithFrame = new Button ()
+        var buttonWithFrame = new Button
         {
             AutoSize = false,
             Title = "Button with Frame (not focusab_le)",
             X = Pos.Right (buttonWithFrameLabel) + 1, Y = Pos.Top (buttonWithFrameLabel), Width = 40, Height = 3,
             CanFocus = false,
-            BorderStyle = LineStyle.Dashed,
+            BorderStyle = LineStyle.Dashed
         };
-        Top.Add (buttonWithFrame);
-
-
+        app.Add (buttonWithFrame);
 
         var checkboxWithFrameLabel = new Label { Text = "_Checkbox with Frame:", X = 0, Y = Pos.Bottom (buttonWithFrame) + 1 };
-        Top.Add (checkboxWithFrameLabel);
+        app.Add (checkboxWithFrameLabel);
 
         var checkboxWithFrameFocusable = new CheckBox
         {
@@ -113,12 +107,12 @@ public class HotKeys : Scenario
             Title = "C_heckbox with Frame (focusable)",
             CanFocus = true,
             X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3,
-            BorderStyle = LineStyle.Dashed,
+            BorderStyle = LineStyle.Dashed
         };
-        Top.Add (checkboxWithFrameFocusable);
+        app.Add (checkboxWithFrameFocusable);
 
-        checkboxWithFrameLabel = new Label { Text = "Checkb_ox with Frame:", X = 0, Y = Pos.Bottom (checkboxWithFrameFocusable) + 1 };
-        Top.Add (checkboxWithFrameLabel);
+        checkboxWithFrameLabel = new() { Text = "Checkb_ox with Frame:", X = 0, Y = Pos.Bottom (checkboxWithFrameFocusable) + 1 };
+        app.Add (checkboxWithFrameLabel);
 
         var checkboxWithFrame = new CheckBox
         {
@@ -126,14 +120,14 @@ public class HotKeys : Scenario
             Title = "Checkbox with Frame (not focusable)",
             X = Pos.Right (checkboxWithFrameLabel) + 1, Y = Pos.Top (checkboxWithFrameLabel), Width = 40, Height = 3,
             CanFocus = false,
-            BorderStyle = LineStyle.Dashed,
+            BorderStyle = LineStyle.Dashed
         };
-        Top.Add (checkboxWithFrame);
-
+        app.Add (checkboxWithFrame);
 
-        var button = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (1), Text = "_Press me!" };
-        Top.Add (button);
+        var button = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (), Text = "_Press me!" };
+        app.Add (button);
 
-        Application.Run (Top);
+        Application.Run (app);
+        app.Dispose ();
     }
 }

+ 12 - 16
UICatalog/Scenarios/LineCanvasExperiment.cs

@@ -8,21 +8,14 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Proof of Concept")]
 public class LineCanvasExperiment : Scenario
 {
-    public override void Init ()
+    public override void Main ()
     {
         Application.Init ();
-        Top = new ();
-    }
-
-    /// <summary>Setup the scenario.</summary>
-    public override void Setup ()
-    {
-        //var menu = new MenuBar (new MenuBarItem [] {
-        //new MenuBarItem ("_File", new MenuItem [] {
-        //	new MenuItem ("_Quit", "", () => Application.RequestStop()),
-        //}) });
 
-        //Top.Add (menu);
+        Window app = new ()
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+        };
 
         var frame1 = new FrameView
         {
@@ -37,7 +30,7 @@ public class LineCanvasExperiment : Scenario
 
         //View.Diagnostics ^= DiagnosticFlags.FrameRuler;
 
-        Top.Add (frame1);
+        app.Add (frame1);
 
         var win1 = new Window
         {
@@ -52,7 +45,7 @@ public class LineCanvasExperiment : Scenario
             BorderStyle = LineStyle.Heavy,
             SuperViewRendersLineCanvas = true
         };
-        win1.Padding.Thickness = new Thickness (1);
+        win1.Padding.Thickness = new (1);
 
         frame1.Add (win1);
 
@@ -140,9 +133,12 @@ public class LineCanvasExperiment : Scenario
             SuperViewRendersLineCanvas = true
         };
         marginWindow.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"];
-        marginWindow.Margin.Thickness = new Thickness (1);
-        marginWindow.Border.Thickness = new Thickness (1, 2, 1, 1);
+        marginWindow.Margin.Thickness = new (1);
+        marginWindow.Border.Thickness = new (1, 2, 1, 1);
 
         frame1.Add (marginWindow);
+
+        Application.Run (app);
+        app.Dispose ();
     }
 }

+ 34 - 24
UICatalog/Scenarios/TextAlignmentsAndDirection.cs

@@ -10,14 +10,21 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Text and Formatting")]
 public class TextAlignmentsAndDirections : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+
+        Window app = new ()
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+        };
+
         // string txt = ".\n...\n.....\nHELLO\n.....\n...\n.";
         // string txt = "┌──┴──┐\n┤HELLO├\n└──┬──┘";
         var txt = "HELLO WORLD";
 
-        var color1 = new ColorScheme { Normal = new Attribute (Color.Black, Color.Gray) };
-        var color2 = new ColorScheme { Normal = new Attribute (Color.Black, Color.DarkGray) };
+        var color1 = new ColorScheme { Normal = new (Color.Black, Color.Gray) };
+        var color2 = new ColorScheme { Normal = new (Color.Black, Color.DarkGray) };
 
         List<Label> txts = new (); // single line
         List<Label> mtxts = new (); // multi line
@@ -125,14 +132,14 @@ public class TextAlignmentsAndDirections : Scenario
         txts.Add (txtLabelHR);
         txts.Add (txtLabelHJ);
 
-        Win.Add (labelHL);
-        Win.Add (txtLabelHL);
-        Win.Add (labelHC);
-        Win.Add (txtLabelHC);
-        Win.Add (labelHR);
-        Win.Add (txtLabelHR);
-        Win.Add (labelHJ);
-        Win.Add (txtLabelHJ);
+        app.Add (labelHL);
+        app.Add (txtLabelHL);
+        app.Add (labelHC);
+        app.Add (txtLabelHC);
+        app.Add (labelHR);
+        app.Add (txtLabelHR);
+        app.Add (labelHJ);
+        app.Add (txtLabelHJ);
 
         // Vertical Single-Line
 
@@ -245,14 +252,14 @@ public class TextAlignmentsAndDirections : Scenario
         txts.Add (txtLabelVB);
         txts.Add (txtLabelVJ);
 
-        Win.Add (labelVT);
-        Win.Add (txtLabelVT);
-        Win.Add (labelVM);
-        Win.Add (txtLabelVM);
-        Win.Add (labelVB);
-        Win.Add (txtLabelVB);
-        Win.Add (labelVJ);
-        Win.Add (txtLabelVJ);
+        app.Add (labelVT);
+        app.Add (txtLabelVT);
+        app.Add (labelVM);
+        app.Add (txtLabelVM);
+        app.Add (labelVB);
+        app.Add (txtLabelVB);
+        app.Add (labelVJ);
+        app.Add (txtLabelVJ);
 
         // Multi-Line
 
@@ -410,7 +417,7 @@ public class TextAlignmentsAndDirections : Scenario
         container.Add (txtLabelBC);
         container.Add (txtLabelBR);
 
-        Win.Add (container);
+        app.Add (container);
 
         // Edit Text
 
@@ -437,7 +444,7 @@ public class TextAlignmentsAndDirections : Scenario
                                    }
                                };
 
-        Win.KeyUp += (s, m) =>
+        app.KeyUp += (s, m) =>
                      {
                          foreach (Label v in txts)
                          {
@@ -452,7 +459,7 @@ public class TextAlignmentsAndDirections : Scenario
 
         editText.SetFocus ();
 
-        Win.Add (editText);
+        app.Add (editText);
 
         // JUSTIFY CHECKBOX
 
@@ -494,7 +501,7 @@ public class TextAlignmentsAndDirections : Scenario
                                        }
                                    };
 
-        Win.Add (justifyCheckbox);
+        app.Add (justifyCheckbox);
 
         // Direction Options
 
@@ -518,6 +525,9 @@ public class TextAlignmentsAndDirections : Scenario
                                                     }
                                                 };
 
-        Win.Add (directionOptions);
+        app.Add (directionOptions);
+
+        Application.Run (app);
+        app.Dispose ();
     }
 }

+ 61 - 49
UICatalog/Scenarios/TrueColors.cs

@@ -7,8 +7,15 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Colors")]
 public class TrueColors : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+
+        Window app = new ()
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+        };
+
         var x = 2;
         var y = 1;
 
@@ -18,7 +25,7 @@ public class TrueColors : Scenario
         {
             X = x, Y = y++, Text = $"Current driver is {Application.Driver.GetType ().Name}"
         };
-        Win.Add (lblDriverName);
+        app.Add (lblDriverName);
         y++;
 
         var cbSupportsTrueColor = new CheckBox
@@ -29,7 +36,7 @@ public class TrueColors : Scenario
             CanFocus = false,
             Text = "Driver supports true color "
         };
-        Win.Add (cbSupportsTrueColor);
+        app.Add (cbSupportsTrueColor);
 
         var cbUseTrueColor = new CheckBox
         {
@@ -40,53 +47,53 @@ public class TrueColors : Scenario
             Text = "Force 16 colors"
         };
         cbUseTrueColor.Toggled += (_, evt) => { Application.Force16Colors = evt.NewValue ?? false; };
-        Win.Add (cbUseTrueColor);
+        app.Add (cbUseTrueColor);
 
         y += 2;
-        SetupGradient ("Red gradient", x, ref y, i => new Color (i, 0));
-        SetupGradient ("Green gradient", x, ref y, i => new Color (0, i));
-        SetupGradient ("Blue gradient", x, ref y, i => new Color (0, 0, i));
-        SetupGradient ("Yellow gradient", x, ref y, i => new Color (i, i));
-        SetupGradient ("Magenta gradient", x, ref y, i => new Color (i, 0, i));
-        SetupGradient ("Cyan gradient", x, ref y, i => new Color (0, i, i));
-        SetupGradient ("Gray gradient", x, ref y, i => new Color (i, i, i));
-
-        Win.Add (
+        SetupGradient ("Red gradient", x, ref y, i => new (i, 0));
+        SetupGradient ("Green gradient", x, ref y, i => new (0, i));
+        SetupGradient ("Blue gradient", x, ref y, i => new (0, 0, i));
+        SetupGradient ("Yellow gradient", x, ref y, i => new (i, i));
+        SetupGradient ("Magenta gradient", x, ref y, i => new (i, 0, i));
+        SetupGradient ("Cyan gradient", x, ref y, i => new (0, i, i));
+        SetupGradient ("Gray gradient", x, ref y, i => new (i, i, i));
+
+        app.Add (
                  new Label { X = Pos.AnchorEnd (44), Y = 2, Text = "Mouse over to get the gradient view color:" }
                 );
 
-        Win.Add (
+        app.Add (
                  new Label { X = Pos.AnchorEnd (44), Y = 4, Text = "Red:" }
                 );
 
-        Win.Add (
+        app.Add (
                  new Label { X = Pos.AnchorEnd (44), Y = 5, Text = "Green:" }
                 );
 
-        Win.Add (
+        app.Add (
                  new Label { X = Pos.AnchorEnd (44), Y = 6, Text = "Blue:" }
                 );
 
-        Win.Add (
+        app.Add (
                  new Label { X = Pos.AnchorEnd (44), Y = 8, Text = "Darker:" }
                 );
 
-        Win.Add (
+        app.Add (
                  new Label { X = Pos.AnchorEnd (44), Y = 9, Text = "Lighter:" }
                 );
 
         var lblRed = new Label { X = Pos.AnchorEnd (32), Y = 4, Text = "na" };
-        Win.Add (lblRed);
+        app.Add (lblRed);
         var lblGreen = new Label { X = Pos.AnchorEnd (32), Y = 5, Text = "na" };
-        Win.Add (lblGreen);
+        app.Add (lblGreen);
         var lblBlue = new Label { X = Pos.AnchorEnd (32), Y = 6, Text = "na" };
-        Win.Add (lblBlue);
+        app.Add (lblBlue);
 
         var lblDarker = new Label { X = Pos.AnchorEnd (32), Y = 8, Text = "     " };
-        Win.Add (lblDarker);
+        app.Add (lblDarker);
 
         var lblLighter = new Label { X = Pos.AnchorEnd (32), Y = 9, Text = "    " };
-        Win.Add (lblLighter);
+        app.Add (lblLighter);
 
         Application.MouseEvent += (s, e) =>
                                   {
@@ -94,16 +101,17 @@ public class TrueColors : Scenario
                                       {
                                           return;
                                       }
+
                                       if (e.Flags == MouseFlags.Button1Clicked)
                                       {
                                           Attribute normal = e.View.GetNormalColor ();
-                                          
-                                          lblLighter.ColorScheme = new ColorScheme(e.View.ColorScheme)
+
+                                          lblLighter.ColorScheme = new (e.View.ColorScheme)
                                           {
-                                              Normal = new Attribute (
-                                                                      normal.Foreground,
-                                                                      normal.Background.GetHighlightColor ()
-                                                                     )
+                                              Normal = new (
+                                                            normal.Foreground,
+                                                            normal.Background.GetHighlightColor ()
+                                                           )
                                           };
                                       }
                                       else
@@ -114,31 +122,35 @@ public class TrueColors : Scenario
                                           lblBlue.Text = normal.Foreground.B.ToString ();
                                       }
                                   };
-    }
+        Application.Run (app);
+        app.Dispose ();
 
-    private void SetupGradient (string name, int x, ref int y, Func<int, Color> colorFunc)
-    {
-        var gradient = new Label { X = x, Y = y++, Text = name };
-        Win.Add (gradient);
+        return;
 
-        for (int dx = x, i = 0; i <= 256; i += 4)
+        void SetupGradient (string name, int x, ref int y, Func<int, Color> colorFunc)
         {
-            var l = new Label
+            var gradient = new Label { X = x, Y = y++, Text = name };
+            app.Add (gradient);
+
+            for (int dx = x, i = 0; i <= 256; i += 4)
             {
-                X = dx++,
-                Y = y,
-                ColorScheme = new ColorScheme
+                var l = new Label
                 {
-                    Normal = new Attribute (
-                                            colorFunc (Math.Clamp (i, 0, 255)),
-                                            colorFunc (Math.Clamp (i, 0, 255))
-                                           )
-                },
-                Text = " "
-            };
-            Win.Add (l);
+                    X = dx++,
+                    Y = y,
+                    ColorScheme = new()
+                    {
+                        Normal = new (
+                                      colorFunc (Math.Clamp (i, 0, 255)),
+                                      colorFunc (Math.Clamp (i, 0, 255))
+                                     )
+                    },
+                    Text = " "
+                };
+                app.Add (l);
+            }
+
+            y += 2;
         }
-
-        y += 2;
     }
 }

+ 16 - 16
UICatalog/Scenarios/ViewExperiments.cs

@@ -9,17 +9,15 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Proof of Concept")]
 public class ViewExperiments : Scenario
 {
-    public override void Init ()
+    public override void Main ()
     {
         Application.Init ();
-        ConfigurationManager.Themes.Theme = Theme;
-        ConfigurationManager.Apply ();
-        Top = new ();
-        Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
-    }
 
-    public override void Setup ()
-    {
+        Window app = new ()
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+        };
+
         var containerLabel = new Label
         {
             X = 0,
@@ -28,7 +26,7 @@ public class ViewExperiments : Scenario
             Width = Dim.Fill (),
             Height = 3
         };
-        Top.Add (containerLabel);
+        app.Add (containerLabel);
 
         var view = new View
         {
@@ -41,7 +39,7 @@ public class ViewExperiments : Scenario
             Id = "DaView"
         };
 
-        //Top.Add (view);
+        //app.Add (view);
 
         view.Margin.Thickness = new Thickness (2, 2, 2, 2);
         view.Margin.ColorScheme = Colors.ColorSchemes ["Toplevel"];
@@ -199,8 +197,7 @@ public class ViewExperiments : Scenario
         };
         view.Add (edit);
 
-        edit = new TextField { Text = "AnchorEnd[Right];AnchorEnd (1)", Y = Pos.AnchorEnd (1), Width = 30, Height = 1 };
-        edit.X = Pos.AnchorEnd (0) - (Pos.Right (edit) - Pos.Left (edit));
+        edit = new TextField { Text = "AnchorEnd ();AnchorEnd ()", X = Pos.AnchorEnd(), Y = Pos.AnchorEnd (), Width = 30, Height = 1 };
         view.Add (edit);
 
         edit = new TextField
@@ -217,9 +214,9 @@ public class ViewExperiments : Scenario
                                {
                                    containerLabel.Text =
                                        $"Container.Frame: {
-                                           Top.Frame
+                                           app.Frame
                                        } .Bounds: {
-                                           Top.Viewport
+                                           app.Viewport
                                        }\nView.Frame: {
                                            view.Frame
                                        } .Viewport: {
@@ -244,11 +241,14 @@ public class ViewExperiments : Scenario
             ViewToEdit = view
         };
 
-        Top.Add (editor);
+        app.Add (editor);
         view.X = 36;
         view.Y = 4;
         view.Width = Dim.Fill ();
         view.Height = Dim.Fill ();
-        Top.Add (view);
+        app.Add (view);
+
+        Application.Run (app);
+        app.Dispose ();
     }
 }

+ 35 - 44
UICatalog/Scenarios/WindowsAndFrameViews.cs

@@ -8,8 +8,15 @@ namespace UICatalog.Scenarios;
 [ScenarioCategory ("Layout")]
 public class WindowsAndFrameViews : Scenario
 {
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+
+        Window app = new ()
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+        };
+
         static int About ()
         {
             return MessageBox.Query (
@@ -26,11 +33,7 @@ public class WindowsAndFrameViews : Scenario
         // list of Windows we create
         List<View> listWin = new ();
 
-        //Ignore the Win that UI Catalog created and create a new one
-        Top.Remove (Win);
-        Win?.Dispose ();
-
-        Win = new Window
+        var win = new Window
         {
             Title = $"{listWin.Count} - Scenario: {GetName ()}",
             X = Pos.Center (),
@@ -39,8 +42,8 @@ public class WindowsAndFrameViews : Scenario
             Height = 10,
             ColorScheme = Colors.ColorSchemes ["Dialog"]
         };
-        Win.Padding.Thickness = new Thickness (padding);
-        Win.Margin.Thickness = new Thickness (margin);
+        win.Padding.Thickness = new (padding);
+        win.Margin.Thickness = new (margin);
 
         var paddingButton = new Button
         {
@@ -50,21 +53,21 @@ public class WindowsAndFrameViews : Scenario
             Text = $"Padding of container is {padding}"
         };
         paddingButton.Accept += (s, e) => About ();
-        Win.Add (paddingButton);
+        win.Add (paddingButton);
 
-        Win.Add (
+        win.Add (
                  new Button
                  {
                      X = Pos.Center (),
-                     Y = Pos.AnchorEnd (1),
+                     Y = Pos.AnchorEnd (),
                      ColorScheme = Colors.ColorSchemes ["Error"],
                      Text = "Press ME! (Y = Pos.AnchorEnd(1))"
                  }
                 );
-        Top.Add (Win);
+        app.Add (win);
 
         // add it to our list
-        listWin.Add (Win);
+        listWin.Add (win);
 
         // create 3 more Windows in a loop, adding them Application.Top
         // Each with a
@@ -75,9 +78,9 @@ public class WindowsAndFrameViews : Scenario
         // 
         for (var pad = 0; pad < 3; pad++)
         {
-            Window win = null;
+            Window loopWin = null;
 
-            win = new Window
+            loopWin = new()
             {
                 Title = $"{listWin.Count} - Window Loop - padding = {pad}",
                 X = margin,
@@ -85,9 +88,9 @@ public class WindowsAndFrameViews : Scenario
                 Width = Dim.Fill (margin),
                 Height = contentHeight + pad * 2 + 2
             };
-            win.Padding.Thickness = new Thickness (pad);
+            loopWin.Padding.Thickness = new (pad);
 
-            win.ColorScheme = Colors.ColorSchemes ["Dialog"];
+            loopWin.ColorScheme = Colors.ColorSchemes ["Dialog"];
 
             var pressMeButton = new Button
             {
@@ -95,8 +98,8 @@ public class WindowsAndFrameViews : Scenario
             };
 
             pressMeButton.Accept += (s, e) =>
-                                         MessageBox.ErrorQuery (win.Title, "Neat?", "Yes", "No");
-            win.Add (pressMeButton);
+                                        MessageBox.ErrorQuery (loopWin.Title, "Neat?", "Yes", "No");
+            loopWin.Add (pressMeButton);
 
             var subWin = new Window
             {
@@ -110,9 +113,9 @@ public class WindowsAndFrameViews : Scenario
             };
 
             subWin.Add (
-                        new TextField { Y = 1, ColorScheme = Colors.ColorSchemes ["Error"], Text = "Edit me! " + win.Title }
+                        new TextField { Y = 1, ColorScheme = Colors.ColorSchemes ["Error"], Text = "Edit me! " + loopWin.Title }
                        );
-            win.Add (subWin);
+            loopWin.Add (subWin);
 
             var frameView = new FrameView
             {
@@ -128,27 +131,15 @@ public class WindowsAndFrameViews : Scenario
             frameView.Add (
                            new TextField { Y = 1, Text = "Edit Me!" }
                           );
-            win.Add (frameView);
+            loopWin.Add (frameView);
 
-            Top.Add (win);
-            listWin.Add (win);
+            app.Add (loopWin);
+            listWin.Add (loopWin);
         }
 
-        // Add a FrameView (frame) to Application.Top
-        // Position it at Bottom, using the list of Windows we created above.
-        // Fill it with
-        //   a label
-        //   a SubWindow containing (subWinofFV)
-        //      a TextField
-        //	    two checkboxes
-        //   a Sub FrameView containing (subFrameViewofFV)
-        //      a TextField
-        //      two CheckBoxes	
-        //   a checkbox
-        //   a checkbox
         FrameView frame = null;
 
-        frame = new FrameView
+        frame = new()
         {
             X = margin,
             Y = Pos.Bottom (listWin.Last ()) + margin / 2,
@@ -199,22 +190,22 @@ public class WindowsAndFrameViews : Scenario
 
         subFrameViewofFV.Add (new CheckBox { Y = 1, Text = "Check me" });
 
-        // BUGBUG: This checkbox is not shown even though frameViewFV has 3 rows in 
-        // its client area. #522
         subFrameViewofFV.Add (new CheckBox { Y = 2, Text = "Or, Check me" });
 
         frame.Add (
-                   new CheckBox { X = 0, Y = Pos.AnchorEnd (1), Text = "Btn1 (Y = Pos.AnchorEnd (1))" }
+                   new CheckBox { X = 0, Y = Pos.AnchorEnd (), Text = "Btn1 (Y = Pos.AnchorEnd ())" }
                   );
-        var c = new CheckBox { Y = Pos.AnchorEnd (1), Text = "Btn2 (Y = Pos.AnchorEnd (1))" };
-        c.X = Pos.AnchorEnd (0) - (Pos.Right (c) - Pos.Left (c));
+        var c = new CheckBox { X = Pos.AnchorEnd (), Y = Pos.AnchorEnd (), Text = "Btn2 (Y = Pos.AnchorEnd ())" };
         frame.Add (c);
 
         frame.Add (subFrameViewofFV);
 
-        Top.Add (frame);
+        app.Add (frame);
         listWin.Add (frame);
 
-        Top.ColorScheme = Colors.ColorSchemes ["Base"];
+        app.ColorScheme = Colors.ColorSchemes ["Base"];
+
+        Application.Run (app);
+        app.Dispose ();
     }
 }

+ 26 - 0
UnitTests/View/Layout/AnchorEndTests.cs

@@ -152,6 +152,32 @@ public class AnchorEndTests (ITestOutputHelper output)
         Assert.Equal (expectedXPosition, view.Frame.X);
     }
 
+    [Theory]
+    [InlineData (0, 25)]
+    [InlineData (10, 23)]
+    [InlineData (50, 13)]
+    [InlineData (100, 0)]
+    public void AnchorEnd_UseDimForOffset_DimPercent_PositionsViewOffsetByDim (int percent, int expectedXPosition)
+    {
+        // Arrange
+        var superView = new View { Width = 25, Height = 25 };
+        var view = new View
+        {
+            X = Pos.AnchorEnd (),
+            Width = Dim.Percent ( percent),
+            Height = 1
+        };
+        superView.Add (view);
+        superView.BeginInit ();
+        superView.EndInit ();
+
+        // Act
+        superView.LayoutSubviews ();
+
+        // Assert
+        Assert.Equal (expectedXPosition, view.Frame.X);
+    }
+
     // This test used to be Dialog_In_Window_With_TextField_And_Button_AnchorEnd in DialogTests.
     [Fact]
     [SetupFakeDriver]