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.

248 lines
5.4KB

  1. #pragma once
  2. #include "widgets.hpp"
  3. #include "blendish.h"
  4. namespace rack {
  5. ////////////////////
  6. // Layouts
  7. ////////////////////
  8. /** Positions children in a row/column based on their widths/heights */
  9. struct SequentialLayout : virtual Widget {
  10. enum Orientation {
  11. HORIZONTAL_ORIENTATION,
  12. VERTICAL_ORIENTATION,
  13. };
  14. Orientation orientation = HORIZONTAL_ORIENTATION;
  15. enum Alignment {
  16. LEFT_ALIGNMENT,
  17. CENTER_ALIGNMENT,
  18. RIGHT_ALIGNMENT,
  19. };
  20. Alignment alignment = LEFT_ALIGNMENT;
  21. float margin = 0.0;
  22. void step() override;
  23. };
  24. ////////////////////
  25. // Blendish UI elements
  26. ////////////////////
  27. struct Label : VirtualWidget {
  28. std::string text;
  29. enum Alignment {
  30. LEFT_ALIGNMENT,
  31. CENTER_ALIGNMENT,
  32. RIGHT_ALIGNMENT,
  33. };
  34. Alignment alignment = LEFT_ALIGNMENT;
  35. Label() {
  36. box.size.y = BND_WIDGET_HEIGHT;
  37. }
  38. void draw(NVGcontext *vg) override;
  39. };
  40. struct List : OpaqueWidget {
  41. void step() override;
  42. void draw(NVGcontext *vg) override;
  43. };
  44. /** Deletes itself from parent when clicked */
  45. struct MenuOverlay : OpaqueWidget {
  46. void step() override;
  47. void onMouseDown(EventMouseDown &e) override;
  48. void onHoverKey(EventHoverKey &e) override;
  49. };
  50. struct MenuEntry;
  51. struct Menu : OpaqueWidget {
  52. Menu *parentMenu = NULL;
  53. Menu *childMenu = NULL;
  54. /** The entry which created the child menu */
  55. MenuEntry *activeEntry = NULL;
  56. Menu() {
  57. box.size = Vec(0, 0);
  58. }
  59. ~Menu();
  60. /** Deprecated. Just use addChild(child) instead */
  61. void pushChild(Widget *child) DEPRECATED {
  62. addChild(child);
  63. }
  64. void setChildMenu(Menu *menu);
  65. void step() override;
  66. void draw(NVGcontext *vg) override;
  67. void onScroll(EventScroll &e) override;
  68. };
  69. struct MenuEntry : OpaqueWidget {
  70. MenuEntry() {
  71. box.size = Vec(0, BND_WIDGET_HEIGHT);
  72. }
  73. template <typename T = MenuEntry>
  74. static T *create() {
  75. T *o = Widget::create<T>(Vec());
  76. return o;
  77. }
  78. };
  79. struct MenuLabel : MenuEntry {
  80. std::string text;
  81. void draw(NVGcontext *vg) override;
  82. void step() override;
  83. template <typename T = MenuLabel>
  84. static T *create(std::string text) {
  85. T *o = MenuEntry::create<T>();
  86. o->text = text;
  87. return o;
  88. }
  89. };
  90. struct MenuItem : MenuEntry {
  91. std::string text;
  92. std::string rightText;
  93. void draw(NVGcontext *vg) override;
  94. void step() override;
  95. virtual Menu *createChildMenu() {return NULL;}
  96. void onMouseEnter(EventMouseEnter &e) override;
  97. void onDragDrop(EventDragDrop &e) override;
  98. template <typename T = MenuItem>
  99. static T *create(std::string text, std::string rightText = "") {
  100. T *o = MenuEntry::create<T>();
  101. o->text = text;
  102. o->rightText = rightText;
  103. return o;
  104. }
  105. };
  106. struct WindowOverlay : OpaqueWidget {
  107. };
  108. struct WindowWidget : OpaqueWidget {
  109. std::string title;
  110. void draw(NVGcontext *vg) override;
  111. void onDragMove(EventDragMove &e) override;
  112. };
  113. struct Button : OpaqueWidget {
  114. std::string text;
  115. BNDwidgetState state = BND_DEFAULT;
  116. Button() {
  117. box.size.y = BND_WIDGET_HEIGHT;
  118. }
  119. void draw(NVGcontext *vg) override;
  120. void onMouseEnter(EventMouseEnter &e) override;
  121. void onMouseLeave(EventMouseLeave &e) override;
  122. void onDragStart(EventDragStart &e) override;
  123. void onDragEnd(EventDragEnd &e) override;
  124. void onDragDrop(EventDragDrop &e) override;
  125. };
  126. struct ChoiceButton : Button {
  127. void draw(NVGcontext *vg) override;
  128. };
  129. struct RadioButton : OpaqueWidget, QuantityWidget {
  130. BNDwidgetState state = BND_DEFAULT;
  131. RadioButton() {
  132. box.size.y = BND_WIDGET_HEIGHT;
  133. }
  134. void draw(NVGcontext *vg) override;
  135. void onMouseEnter(EventMouseEnter &e) override;
  136. void onMouseLeave(EventMouseLeave &e) override;
  137. void onDragDrop(EventDragDrop &e) override;
  138. };
  139. struct Slider : OpaqueWidget, QuantityWidget {
  140. BNDwidgetState state = BND_DEFAULT;
  141. Slider() {
  142. box.size.y = BND_WIDGET_HEIGHT;
  143. }
  144. void draw(NVGcontext *vg) override;
  145. void onDragStart(EventDragStart &e) override;
  146. void onDragMove(EventDragMove &e) override;
  147. void onDragEnd(EventDragEnd &e) override;
  148. void onMouseDown(EventMouseDown &e) override;
  149. };
  150. struct ScrollBar;
  151. /** Handles a container with ScrollBar */
  152. struct ScrollWidget : OpaqueWidget {
  153. Widget *container;
  154. ScrollBar *horizontalScrollBar;
  155. ScrollBar *verticalScrollBar;
  156. Vec offset;
  157. ScrollWidget();
  158. void draw(NVGcontext *vg) override;
  159. void step() override;
  160. void onMouseMove(EventMouseMove &e) override;
  161. void onScroll(EventScroll &e) override;
  162. };
  163. struct TextField : OpaqueWidget {
  164. std::string text;
  165. std::string placeholder;
  166. bool multiline = false;
  167. int begin = 0;
  168. int end = 0;
  169. int dragPos = 0;
  170. TextField() {
  171. box.size.y = BND_WIDGET_HEIGHT;
  172. }
  173. void draw(NVGcontext *vg) override;
  174. void onMouseDown(EventMouseDown &e) override;
  175. void onMouseMove(EventMouseMove &e) override;
  176. void onFocus(EventFocus &e) override;
  177. void onText(EventText &e) override;
  178. void onKey(EventKey &e) override;
  179. /** Inserts text at the cursor, replacing the selection if necessary */
  180. void insertText(std::string text);
  181. /** Replaces the entire text */
  182. void setText(std::string text);
  183. virtual int getTextPosition(Vec mousePos);
  184. virtual void onTextChange() {}
  185. };
  186. struct PasswordField : TextField {
  187. void draw(NVGcontext *vg) override;
  188. };
  189. struct ProgressBar : QuantityWidget {
  190. ProgressBar() {
  191. box.size.y = BND_WIDGET_HEIGHT;
  192. }
  193. void draw(NVGcontext *vg) override;
  194. };
  195. struct Tooltip : VirtualWidget {
  196. void step() override;
  197. void draw(NVGcontext *vg) override;
  198. };
  199. struct Scene : OpaqueWidget {
  200. Widget *overlay = NULL;
  201. void setOverlay(Widget *w);
  202. Menu *createMenu();
  203. void step() override;
  204. };
  205. ////////////////////
  206. // globals
  207. ////////////////////
  208. extern Scene *gScene;
  209. } // namespace rack