Browse Source

Add disabled state to MenuItem appearance

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
0490a9d13d
3 changed files with 27 additions and 6 deletions
  1. +3
    -0
      include/event.hpp
  2. +11
    -0
      src/app/Toolbar.cpp
  3. +13
    -6
      src/ui/MenuItem.cpp

+ 3
- 0
include/event.hpp View File

@@ -208,6 +208,9 @@ struct Zoom : Event {




struct Context { struct Context {
/** State widgets
Don't set these directly unless you know what you're doing. Use the set*() methods instead.
*/
Widget *rootWidget = NULL; Widget *rootWidget = NULL;
Widget *hoveredWidget = NULL; Widget *hoveredWidget = NULL;
Widget *draggedWidget = NULL; Widget *draggedWidget = NULL;


+ 11
- 0
src/app/Toolbar.cpp View File

@@ -334,6 +334,16 @@ struct ManageItem : MenuItem {
}; };




struct SyncItem : MenuItem {
SyncItem() {
text = "Sync";
disabled = true;
}
void onAction(event::Action &e) override {
}
};


// struct SyncButton : Button { // struct SyncButton : Button {
// bool checked = false; // bool checked = false;
// /** Updates are available */ // /** Updates are available */
@@ -416,6 +426,7 @@ struct PluginsButton : MenuButton {
} }
else if (plugin::isLoggedIn()) { else if (plugin::isLoggedIn()) {
menu->addChild(new ManageItem); menu->addChild(new ManageItem);
menu->addChild(new SyncItem);
menu->addChild(new LogOutItem); menu->addChild(new LogOutItem);
} }
else { else {


+ 13
- 6
src/ui/MenuItem.cpp View File

@@ -4,18 +4,25 @@ namespace rack {




void MenuItem::draw(NVGcontext *vg) { void MenuItem::draw(NVGcontext *vg) {
// Get state
BNDwidgetState state = (context()->event->hoveredWidget == this) ? BND_HOVER : BND_DEFAULT;
BNDwidgetState state = BND_DEFAULT;

if (context()->event->hoveredWidget == this)
state = BND_HOVER;

// Set active state if this MenuItem // Set active state if this MenuItem
Menu *parentMenu = dynamic_cast<Menu*>(parent); Menu *parentMenu = dynamic_cast<Menu*>(parent);
if (parentMenu && parentMenu->activeEntry == this) {
if (parentMenu && parentMenu->activeEntry == this)
state = BND_ACTIVE; state = BND_ACTIVE;
}


bndMenuItem(vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str());
// Main text and background
if (!disabled)
bndMenuItem(vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str());
else
bndMenuLabel(vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str());


// Right text
float x = box.size.x - bndLabelWidth(vg, -1, rightText.c_str()); float x = box.size.x - bndLabelWidth(vg, -1, rightText.c_str());
NVGcolor rightColor = (state == BND_DEFAULT) ? bndGetTheme()->menuTheme.textColor : bndGetTheme()->menuTheme.textSelectedColor;
NVGcolor rightColor = (state == BND_DEFAULT && !disabled) ? 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); bndIconLabelValue(vg, x, 0.0, box.size.x, box.size.y, -1, rightColor, BND_LEFT, BND_LABEL_FONT_SIZE, rightText.c_str(), NULL);
} }




Loading…
Cancel
Save