ViewWithText.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Terminal.Gui;
  5. namespace UICatalog {
  6. [ScenarioMetadata (Name: "View Text", Description: "Demos and tests View's Text capabilities.")]
  7. [ScenarioCategory ("Text")]
  8. [ScenarioCategory ("POC")]
  9. class ViewWithText : Scenario {
  10. public override void Setup ()
  11. {
  12. Win.Text = "This is the Te_xt for the host Win object. TextAlignment.Centered was specified. It is intentionally very long to illustrate word wrap.\n" +
  13. "<-- There is a new line here to show a hard line break. You should see this text bleed underneath the subviews, which start at Y = 3.";
  14. Win.TextAlignment = TextAlignment.Centered;
  15. #if true
  16. string txt = "Hello world, how are you today? Pretty neat!";
  17. #else
  18. string txt = "Hello world, how are you today? Unicode:  ~  gui.cs  . Neat?";
  19. #endif
  20. var alignments = Enum.GetValues (typeof (Terminal.Gui.TextAlignment)).Cast<Terminal.Gui.TextAlignment> ().ToList ();
  21. var label = new View ($"Demonstrating single-line (should clip!):") { Y = 3 };
  22. Win.Add (label);
  23. foreach (var alignment in alignments) {
  24. label = new Label ($"{alignment}:") { Y = Pos.Bottom (label) };
  25. Win.Add (label);
  26. label = new Label (txt) {
  27. TextAlignment = alignment,
  28. Y = Pos.Bottom (label),
  29. Width = Dim.Fill (),
  30. Height = 1,
  31. ColorScheme = Colors.Dialog,
  32. };
  33. Win.Add (label);
  34. }
  35. txt += "\nSecond line\n\nFourth Line.";
  36. label = new View ($"Demonstrating multi-line and word wrap:") { Y = Pos.Bottom (label) + 1 };
  37. Win.Add (label);
  38. foreach (var alignment in alignments) {
  39. label = new View ($"{alignment}:") { Y = Pos.Bottom (label) };
  40. Win.Add (label);
  41. label = new View (txt) { TextAlignment = alignment, Width = Dim.Fill (), Height = 6, ColorScheme = Colors.Dialog, Y = Pos.Bottom (label) };
  42. Win.Add (label);
  43. }
  44. }
  45. }
  46. }