using System; using System.Collections.Generic; using System.Linq; using Terminal.Gui; using static Terminal.Gui.Dialog; namespace UICatalog.Scenarios; /// /// This Scenario demonstrates how to use Terminal.Gui's Dim and Pos Layout System. /// [ScenarioMetadata ("Computed Layout", "Demonstrates the Computed (Dim and Pos) Layout System.")] [ScenarioCategory ("Layout")] public class ComputedLayout : Scenario { public override void Main () { Application.Init (); Window app = new () { Title = GetQuitKeyAndName (), }; // Demonstrate using Dim to create a horizontal ruler that always measures the parent window's width const string rule = "|123456789"; var horizontalRuler = new Label { X = 0, Y = 0, Width = Dim.Fill (), Height = 1, ColorScheme = Colors.ColorSchemes ["Error"], Text = rule }; 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"; var verticalRuler = new Label { X = 0, Y = 0, Width = 1, Height = Dim.Fill (), ColorScheme = Colors.ColorSchemes ["Error"], Text = vrule }; app.LayoutComplete += (s, a) => { if (horizontalRuler.Viewport.Width == 0 || horizontalRuler.Viewport.Height == 0) { return; } horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling (horizontalRuler.Viewport.Width / (double)rule.Length)) [ ..horizontalRuler.Viewport.Width]; verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling (verticalRuler.Viewport.Height * 2 / (double)rule.Length)) [..(verticalRuler.Viewport.Height * 2)]; }; app.Add (verticalRuler); // Demonstrate At - Using Pos.At to locate a view in an absolute location var atButton = new Button { Text = "Absolute(2,1)", X = Pos.Absolute (2), Y = Pos.Absolute (1) }; 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 }; app.Add (absoluteButton); // Demonstrate using Dim to create a window that fills the parent with a margin var margin = 10; var subWin = new Window { X = Pos.Center (), Y = 2, Width = Dim.Fill (margin), Height = 7 }; subWin.Initialized += (s, a) => { subWin.Title = $"{subWin.GetType ().Name} {{X={subWin.X},Y={subWin.Y},Width={subWin.Width},Height={subWin.Height}}}"; }; app.Add (subWin); var i = 1; var txt = "Resize the terminal to see computed layout in action."; List