demo.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Terminal;
  2. class Demo {
  3. static void ShowTextAlignments (View container)
  4. {
  5. container.Add (
  6. new Label (new Rect (0, 0, 40, 3), "1-Hello world, how are you doing today") { TextAlignment = TextAlignment.Left },
  7. new Label (new Rect (0, 4, 40, 3), "2-Hello world, how are you doing today") { TextAlignment = TextAlignment.Right },
  8. new Label (new Rect (0, 8, 40, 3), "3-Hello world, how are you doing today") { TextAlignment = TextAlignment.Centered },
  9. new Label (new Rect (0, 12, 40, 3), "4-Hello world, how are you doing today") { TextAlignment = TextAlignment.Justified });
  10. }
  11. static void ShowEntries (View container)
  12. {
  13. container.Add (
  14. new Label (3, 2, "Login: "),
  15. new TextField (14, 2, 40, ""),
  16. new Label (3, 4, "Password: "),
  17. new TextField (14, 4, 40, "") { Secret = true },
  18. new CheckBox (3, 6, "Remember me"),
  19. new RadioGroup (3, 8, new [] { "_Personal", "_Company" }),
  20. new Button (3, 14, "Ok"),
  21. new Button (10, 14, "Cancel"),
  22. new Label (3, 18, "Press ESC and 9 to activate the menubar")
  23. );
  24. }
  25. public static Label ml2;
  26. static void NewFile ()
  27. {
  28. var d = new Dialog (
  29. "New File", 50, 20,
  30. new Button ("Ok", is_default: true ) { Clicked = () => { Application.RequestStop (); } },
  31. new Button ("Cancel") { Clicked = () => { Application.RequestStop (); } });
  32. ml2 = new Label (1, 1, "Mouse Debug Line");
  33. d.Add (ml2);
  34. Application.Run (d);
  35. }
  36. public static Label ml;
  37. static void Main ()
  38. {
  39. Application.Init ();
  40. var top = Application.Top;
  41. var tframe = top.Frame;
  42. var win = new Window (new Rect (0, 1, tframe.Width, tframe.Height-1), "Hello");
  43. var menu = new MenuBar (new MenuBarItem [] {
  44. new MenuBarItem ("_File", new MenuItem [] {
  45. new MenuItem ("_New", "Creates new file", NewFile),
  46. new MenuItem ("_Open", "", null),
  47. new MenuItem ("_Close", "", null),
  48. new MenuItem ("_Quit", "", () => { top.Running = false; })
  49. }),
  50. new MenuBarItem ("_Edit", new MenuItem [] {
  51. new MenuItem ("_Copy", "", null),
  52. new MenuItem ("C_ut", "", null),
  53. new MenuItem ("_Paste", "", null)
  54. })
  55. });
  56. ShowEntries (win);
  57. int count = 0;
  58. ml = new Label (new Rect (3, 16, 50, 1), "Mouse: ");
  59. Application.RootMouseEvent += delegate (MouseEvent me) {
  60. ml.Text = $"Mouse: ({me.X},{me.Y}) - {me.Flags} {count++}";
  61. };
  62. win.Add (ml);
  63. // ShowTextAlignments (win);
  64. top.Add (win);
  65. top.Add (menu);
  66. Application.Run ();
  67. }
  68. }