using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Terminal.Gui; namespace UICatalog.Scenarios { /// /// This Scenario demonstrates how to use Termina.gui's Dim and Pos Layout System. /// [x] - Using Dim.Fill to fill a window /// [x] - Using Dim.Fill and Dim.Pos to automatically align controls based on an initial control /// [ ] - ... /// [ScenarioMetadata (Name: "Computed Layout", Description: "Demonstrates the Computed (Dim and Pos) Layout System.")] [ScenarioCategory ("Layout")] public class ComputedLayout : Scenario { public override void Init () { Application.Init (); ConfigurationManager.Themes.Theme = Theme; ConfigurationManager.Apply (); Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme]; } public override void Setup () { // Demonstrate using Dim to create a horizontal ruler that always measures the parent window's width const string rule = "|123456789"; var horizontalRuler = new Label (rule, false) { AutoSize = false, X = 0, Y = 0, Width = Dim.Fill (), Height = 1, ColorScheme = Colors.Error }; Application.Top.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 (vrule, false) { AutoSize = false, X = 0, Y = 0, Width = 1, Height = Dim.Fill (), ColorScheme = Colors.Error }; Application.Top.LayoutComplete += (s, a) => { horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)]; verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)]; }; Application.Top.Add (verticalRuler); // Demonstrate At - Using Pos.At to locate a view in an absolute location var atButton = new Button ("At(2,1)") { X = Pos.At (2), Y = Pos.At (1) }; Application.Top.Add (atButton); // Throw in a literal absolute - Should function identically to above var absoluteButton = new Button ("X = 30, Y = 1") { X = 30, Y = 1 }; Application.Top.Add (absoluteButton); // Demonstrate using Dim to create a window that fills the parent with a margin int margin = 10; var subWin = new Window () { X = Pos.Center (), Y = 2, Width = Dim.Fill (margin), Height = 7 }; subWin.Title = $"{subWin.GetType ().Name} {{X={subWin.X},Y={subWin.Y},Width={subWin.Width},Height={subWin.Height}}}"; Application.Top.Add (subWin); int i = 1; string txt = "Resize the terminal to see computed layout in action."; var labelList = new List