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.

56 lines
1.4KB

  1. #include "widgets.hpp"
  2. namespace rack {
  3. #define RIGHT_PADDING 10.0
  4. #define BND_LABEL_FONT_SIZE 13
  5. float MenuItem::computeMinWidth(NVGcontext *vg) {
  6. return MenuEntry::computeMinWidth(vg) + RIGHT_PADDING + bndLabelWidth(vg, -1, rightText.c_str());
  7. }
  8. void MenuItem::draw(NVGcontext *vg) {
  9. // Get state
  10. BNDwidgetState state = (gHoveredWidget == this) ? BND_HOVER : BND_DEFAULT;
  11. Menu *parentMenu = dynamic_cast<Menu*>(parent);
  12. if (parentMenu && parentMenu->activeEntry == this) {
  13. state = BND_ACTIVE;
  14. }
  15. bndMenuItem(vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str());
  16. float x = box.size.x - bndLabelWidth(vg, -1, rightText.c_str());
  17. NVGcolor rightColor = (state == BND_DEFAULT) ? bndGetTheme()->menuTheme.textColor : bndGetTheme()->menuTheme.textSelectedColor;
  18. bndIconLabelValue(vg, x, 0.0, box.size.x, box.size.y, -1, rightColor, BND_LEFT, BND_LABEL_FONT_SIZE, rightText.c_str(), NULL);
  19. }
  20. void MenuItem::onMouseEnter() {
  21. Menu *parentMenu = dynamic_cast<Menu*>(parent);
  22. if (!parentMenu)
  23. return;
  24. parentMenu->activeEntry = NULL;
  25. // Try to create child menu
  26. Menu *childMenu = createChildMenu();
  27. if (childMenu) {
  28. parentMenu->activeEntry = this;
  29. childMenu->box.pos = parent->box.pos.plus(box.getTopRight());
  30. }
  31. parentMenu->setChildMenu(childMenu);
  32. }
  33. void MenuItem::onDragDrop(Widget *origin) {
  34. if (origin != this)
  35. return;
  36. onAction();
  37. // deletes `this`
  38. gScene->setOverlay(NULL);
  39. }
  40. } // namespace rack