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.

251 lines
5.5KB

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