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.

254 lines
5.6KB

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