diff --git a/Terminal.Gui/View/Layout/PosDim.cs b/Terminal.Gui/View/Layout/PosDim.cs
index 97ebb7fc0..bf98db91b 100644
--- a/Terminal.Gui/View/Layout/PosDim.cs
+++ b/Terminal.Gui/View/Layout/PosDim.cs
@@ -125,16 +125,16 @@
public class Pos
{
///
- /// Creates a 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 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 ,
+ /// with an offset equivalent to the View's respective dimension.
///
- /// The object anchored to the end (the bottom or the right side).
+ /// The object anchored to the end (the bottom or the right side) minus the View's dimension.
///
/// This sample shows how align a to the bottom-right the SuperView.
///
- /// anchorButton.X = Pos.AnchorEnd (0);
- /// anchorButton.Y = Pos.AnchorEnd (0);
+ /// anchorButton.X = Pos.AnchorEnd ();
+ /// anchorButton.Y = Pos.AnchorEnd ();
///
///
public static Pos AnchorEnd ()
@@ -149,8 +149,7 @@ public class Pos
/// The object anchored to the end (the bottom or the right side).
/// The view will be shifted left or up by the amount specified.
///
- /// This sample shows how align a 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 to the bottom-right the SuperView.
///
/// anchorButton.X = Pos.AnchorEnd (10);
/// anchorButton.Y = 1
diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs
index 69a07f066..fe7ccebb0 100644
--- a/Terminal.Gui/View/Layout/ViewLayout.cs
+++ b/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 (
diff --git a/UICatalog/Scenarios/Adornments.cs b/UICatalog/Scenarios/Adornments.cs
index 27aefbddc..ab68fb961 100644
--- a/UICatalog/Scenarios/Adornments.cs
+++ b/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; };
diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs
index 22d6d11dc..b9b20377e 100644
--- a/UICatalog/Scenarios/AllViewsTester.cs
+++ b/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
diff --git a/UICatalog/Scenarios/Animation.cs b/UICatalog/Scenarios/Animation.cs
index 80bebdec2..42ad540c1 100644
--- a/UICatalog/Scenarios/Animation.cs
+++ b/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);
diff --git a/UICatalog/Scenarios/BasicColors.cs b/UICatalog/Scenarios/BasicColors.cs
index 9fc6fead5..e12e51284 100644
--- a/UICatalog/Scenarios/BasicColors.cs
+++ b/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 ();
}
}
diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs
index f405e063c..33590a7e0 100644
--- a/UICatalog/Scenarios/Buttons.cs
+++ b/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,
diff --git a/UICatalog/Scenarios/ColorPicker.cs b/UICatalog/Scenarios/ColorPicker.cs
index bc426e4e2..fe2b08fad 100644
--- a/UICatalog/Scenarios/ColorPicker.cs
+++ b/UICatalog/Scenarios/ColorPicker.cs
@@ -24,42 +24,45 @@ public class ColorPickers : Scenario
private ColorPicker foregroundColorPicker;
/// Setup the scenario.
- 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 ();
}
/// Fired when background color is changed.
diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs
index 65904cdf9..c8013c46a 100644
--- a/UICatalog/Scenarios/ComputedLayout.cs
+++ b/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 ();
}
}
diff --git a/UICatalog/Scenarios/ContentScrolling.cs b/UICatalog/Scenarios/ContentScrolling.cs
index 67f61d3c8..d8f81f2a8 100644
--- a/UICatalog/Scenarios/ContentScrolling.cs
+++ b/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
{
diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs
index f6ec1616e..650e854db 100644
--- a/UICatalog/Scenarios/DynamicMenuBar.cs
+++ b/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 = ">" };
diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs
index f7934024a..316e3d263 100644
--- a/UICatalog/Scenarios/DynamicStatusBar.cs
+++ b/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
diff --git a/UICatalog/Scenarios/HotKeys.cs b/UICatalog/Scenarios/HotKeys.cs
index 8201a140f..5b9507374 100644
--- a/UICatalog/Scenarios/HotKeys.cs
+++ b/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 (), Text = "_Press me!" };
+ app.Add (button);
- var button = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (1), Text = "_Press me!" };
- Top.Add (button);
-
- Application.Run (Top);
+ Application.Run (app);
+ app.Dispose ();
}
}
diff --git a/UICatalog/Scenarios/LineCanvasExperiment.cs b/UICatalog/Scenarios/LineCanvasExperiment.cs
index 651d82f56..d015cd23e 100644
--- a/UICatalog/Scenarios/LineCanvasExperiment.cs
+++ b/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 ();
- }
- /// Setup the scenario.
- 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 ();
}
}
diff --git a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs b/UICatalog/Scenarios/TextAlignmentsAndDirection.cs
index 2abe35177..52c7c5b5e 100644
--- a/UICatalog/Scenarios/TextAlignmentsAndDirection.cs
+++ b/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