You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui.hpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #pragma once
  2. #include "widgets.hpp"
  3. #include "../ext/oui-blendish/blendish.h"
  4. namespace rack {
  5. struct Label : Widget {
  6. std::string text;
  7. Label() {
  8. box.size.y = BND_WIDGET_HEIGHT;
  9. }
  10. void draw(NVGcontext *vg) override;
  11. };
  12. /** Deletes itself from parent when clicked */
  13. struct MenuOverlay : OpaqueWidget {
  14. void step() override;
  15. void onMouseDown(EventMouseDown &e) override;
  16. void onHoverKey(EventHoverKey &e) override;
  17. };
  18. struct MenuEntry;
  19. struct Menu : OpaqueWidget {
  20. Menu *parentMenu = NULL;
  21. Menu *childMenu = NULL;
  22. /** The entry which created the child menu */
  23. MenuEntry *activeEntry = NULL;
  24. Menu() {
  25. box.size = Vec(0, 0);
  26. }
  27. ~Menu();
  28. // Resizes menu and calls addChild()
  29. void pushChild(Widget *child) DEPRECATED {
  30. addChild(child);
  31. }
  32. void setChildMenu(Menu *menu);
  33. void step() override;
  34. void draw(NVGcontext *vg) override;
  35. void onScroll(EventScroll &e) override;
  36. };
  37. struct MenuEntry : OpaqueWidget {
  38. std::string text;
  39. MenuEntry() {
  40. box.size = Vec(0, BND_WIDGET_HEIGHT);
  41. }
  42. };
  43. struct MenuLabel : MenuEntry {
  44. void draw(NVGcontext *vg) override;
  45. void step() override;
  46. };
  47. struct MenuItem : MenuEntry {
  48. std::string rightText;
  49. void draw(NVGcontext *vg) override;
  50. void step() override;
  51. virtual Menu *createChildMenu() {return NULL;}
  52. void onMouseEnter(EventMouseEnter &e) override;
  53. void onDragDrop(EventDragDrop &e) override;
  54. };
  55. struct WindowOverlay : OpaqueWidget {
  56. };
  57. struct Window : OpaqueWidget {
  58. std::string title;
  59. void draw(NVGcontext *vg) override;
  60. void onDragMove(EventDragMove &e) override;
  61. };
  62. struct Button : OpaqueWidget {
  63. std::string text;
  64. BNDwidgetState state = BND_DEFAULT;
  65. Button() {
  66. box.size.y = BND_WIDGET_HEIGHT;
  67. }
  68. void draw(NVGcontext *vg) override;
  69. void onMouseEnter(EventMouseEnter &e) override;
  70. void onMouseLeave(EventMouseLeave &e) override;
  71. void onDragStart(EventDragStart &e) override;
  72. void onDragEnd(EventDragEnd &e) override;
  73. void onDragDrop(EventDragDrop &e) override;
  74. };
  75. struct ChoiceButton : Button {
  76. void draw(NVGcontext *vg) override;
  77. };
  78. struct RadioButton : OpaqueWidget, QuantityWidget {
  79. BNDwidgetState state = BND_DEFAULT;
  80. RadioButton() {
  81. box.size.y = BND_WIDGET_HEIGHT;
  82. }
  83. void draw(NVGcontext *vg) override;
  84. void onMouseEnter(EventMouseEnter &e) override;
  85. void onMouseLeave(EventMouseLeave &e) override;
  86. void onDragDrop(EventDragDrop &e) override;
  87. };
  88. struct Slider : OpaqueWidget, QuantityWidget {
  89. BNDwidgetState state = BND_DEFAULT;
  90. Slider() {
  91. box.size.y = BND_WIDGET_HEIGHT;
  92. }
  93. void draw(NVGcontext *vg) override;
  94. void onDragStart(EventDragStart &e) override;
  95. void onDragMove(EventDragMove &e) override;
  96. void onDragEnd(EventDragEnd &e) override;
  97. void onMouseDown(EventMouseDown &e) override;
  98. };
  99. /** Parent must be a ScrollWidget */
  100. struct ScrollBar : OpaqueWidget {
  101. enum { VERTICAL, HORIZONTAL } orientation;
  102. BNDwidgetState state = BND_DEFAULT;
  103. float offset = 0.0;
  104. float size = 0.0;
  105. ScrollBar() {
  106. box.size = Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT);
  107. }
  108. void draw(NVGcontext *vg) override;
  109. void onDragStart(EventDragStart &e) override;
  110. void onDragMove(EventDragMove &e) override;
  111. void onDragEnd(EventDragEnd &e) override;
  112. };
  113. /** Handles a container with ScrollBar */
  114. struct ScrollWidget : OpaqueWidget {
  115. Widget *container;
  116. ScrollBar *horizontalScrollBar;
  117. ScrollBar *verticalScrollBar;
  118. Vec offset;
  119. ScrollWidget();
  120. void draw(NVGcontext *vg) override;
  121. void step() override;
  122. void onMouseMove(EventMouseMove &e) override;
  123. void onScroll(EventScroll &e) override;
  124. };
  125. struct TextField : OpaqueWidget {
  126. std::string text;
  127. std::string placeholder;
  128. bool multiline = false;
  129. int begin = 0;
  130. int end = 0;
  131. TextField() {
  132. box.size.y = BND_WIDGET_HEIGHT;
  133. }
  134. void draw(NVGcontext *vg) override;
  135. void onMouseDown(EventMouseDown &e) override;
  136. void onFocus(EventFocus &e) override;
  137. void onText(EventText &e) override;
  138. void onKey(EventKey &e) override;
  139. void insertText(std::string newText);
  140. virtual void onTextChange() {}
  141. };
  142. struct PasswordField : TextField {
  143. void draw(NVGcontext *vg) override;
  144. };
  145. struct ProgressBar : TransparentWidget, QuantityWidget {
  146. ProgressBar() {
  147. box.size.y = BND_WIDGET_HEIGHT;
  148. }
  149. void draw(NVGcontext *vg) override;
  150. };
  151. struct Tooltip : Widget {
  152. void step() override;
  153. void draw(NVGcontext *vg) override;
  154. };
  155. struct Scene : OpaqueWidget {
  156. Widget *overlay = NULL;
  157. void setOverlay(Widget *w);
  158. Menu *createMenu();
  159. void step() override;
  160. };
  161. ////////////////////
  162. // globals
  163. ////////////////////
  164. extern Scene *gScene;
  165. } // namespace rack