using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Terminal.Gui;
namespace UICatalog {
///
/// 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 using the Computed (Dim and Pos) Layout System")]
[ScenarioCategory ("Layout")]
class ComputedLayout : Scenario {
public override void Setup ()
{
//Top.LayoutStyle = LayoutStyle.Computed;
// Demonstrate using Dim to create a horizontal ruler that always measures the parent window's width
// BUGBUG: Dim.Fill returns too big a value sometimes.
const string rule = "|123456789";
var horizontalRuler = new Label ("") {
X = 0,
Y = 0,
Width = Dim.Fill (1), // BUGBUG: I don't think this should be needed; DimFill() should respect container's frame. X does.
ColorScheme = Colors.Error
};
Win.Add (horizontalRuler);
// Demonstrate using Dim to create a vertical ruler that always measures the parent window's height
// TODO: Either build a custom control for this or implement linewrap in Label #352
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.Error
};
Application.Resized += (sender, 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)];
};
Win.Add (verticalRuler);
// Demonstrate At - Absolute Layout using Pos
var absoluteButton = new Button ("Absolute At(2,1)") {
X = Pos.At (2),
Y = Pos.At (1)
};
Win.Add (absoluteButton);
// Demonstrate using Dim to create a window that fills the parent with a margin
int margin = 10;
var subWin = new Window ($"Centered Sub Window with {margin} character margin") {
X = Pos.Center(),
Y = 2,
Width = Dim.Fill (margin),
Height = 7
};
Win.Add (subWin);
int i = 1;
string txt = "Resize the terminal to see computed layout in action.";
var labelList = new List