02_HelloGUI.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  3. // Copyright (c) 2015 Xamarin Inc
  4. // Copyright (c) 2016 THUNDERBEAST GAMES LLC
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. // THE SOFTWARE.
  23. //
  24. using AtomicEngine;
  25. namespace FeatureExamples
  26. {
  27. // TODO: Show drag and drop example
  28. public class HelloGUISample : Sample
  29. {
  30. UIWindow window;
  31. public HelloGUISample() : base() { }
  32. public override void Start()
  33. {
  34. base.Start();
  35. // Initialize Window
  36. InitWindow();
  37. }
  38. void InitWindow()
  39. {
  40. var layout = new UILayout();
  41. layout.Axis = UI_AXIS.UI_AXIS_Y;
  42. var checkBox = new UICheckBox();
  43. checkBox.Id = "Checkbox";
  44. layout.AddChild(checkBox);
  45. var button = new UIButton();
  46. button.Text = "Button";
  47. button.Id = "Button";
  48. layout.AddChild(button);
  49. var edit = new UIEditField();
  50. layout.AddChild(edit);
  51. edit.Id = "EditField";
  52. window = new UIWindow();
  53. window.Settings = UI_WINDOW_SETTINGS.UI_WINDOW_SETTINGS_TITLEBAR | UI_WINDOW_SETTINGS.UI_WINDOW_SETTINGS_CLOSE_BUTTON;
  54. window.Text = "Hello Atomic GUI!";
  55. window.AddChild(layout);
  56. window.ResizeToFitContent();
  57. UIView.AddChild(window);
  58. window.Center();
  59. SubscribeToEvent<WidgetEvent>(window, e =>
  60. {
  61. if (e.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK)
  62. {
  63. var target = e.Target;
  64. if (target != null)
  65. {
  66. window.Text = $"Hello: {target.Id}";
  67. }
  68. }
  69. });
  70. SubscribeToEvent<WidgetDeletedEvent>(window, e =>
  71. {
  72. BackToSelector();
  73. });
  74. }
  75. }
  76. }