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.

226 lines
5.0KB

  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. MenuEntry() {
  39. box.size = Vec(0, BND_WIDGET_HEIGHT);
  40. }
  41. template <typename T = MenuEntry>
  42. static T *create() {
  43. T *o = Widget::create<T>(Vec());
  44. return o;
  45. }
  46. };
  47. struct MenuLabel : MenuEntry {
  48. std::string text;
  49. void draw(NVGcontext *vg) override;
  50. void step() override;
  51. template <typename T = MenuLabel>
  52. static T *create(std::string text) {
  53. T *o = MenuEntry::create<T>();
  54. o->text = text;
  55. return o;
  56. }
  57. };
  58. struct MenuItem : MenuEntry {
  59. std::string text;
  60. std::string rightText;
  61. void draw(NVGcontext *vg) override;
  62. void step() override;
  63. virtual Menu *createChildMenu() {return NULL;}
  64. void onMouseEnter(EventMouseEnter &e) override;
  65. void onDragDrop(EventDragDrop &e) override;
  66. template <typename T = MenuItem>
  67. static T *create(std::string text, std::string rightText = "") {
  68. T *o = MenuEntry::create<T>();
  69. o->text = text;
  70. o->rightText = rightText;
  71. return o;
  72. }
  73. };
  74. struct WindowOverlay : OpaqueWidget {
  75. };
  76. struct Window : OpaqueWidget {
  77. std::string title;
  78. void draw(NVGcontext *vg) override;
  79. void onDragMove(EventDragMove &e) override;
  80. };
  81. struct Button : OpaqueWidget {
  82. std::string text;
  83. BNDwidgetState state = BND_DEFAULT;
  84. Button() {
  85. box.size.y = BND_WIDGET_HEIGHT;
  86. }
  87. void draw(NVGcontext *vg) override;
  88. void onMouseEnter(EventMouseEnter &e) override;
  89. void onMouseLeave(EventMouseLeave &e) override;
  90. void onDragStart(EventDragStart &e) override;
  91. void onDragEnd(EventDragEnd &e) override;
  92. void onDragDrop(EventDragDrop &e) override;
  93. };
  94. struct ChoiceButton : Button {
  95. void draw(NVGcontext *vg) override;
  96. };
  97. struct RadioButton : OpaqueWidget, QuantityWidget {
  98. BNDwidgetState state = BND_DEFAULT;
  99. RadioButton() {
  100. box.size.y = BND_WIDGET_HEIGHT;
  101. }
  102. void draw(NVGcontext *vg) override;
  103. void onMouseEnter(EventMouseEnter &e) override;
  104. void onMouseLeave(EventMouseLeave &e) override;
  105. void onDragDrop(EventDragDrop &e) override;
  106. };
  107. struct Slider : OpaqueWidget, QuantityWidget {
  108. BNDwidgetState state = BND_DEFAULT;
  109. Slider() {
  110. box.size.y = BND_WIDGET_HEIGHT;
  111. }
  112. void draw(NVGcontext *vg) override;
  113. void onDragStart(EventDragStart &e) override;
  114. void onDragMove(EventDragMove &e) override;
  115. void onDragEnd(EventDragEnd &e) override;
  116. void onMouseDown(EventMouseDown &e) override;
  117. };
  118. /** Parent must be a ScrollWidget */
  119. struct ScrollBar : OpaqueWidget {
  120. enum { VERTICAL, HORIZONTAL } orientation;
  121. BNDwidgetState state = BND_DEFAULT;
  122. float offset = 0.0;
  123. float size = 0.0;
  124. ScrollBar() {
  125. box.size = Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT);
  126. }
  127. void draw(NVGcontext *vg) override;
  128. void onDragStart(EventDragStart &e) override;
  129. void onDragMove(EventDragMove &e) override;
  130. void onDragEnd(EventDragEnd &e) override;
  131. };
  132. /** Handles a container with ScrollBar */
  133. struct ScrollWidget : OpaqueWidget {
  134. Widget *container;
  135. ScrollBar *horizontalScrollBar;
  136. ScrollBar *verticalScrollBar;
  137. Vec offset;
  138. ScrollWidget();
  139. void draw(NVGcontext *vg) override;
  140. void step() override;
  141. void onMouseMove(EventMouseMove &e) override;
  142. void onScroll(EventScroll &e) override;
  143. };
  144. struct TextField : OpaqueWidget {
  145. std::string text;
  146. std::string placeholder;
  147. bool multiline = false;
  148. int begin = 0;
  149. int end = 0;
  150. int dragPos = 0;
  151. TextField() {
  152. box.size.y = BND_WIDGET_HEIGHT;
  153. }
  154. void draw(NVGcontext *vg) override;
  155. void onMouseDown(EventMouseDown &e) override;
  156. void onMouseMove(EventMouseMove &e) override;
  157. void onFocus(EventFocus &e) override;
  158. void onText(EventText &e) override;
  159. void onKey(EventKey &e) override;
  160. void insertText(std::string newText);
  161. virtual int getTextPosition(Vec mousePos);
  162. virtual void onTextChange() {}
  163. };
  164. struct PasswordField : TextField {
  165. void draw(NVGcontext *vg) override;
  166. };
  167. struct ProgressBar : QuantityWidget {
  168. ProgressBar() {
  169. box.size.y = BND_WIDGET_HEIGHT;
  170. }
  171. void draw(NVGcontext *vg) override;
  172. };
  173. struct Tooltip : Widget {
  174. void step() override;
  175. void draw(NVGcontext *vg) override;
  176. };
  177. struct Scene : OpaqueWidget {
  178. Widget *overlay = NULL;
  179. void setOverlay(Widget *w);
  180. Menu *createMenu();
  181. void step() override;
  182. };
  183. ////////////////////
  184. // globals
  185. ////////////////////
  186. extern Scene *gScene;
  187. } // namespace rack