| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- #nullable enable
- using System;
- namespace UICatalog.Scenarios;
- [ScenarioMetadata ("RuneWidthGreaterThanOne", "Test rune width greater than one")]
- [ScenarioCategory ("Controls")]
- [ScenarioCategory ("Text and Formatting")]
- [ScenarioCategory ("Tests")]
- public class RuneWidthGreaterThanOne : Scenario
- {
- private Button? _button;
- private Label? _label;
- private Label? _labelR;
- private Label? _labelV;
- private string? _lastRunesUsed;
- private TextField? _text;
- private Window? _win;
- public override void Main ()
- {
- Application.Init ();
- // Window (top-level)
- Window win = new ()
- {
- X = 5,
- Y = 5,
- Width = Dim.Fill (22),
- Height = Dim.Fill (5),
- Arrangement = ViewArrangement.Overlapped | ViewArrangement.Movable
- };
- _win = win;
- // MenuBar
- MenuBar menu = new ();
- // Controls
- _label = new ()
- {
- X = Pos.Center (),
- Y = 1
- };
- _text = new ()
- {
- X = Pos.Center (),
- Y = 3,
- Width = 20
- };
- _button = new ()
- {
- X = Pos.Center (),
- Y = 5
- };
- _labelR = new ()
- {
- X = Pos.AnchorEnd (30),
- Y = 18
- };
- _labelV = new ()
- {
- TextDirection = TextDirection.TopBottom_LeftRight,
- X = Pos.AnchorEnd (30),
- Y = Pos.Bottom (_labelR)
- };
- menu.Add (
- new MenuBarItem (
- "Padding",
- [
- new MenuItem
- {
- Title = "With Padding",
- Action = () =>
- {
- if (_win is { })
- {
- _win.Padding!.Thickness = new (1);
- }
- }
- },
- new MenuItem
- {
- Title = "Without Padding",
- Action = () =>
- {
- if (_win is { })
- {
- _win.Padding!.Thickness = new (0);
- }
- }
- }
- ]
- )
- );
- menu.Add (
- new MenuBarItem (
- "BorderStyle",
- [
- new MenuItem
- {
- Title = "Single",
- Action = () =>
- {
- if (_win is { })
- {
- _win.BorderStyle = LineStyle.Single;
- }
- }
- },
- new MenuItem
- {
- Title = "None",
- Action = () =>
- {
- if (_win is { })
- {
- _win.BorderStyle = LineStyle.None;
- }
- }
- }
- ]
- )
- );
- menu.Add (
- new MenuBarItem (
- "Runes length",
- [
- new MenuItem
- {
- Title = "Wide",
- Action = WideRunes
- },
- new MenuItem
- {
- Title = "Narrow",
- Action = NarrowRunes
- },
- new MenuItem
- {
- Title = "Mixed",
- Action = MixedRunes
- }
- ]
- )
- );
- // Add views in order of visual appearance
- win.Add (menu, _label, _text, _button, _labelR, _labelV);
- WideRunes ();
- Application.Run (win);
- win.Dispose ();
- Application.Shutdown ();
- }
- private void MixedMessage (object? sender, EventArgs e)
- {
- if (_text is { })
- {
- MessageBox.Query (Application.Instance, "Say Hello 你", $"Hello {_text.Text}", "Ok");
- }
- }
- private void MixedRunes ()
- {
- if (_label is null || _text is null || _button is null || _labelR is null || _labelV is null || _win is null)
- {
- return;
- }
- UnsetClickedEvent ();
- _label.Text = "Enter your name 你:";
- _text.Text = "gui.cs 你:";
- _button.Text = "Say Hello 你";
- _button.Accepting += MixedMessage;
- _labelR.X = Pos.AnchorEnd (21);
- _labelR.Y = 18;
- _labelR.Text = "This is a test text 你";
- _labelV.X = Pos.AnchorEnd (21);
- _labelV.Y = Pos.Bottom (_labelR);
- _labelV.Text = "This is a test text 你";
- _win.Title = "HACC Demo 你";
- _lastRunesUsed = "Mixed";
- Application.LayoutAndDraw ();
- }
- private void NarrowMessage (object? sender, EventArgs e)
- {
- if (_text is { })
- {
- MessageBox.Query (Application.Instance, "Say Hello", $"Hello {_text.Text}", "Ok");
- }
- }
- private void NarrowRunes ()
- {
- if (_label is null || _text is null || _button is null || _labelR is null || _labelV is null || _win is null)
- {
- return;
- }
- UnsetClickedEvent ();
- _label.Text = "Enter your name:";
- _text.Text = "gui.cs";
- _button.Text = "Say Hello";
- _button.Accepting += NarrowMessage;
- _labelR.X = Pos.AnchorEnd (19);
- _labelR.Y = 18;
- _labelR.Text = "This is a test text";
- _labelV.X = Pos.AnchorEnd (19);
- _labelV.Y = Pos.Bottom (_labelR);
- _labelV.Text = "This is a test text";
- _win.Title = "HACC Demo";
- _lastRunesUsed = "Narrow";
- Application.LayoutAndDraw ();
- }
- private void UnsetClickedEvent ()
- {
- if (_button is null)
- {
- return;
- }
- switch (_lastRunesUsed)
- {
- case "Narrow":
- _button.Accepting -= NarrowMessage;
- break;
- case "Mixed":
- _button.Accepting -= MixedMessage;
- break;
- case "Wide":
- _button.Accepting -= WideMessage;
- break;
- }
- }
- private void WideMessage (object? sender, EventArgs e)
- {
- if (_text is { })
- {
- MessageBox.Query (Application.Instance, "こんにちはと言う", $"こんにちは {_text.Text}", "Ok");
- }
- }
- private void WideRunes ()
- {
- if (_label is null || _text is null || _button is null || _labelR is null || _labelV is null || _win is null)
- {
- return;
- }
- UnsetClickedEvent ();
- _label.Text = "あなたの名前を入力してください:";
- _text.Text = "ティラミス";
- _button.Text = "こんにちはと言う";
- _button.Accepting += WideMessage;
- _labelR.X = Pos.AnchorEnd (29);
- _labelR.Y = 18;
- _labelR.Text = "あなたの名前を入力してください";
- _labelV.X = Pos.AnchorEnd (29);
- _labelV.Y = Pos.Bottom (_labelR);
- _labelV.Text = "あなたの名前を入力してください";
- _win.Title = "デモエムポンズ";
- _lastRunesUsed = "Wide";
- Application.LayoutAndDraw ();
- }
- }
|