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.

252 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 draw(NVGcontext *vg) override;
  160. void step() override;
  161. void onMouseMove(EventMouseMove &e) override;
  162. void onScroll(EventScroll &e) override;
  163. };
  164. struct TextField : OpaqueWidget {
  165. std::string text;
  166. std::string placeholder;
  167. bool multiline = false;
  168. /** The index of the text cursor */
  169. int cursor = 0;
  170. /** The index of the other end of the selection.
  171. If nothing is selected, this is equal to `cursor`.
  172. */
  173. int selection = 0;
  174. TextField() {
  175. box.size.y = BND_WIDGET_HEIGHT;
  176. }
  177. void draw(NVGcontext *vg) override;
  178. void onMouseDown(EventMouseDown &e) override;
  179. void onMouseMove(EventMouseMove &e) override;
  180. void onFocus(EventFocus &e) override;
  181. void onText(EventText &e) override;
  182. void onKey(EventKey &e) override;
  183. /** Inserts text at the cursor, replacing the selection if necessary */
  184. void insertText(std::string text);
  185. /** Replaces the entire text */
  186. void setText(std::string text);
  187. virtual int getTextPosition(Vec mousePos);
  188. virtual void onTextChange() {}
  189. };
  190. struct PasswordField : TextField {
  191. void draw(NVGcontext *vg) override;
  192. };
  193. struct ProgressBar : QuantityWidget {
  194. ProgressBar() {
  195. box.size.y = BND_WIDGET_HEIGHT;
  196. }
  197. void draw(NVGcontext *vg) override;
  198. };
  199. struct Tooltip : VirtualWidget {
  200. void step() override;
  201. void draw(NVGcontext *vg) override;
  202. };
  203. struct Scene : OpaqueWidget {
  204. Widget *overlay = NULL;
  205. void setOverlay(Widget *w);
  206. Menu *createMenu();
  207. void step() override;
  208. };
  209. ////////////////////
  210. // globals
  211. ////////////////////
  212. extern Scene *gScene;
  213. } // namespace rack