123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using System;
- using Terminal.Gui;
- using static Terminal.Gui.Dim;
- namespace UICatalog.Scenarios;
- [ScenarioMetadata ("DimAuto", "Demonstrates Dim.Auto")]
- [ScenarioCategory ("Layout")]
- public class DimAutoDemo : Scenario
- {
- public override void Main ()
- {
- Application.Init ();
- // Setup - Create a top-level application window and configure it.
- Window appWindow = new ()
- {
- Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
- };
- var view = new FrameView
- {
- Title = "Type to make View grow",
- X = 1,
- Y = 1,
- Width = Auto (DimAutoStyle.Subviews, 40),
- Height = Auto (DimAutoStyle.Subviews, 10)
- };
- view.ValidatePosDim = true;
- var textEdit = new TextView { Text = "", X = 1, Y = 0, Width = 20, Height = 4 };
- view.Add (textEdit);
- var vlabel = new Label
- {
- Text = textEdit.Text,
- X = Pos.Left (textEdit),
- Y = Pos.Bottom (textEdit) + 1,
- Width = Auto (DimAutoStyle.Text, 1),
- Height = Auto (DimAutoStyle.Text, 8),
- ColorScheme = Colors.ColorSchemes ["Error"],
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- vlabel.Id = "vlabel";
- view.Add (vlabel);
- var hlabel = new Label
- {
- Text = textEdit.Text,
- X = Pos.Right (vlabel) + 1,
- Y = Pos.Bottom (textEdit),
- Width = Auto (DimAutoStyle.Text, 20),
- Height = Auto (DimAutoStyle.Text, 1),
- ColorScheme = Colors.ColorSchemes ["Error"]
- };
- hlabel.Id = "hlabel";
- view.Add (hlabel);
- var heightAuto = new View
- {
- X = Pos.Right (vlabel) + 1,
- Y = Pos.Bottom (hlabel) + 1,
- Width = 20,
- Height = Auto (),
- ColorScheme = Colors.ColorSchemes ["Error"],
- Title = "W: 20, H: Auto",
- BorderStyle = LineStyle.Rounded
- };
- heightAuto.Id = "heightAuto";
- view.Add (heightAuto);
- var widthAuto = new View
- {
- X = Pos.Right (heightAuto) + 1,
- Y = Pos.Bottom (hlabel) + 1,
- Width = Auto (),
- Height = 5,
- ColorScheme = Colors.ColorSchemes ["Error"],
- Title = "W: Auto, H: 5",
- BorderStyle = LineStyle.Rounded
- };
- widthAuto.Id = "widthAuto";
- view.Add (widthAuto);
- var bothAuto = new View
- {
- X = Pos.Right (widthAuto) + 1,
- Y = Pos.Bottom (hlabel) + 1,
- Width = Auto (),
- Height = Auto (),
- ColorScheme = Colors.ColorSchemes ["Error"],
- Title = "W: Auto, H: Auto",
- BorderStyle = LineStyle.Rounded
- };
- bothAuto.Id = "bothAuto";
- view.Add (bothAuto);
- textEdit.ContentsChanged += (s, e) =>
- {
- hlabel.Text = textEdit.Text;
- vlabel.Text = textEdit.Text;
- heightAuto.Text = textEdit.Text;
- widthAuto.Text = textEdit.Text;
- bothAuto.Text = textEdit.Text;
- };
- var movingButton = new Button
- {
- Text = "_Move down",
- X = Pos.Right (vlabel),
- Y = Pos.Bottom (vlabel),
- };
- movingButton.Accept += (s, e) => { movingButton.Y = movingButton.Frame.Y + 1; };
- view.Add (movingButton);
- var resetButton = new Button
- {
- Text = "_Reset Button",
- X = Pos.Right (movingButton),
- Y = Pos.Top (movingButton)
- };
- resetButton.Accept += (s, e) => { movingButton.Y = Pos.Bottom (hlabel); };
- view.Add (resetButton);
- var dlgButton = new Button
- {
- Text = "Open Test _Dialog",
- X = Pos.Right (view),
- Y = Pos.Top (view)
- };
- dlgButton.Accept += DlgButton_Clicked;
- appWindow.Add (view, dlgButton);
- // Run - Start the application.
- Application.Run (appWindow);
- appWindow.Dispose ();
- // Shutdown - Calling Application.Shutdown is required.
- Application.Shutdown ();
- }
- private void DlgButton_Clicked (object sender, EventArgs e)
- {
- var dlg = new Dialog
- {
- Title = "Test Dialog",
- Width = Dim.Auto (min: Dim.Percent (10)),
- //Height = Dim.Auto (min: Dim.Percent (50))
- };
- //var ok = new Button ("Bye") { IsDefault = true };
- //ok.Clicked += (s, _) => Application.RequestStop (dlg);
- //dlg.AddButton (ok);
- //var cancel = new Button ("Abort") { };
- //cancel.Clicked += (s, _) => Application.RequestStop (dlg);
- //dlg.AddButton (cancel);
- //var label = new Label
- //{
- // ValidatePosDim = true,
- // Text = "This is a label (AutoSize = false; Dim.Auto(3/20). Press Esc to close. Even more text.",
- // AutoSize = false,
- // X = Pos.Center (),
- // Y = 0,
- // Height = Auto (min: 3),
- // Width = Auto (min: 20),
- // ColorScheme = Colors.ColorSchemes ["Menu"]
- //};
- var text = new TextField
- {
- ValidatePosDim = true,
- Text = "TextField: X=1; Y=Pos.Bottom (label)+1, Width=Dim.Fill (0); Height=1",
- TextFormatter = new TextFormatter { WordWrap = true },
- X = 0,
- Y = 0, //Pos.Bottom (label) + 1,
- Width = Fill (10),
- Height = 1
- };
- //var btn = new Button
- //{
- // Text = "AnchorEnd", Y = Pos.AnchorEnd (1)
- //};
- //// TODO: We should really fix AnchorEnd to do this automatically.
- //btn.X = Pos.AnchorEnd () - (Pos.Right (btn) - Pos.Left (btn));
- //dlg.Add (label);
- dlg.Add (text);
- //dlg.Add (btn);
- Application.Run (dlg);
- dlg.Dispose ();
- }
- }
|