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.

227 lines
4.9KB

  1. #pragma once
  2. #include "widgets.hpp"
  3. #include "blendish.h"
  4. namespace rack {
  5. struct Label : Widget {
  6. std::string text;
  7. enum Align {
  8. LEFT_ALIGN,
  9. CENTER_ALIGN,
  10. RIGHT_ALIGN
  11. };
  12. Align align = LEFT_ALIGN;
  13. Label() {
  14. box.size.y = BND_WIDGET_HEIGHT;
  15. }
  16. void draw(NVGcontext *vg) override;
  17. };
  18. struct List : OpaqueWidget {
  19. void step() override;
  20. void draw(NVGcontext *vg) override;
  21. };
  22. /** Deletes itself from parent when clicked */
  23. struct MenuOverlay : OpaqueWidget {
  24. void step() override;
  25. void onMouseDown(EventMouseDown &e) override;
  26. void onHoverKey(EventHoverKey &e) override;
  27. };
  28. struct MenuEntry;
  29. struct Menu : OpaqueWidget {
  30. Menu *parentMenu = NULL;
  31. Menu *childMenu = NULL;
  32. /** The entry which created the child menu */
  33. MenuEntry *activeEntry = NULL;
  34. Menu() {
  35. box.size = Vec(0, 0);
  36. }
  37. ~Menu();
  38. /** Deprecated. Just use addChild(child) instead */
  39. void pushChild(Widget *child) DEPRECATED {
  40. addChild(child);
  41. }
  42. void setChildMenu(Menu *menu);
  43. void step() override;
  44. void draw(NVGcontext *vg) override;
  45. void onScroll(EventScroll &e) override;
  46. };
  47. struct MenuEntry : OpaqueWidget {
  48. template <typename T = MenuEntry>
  49. static T *create() {
  50. T *o = Widget::create<T>(Vec());
  51. return o;
  52. }
  53. };
  54. struct MenuLabel : MenuEntry {
  55. std::string text;
  56. MenuLabel() {
  57. box.size = Vec(0, BND_WIDGET_HEIGHT);
  58. }
  59. void draw(NVGcontext *vg) override;
  60. void step() override;
  61. template <typename T = MenuLabel>
  62. static T *create(std::string text) {
  63. T *o = MenuEntry::create<T>();
  64. o->text = text;
  65. return o;
  66. }
  67. };
  68. struct MenuItem : MenuEntry {
  69. std::string text;
  70. std::string rightText;
  71. MenuItem() {
  72. box.size = Vec(0, BND_WIDGET_HEIGHT);
  73. }
  74. void draw(NVGcontext *vg) override;
  75. void step() override;
  76. virtual Menu *createChildMenu() {return NULL;}
  77. void onMouseEnter(EventMouseEnter &e) override;
  78. void onDragDrop(EventDragDrop &e) override;
  79. template <typename T = MenuItem>
  80. static T *create(std::string text, std::string rightText = "") {
  81. T *o = MenuEntry::create<T>();
  82. o->text = text;
  83. o->rightText = rightText;
  84. return o;
  85. }
  86. };
  87. struct WindowOverlay : OpaqueWidget {
  88. };
  89. struct WindowWidget : OpaqueWidget {
  90. std::string title;
  91. void draw(NVGcontext *vg) override;
  92. void onDragMove(EventDragMove &e) override;
  93. };
  94. struct Button : OpaqueWidget {
  95. std::string text;
  96. BNDwidgetState state = BND_DEFAULT;
  97. Button() {
  98. box.size.y = BND_WIDGET_HEIGHT;
  99. }
  100. void draw(NVGcontext *vg) override;
  101. void onMouseEnter(EventMouseEnter &e) override;
  102. void onMouseLeave(EventMouseLeave &e) override;
  103. void onDragStart(EventDragStart &e) override;
  104. void onDragEnd(EventDragEnd &e) override;
  105. void onDragDrop(EventDragDrop &e) override;
  106. };
  107. struct ChoiceButton : Button {
  108. void draw(NVGcontext *vg) override;
  109. };
  110. struct RadioButton : OpaqueWidget, QuantityWidget {
  111. BNDwidgetState state = BND_DEFAULT;
  112. RadioButton() {
  113. box.size.y = BND_WIDGET_HEIGHT;
  114. }
  115. void draw(NVGcontext *vg) override;
  116. void onMouseEnter(EventMouseEnter &e) override;
  117. void onMouseLeave(EventMouseLeave &e) override;
  118. void onDragDrop(EventDragDrop &e) override;
  119. };
  120. struct Slider : OpaqueWidget, QuantityWidget {
  121. BNDwidgetState state = BND_DEFAULT;
  122. Slider() {
  123. box.size.y = BND_WIDGET_HEIGHT;
  124. }
  125. void draw(NVGcontext *vg) override;
  126. void onDragStart(EventDragStart &e) override;
  127. void onDragMove(EventDragMove &e) override;
  128. void onDragEnd(EventDragEnd &e) override;
  129. void onMouseDown(EventMouseDown &e) override;
  130. };
  131. struct ScrollBar;
  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. /** Inserts text at the cursor, replacing the selection if necessary */
  161. void insertText(std::string text);
  162. /** Replaces the entire text */
  163. void setText(std::string text);
  164. virtual int getTextPosition(Vec mousePos);
  165. virtual void onTextChange() {}
  166. };
  167. struct PasswordField : TextField {
  168. void draw(NVGcontext *vg) override;
  169. };
  170. struct ProgressBar : QuantityWidget {
  171. ProgressBar() {
  172. box.size.y = BND_WIDGET_HEIGHT;
  173. }
  174. void draw(NVGcontext *vg) override;
  175. };
  176. struct Tooltip : Widget {
  177. void step() override;
  178. void draw(NVGcontext *vg) override;
  179. };
  180. struct Scene : OpaqueWidget {
  181. Widget *overlay = NULL;
  182. void setOverlay(Widget *w);
  183. Menu *createMenu();
  184. void step() override;
  185. };
  186. ////////////////////
  187. // globals
  188. ////////////////////
  189. extern Scene *gScene;
  190. } // namespace rack