demo.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Terminal.Gui;
  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, 6, "Login: "),
  15. new TextField (14, 6, 40, ""),
  16. new Label (3, 8, "Password: "),
  17. new TextField (14, 8, 40, "") { Secret = true },
  18. new CheckBox (3, 10, "Remember me"),
  19. new RadioGroup (3, 12, new [] { "_Personal", "_Company" }),
  20. new Button (3, 18, "Ok"),
  21. new Button (10, 18, "Cancel"),
  22. new Label (3, 22, "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. static bool Quit ()
  37. {
  38. var n = MessageBox.Query (50, 7, "Quit Demo", "Are you sure you want to quit this demo?", "Yes", "No");
  39. return n == 0;
  40. }
  41. static void Close ()
  42. {
  43. MessageBox.ErrorQuery (50, 5, "Error", "There is nothing to close", "Ok");
  44. }
  45. public static Label ml;
  46. static void Main ()
  47. {
  48. Application.Init ();
  49. var top = Application.Top;
  50. var tframe = top.Frame;
  51. var win = new Window (new Rect (0, 1, tframe.Width, tframe.Height-1), "Hello");
  52. var menu = new MenuBar (new MenuBarItem [] {
  53. new MenuBarItem ("_File", new MenuItem [] {
  54. new MenuItem ("_New", "Creates new file", NewFile),
  55. new MenuItem ("_Open", "", null),
  56. new MenuItem ("_Close", "", () => Close ()),
  57. new MenuItem ("_Quit", "", () => { if (Quit ()) top.Running = false; })
  58. }),
  59. new MenuBarItem ("_Edit", new MenuItem [] {
  60. new MenuItem ("_Copy", "", null),
  61. new MenuItem ("C_ut", "", null),
  62. new MenuItem ("_Paste", "", null)
  63. })
  64. });
  65. ShowEntries (win);
  66. int count = 0;
  67. ml = new Label (new Rect (3, 16, 50, 1), "Mouse: ");
  68. Application.RootMouseEvent += delegate (MouseEvent me) {
  69. ml.Text = $"Mouse: ({me.X},{me.Y}) - {me.Flags} {count++}";
  70. };
  71. win.Add (ml);
  72. // ShowTextAlignments (win);
  73. top.Add (win);
  74. top.Add (menu);
  75. Application.Run ();
  76. }
  77. }