AutoSizeAndDirectionText.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Terminal.Gui;
  2. namespace UICatalog {
  3. [ScenarioMetadata (Name: "AutoSize and Direction Text", Description: "Demonstrates the text auto-size and direction manipulation.")]
  4. [ScenarioCategory ("Text")]
  5. 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. };
  50. ckbAutoSize.Toggled += (_) => labelH.AutoSize = labelV.AutoSize = ckbAutoSize.Checked;
  51. Win.Add (ckbAutoSize);
  52. Win.KeyUp += (_) =>
  53. labelH.Text = labelV.Text = text = editText.Text.ToString ();
  54. }
  55. }
  56. }