RuneWidthGreaterThanOne.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using System;
  2. using System.Globalization;
  3. using System.Text;
  4. using System.Threading;
  5. using Terminal.Gui;
  6. namespace UICatalog.Scenarios {
  7. [ScenarioMetadata (Name: "RuneWidthGreaterThanOne", Description: "Test rune width greater than one")]
  8. [ScenarioCategory ("Controls")]
  9. public class RuneWidthGreaterThanOne : Scenario {
  10. private Label _label;
  11. private TextField _text;
  12. private Button _button;
  13. private Label _labelR;
  14. private Label _labelV;
  15. private Window _win;
  16. private string _lastRunesUsed;
  17. public override void Init (ColorScheme colorScheme)
  18. {
  19. Application.Init ();
  20. var menu = new MenuBar (new MenuBarItem [] {
  21. new MenuBarItem ("Margin", new MenuItem [] {
  22. new MenuItem ("With margin", "", WithMargin),
  23. new MenuItem ("Without margin", "", WithoutMargin)
  24. }),
  25. new MenuBarItem ("Draw Margin Frame", new MenuItem [] {
  26. new MenuItem ("With draw", "", WithDrawMargin),
  27. new MenuItem ("Without draw", "", WithoutDrawMargin)
  28. }),
  29. new MenuBarItem ("Runes length", new MenuItem [] {
  30. new MenuItem ("Wide", "", WideRunes),
  31. new MenuItem ("Narrow", "", NarrowRunes),
  32. new MenuItem ("Mixed", "", MixedRunes)
  33. })
  34. });
  35. _label = new Label () {
  36. X = Pos.Center (),
  37. Y = 1,
  38. ColorScheme = new ColorScheme () {
  39. Normal = Colors.Base.Focus
  40. }
  41. };
  42. _text = new TextField () {
  43. X = Pos.Center (),
  44. Y = 3,
  45. Width = 20
  46. };
  47. _button = new Button () {
  48. X = Pos.Center (),
  49. Y = 5
  50. };
  51. _labelR = new Label () {
  52. X = Pos.AnchorEnd (30),
  53. Y = 18
  54. };
  55. _labelV = new Label () {
  56. TextDirection = TextDirection.TopBottom_LeftRight,
  57. X = Pos.AnchorEnd (30),
  58. Y = Pos.Bottom (_labelR)
  59. };
  60. _win = new Window () {
  61. X = 5,
  62. Y = 5,
  63. Width = Dim.Fill (22),
  64. Height = Dim.Fill (5)
  65. };
  66. _win.Add (_label, _text, _button, _labelR, _labelV);
  67. Application.Top.Add (menu, _win);
  68. WideRunes ();
  69. //NarrowRunes ();
  70. //MixedRunes ();
  71. Application.Run ();
  72. }
  73. private void UnsetClickedEvent ()
  74. {
  75. switch (_lastRunesUsed) {
  76. case "Narrow":
  77. _button.Clicked -= NarrowMessage;
  78. break;
  79. case "Mixed":
  80. _button.Clicked -= MixedMessage;
  81. break;
  82. case "Wide":
  83. _button.Clicked -= WideMessage;
  84. break;
  85. }
  86. }
  87. private void MixedMessage ()
  88. {
  89. MessageBox.Query ("Say Hello 你", $"Hello {_text.Text}", "Ok");
  90. }
  91. private void NarrowMessage ()
  92. {
  93. MessageBox.Query ("Say Hello", $"Hello {_text.Text}", "Ok");
  94. }
  95. private void WideMessage ()
  96. {
  97. MessageBox.Query ("こんにちはと言う", $"こんにちは {_text.Text}", "Ok");
  98. }
  99. private void MixedRunes ()
  100. {
  101. UnsetClickedEvent ();
  102. _label.Text = "Enter your name 你:";
  103. _text.Text = "gui.cs 你:";
  104. _button.Text = "Say Hello 你";
  105. _button.Clicked += MixedMessage;
  106. _labelR.X = Pos.AnchorEnd (21);
  107. _labelR.Y = 18;
  108. _labelR.Text = "This is a test text 你";
  109. _labelV.X = Pos.AnchorEnd (21);
  110. _labelV.Y = Pos.Bottom (_labelR);
  111. _labelV.Text = "This is a test text 你";
  112. _win.Title = "HACC Demo 你";
  113. _lastRunesUsed = "Mixed";
  114. Application.Refresh ();
  115. }
  116. private void NarrowRunes ()
  117. {
  118. UnsetClickedEvent ();
  119. _label.Text = "Enter your name:";
  120. _text.Text = "gui.cs";
  121. _button.Text = "Say Hello";
  122. _button.Clicked += NarrowMessage;
  123. _labelR.X = Pos.AnchorEnd (19);
  124. _labelR.Y = 18;
  125. _labelR.Text = "This is a test text";
  126. _labelV.X = Pos.AnchorEnd (19);
  127. _labelV.Y = Pos.Bottom (_labelR);
  128. _labelV.Text = "This is a test text";
  129. _win.Title = "HACC Demo";
  130. _lastRunesUsed = "Narrow";
  131. Application.Refresh ();
  132. }
  133. private void WideRunes ()
  134. {
  135. UnsetClickedEvent ();
  136. _label.Text = "あなたの名前を入力してください:";
  137. _text.Text = "ティラミス";
  138. _button.Text = "こんにちはと言う";
  139. _button.Clicked += WideMessage;
  140. _labelR.X = Pos.AnchorEnd (29);
  141. _labelR.Y = 18;
  142. _labelR.Text = "あなたの名前を入力してください";
  143. _labelV.X = Pos.AnchorEnd (29);
  144. _labelV.Y = Pos.Bottom (_labelR);
  145. _labelV.Text = "あなたの名前を入力してください";
  146. _win.Title = "デモエムポンズ";
  147. _lastRunesUsed = "Wide";
  148. Application.Refresh ();
  149. }
  150. private void WithoutDrawMargin ()
  151. {
  152. _win.Border.BorderStyle = BorderStyle.None;
  153. _win.Border.DrawMarginFrame = false;
  154. }
  155. private void WithDrawMargin ()
  156. {
  157. _win.Border.DrawMarginFrame = true;
  158. _win.Border.BorderStyle = BorderStyle.Single;
  159. }
  160. private void WithoutMargin ()
  161. {
  162. _win.X = 0;
  163. _win.Y = 0;
  164. _win.Width = Dim.Fill ();
  165. _win.Height = Dim.Fill ();
  166. }
  167. private void WithMargin ()
  168. {
  169. _win.X = 5;
  170. _win.Y = 5;
  171. _win.Width = Dim.Fill (22);
  172. _win.Height = Dim.Fill (5);
  173. }
  174. public override void Run ()
  175. {
  176. }
  177. }
  178. }