AutoSizeAndDirectionText.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Terminal.Gui;
  2. namespace UICatalog.Scenarios {
  3. [ScenarioMetadata (Name: "AutoSize and Direction Text", Description: "Demonstrates the text auto-size and direction manipulation.")]
  4. [ScenarioCategory ("Text")]
  5. public class AutoSizeAndDirectionText : Scenario {
  6. public override void Setup ()
  7. {
  8. var text = "Hello World";
  9. var color = Colors.Dialog;
  10. var labelH = new Label (text, TextDirection.LeftRight_TopBottom) {
  11. X = 1,
  12. Y = 1,
  13. ColorScheme = color
  14. };
  15. Win.Add (labelH);
  16. var labelV = new Label (text, TextDirection.TopBottom_LeftRight) {
  17. X = 70,
  18. Y = 1,
  19. ColorScheme = color
  20. };
  21. Win.Add (labelV);
  22. var editText = new TextView () {
  23. X = Pos.Center (),
  24. Y = Pos.Center (),
  25. Width = 20,
  26. Height = 5,
  27. ColorScheme = color,
  28. Text = text
  29. };
  30. editText.SetFocus ();
  31. Win.Add (editText);
  32. var ckbDirection = new CheckBox ("Toggle Direction") {
  33. X = Pos.Center (),
  34. Y = Pos.Center () + 3
  35. };
  36. ckbDirection.Toggled += (_) => {
  37. if (labelH.TextDirection == TextDirection.LeftRight_TopBottom) {
  38. labelH.TextDirection = TextDirection.TopBottom_LeftRight;
  39. labelV.TextDirection = TextDirection.LeftRight_TopBottom;
  40. } else {
  41. labelH.TextDirection = TextDirection.LeftRight_TopBottom;
  42. labelV.TextDirection = TextDirection.TopBottom_LeftRight;
  43. }
  44. };
  45. Win.Add (ckbDirection);
  46. var ckbAutoSize = new CheckBox ("Auto Size") {
  47. X = Pos.Center (),
  48. Y = Pos.Center () + 5,
  49. Checked = labelH.AutoSize = labelV.AutoSize
  50. };
  51. ckbAutoSize.Toggled += (_) => labelH.AutoSize = labelV.AutoSize = ckbAutoSize.Checked;
  52. Win.Add (ckbAutoSize);
  53. Win.KeyUp += (_) =>
  54. labelH.Text = labelV.Text = text = editText.Text.ToString ();
  55. }
  56. }
  57. }