|
@@ -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 ();
|
|
|
}
|
|
|
}
|