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