createBoolPtrMenuItem().tags/v2.0.0
@@ -239,14 +239,20 @@ Example: | |||
)); | |||
*/ | |||
template <class TMenuItem = ui::MenuItem> | |||
ui::MenuItem* createCheckMenuItem(std::string text, std::function<bool()> checked, std::function<void()> action, bool disabled = false, bool alwaysConsume = false) { | |||
ui::MenuItem* createCheckMenuItem(std::string text, std::string rightText, std::function<bool()> checked, std::function<void()> action, bool disabled = false, bool alwaysConsume = false) { | |||
struct Item : TMenuItem { | |||
std::string rightTextPrefix; | |||
std::function<bool()> checked; | |||
std::function<void()> action; | |||
bool alwaysConsume; | |||
void step() override { | |||
this->rightText = CHECKMARK(checked()); | |||
this->rightText = rightTextPrefix; | |||
if (checked()) { | |||
if (!rightTextPrefix.empty()) | |||
this->rightText += " "; | |||
this->rightText += CHECKMARK_STRING; | |||
} | |||
TMenuItem::step(); | |||
} | |||
void onAction(const event::Action& e) override { | |||
@@ -257,6 +263,7 @@ ui::MenuItem* createCheckMenuItem(std::string text, std::function<bool()> checke | |||
}; | |||
Item* item = createMenuItem<Item>(text); | |||
item->rightTextPrefix = rightText; | |||
item->checked = checked; | |||
item->action = action; | |||
item->disabled = disabled; | |||
@@ -278,14 +285,20 @@ Example: | |||
)); | |||
*/ | |||
template <class TMenuItem = ui::MenuItem> | |||
ui::MenuItem* createBoolMenuItem(std::string text, std::function<bool()> getter, std::function<void(bool state)> setter, bool disabled = false, bool alwaysConsume = false) { | |||
ui::MenuItem* createBoolMenuItem(std::string text, std::string rightText, std::function<bool()> getter, std::function<void(bool state)> setter, bool disabled = false, bool alwaysConsume = false) { | |||
struct Item : TMenuItem { | |||
std::string rightTextPrefix; | |||
std::function<bool()> getter; | |||
std::function<void(size_t)> setter; | |||
bool alwaysConsume; | |||
void step() override { | |||
this->rightText = CHECKMARK(getter()); | |||
this->rightText = rightTextPrefix; | |||
if (getter()) { | |||
if (!rightTextPrefix.empty()) | |||
this->rightText += " "; | |||
this->rightText += CHECKMARK_STRING; | |||
} | |||
TMenuItem::step(); | |||
} | |||
void onAction(const event::Action& e) override { | |||
@@ -296,6 +309,7 @@ ui::MenuItem* createBoolMenuItem(std::string text, std::function<bool()> getter, | |||
}; | |||
Item* item = createMenuItem<Item>(text); | |||
item->rightTextPrefix = rightText; | |||
item->getter = getter; | |||
item->setter = setter; | |||
item->disabled = disabled; | |||
@@ -310,8 +324,8 @@ Example: | |||
menu->addChild(createBoolPtrMenuItem("Loop", &module->loop)); | |||
*/ | |||
template <typename T> | |||
ui::MenuItem* createBoolPtrMenuItem(std::string text, T* ptr) { | |||
return createBoolMenuItem(text, | |||
ui::MenuItem* createBoolPtrMenuItem(std::string text, std::string rightText, T* ptr) { | |||
return createBoolMenuItem(text, rightText, | |||
[=]() {return *ptr;}, | |||
[=](T val) {*ptr = val;} | |||
); | |||
@@ -383,7 +383,7 @@ struct ViewButton : MenuButton { | |||
menu->cornerFlags = BND_CORNER_TOP; | |||
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); | |||
menu->addChild(createBoolPtrMenuItem("Show tooltips", &settings::tooltips)); | |||
menu->addChild(createBoolPtrMenuItem("Show tooltips", "", &settings::tooltips)); | |||
ZoomSlider* zoomSlider = new ZoomSlider; | |||
zoomSlider->box.size.x = 250.0; | |||
@@ -409,7 +409,7 @@ struct ViewButton : MenuButton { | |||
menu->addChild(createSubmenuItem("Frame rate", string::f("%.0f Hz", frameRate), [=](ui::Menu* menu) { | |||
for (int i = 1; i <= 6; i++) { | |||
double frameRate = APP->window->getMonitorRefreshRate() / i; | |||
menu->addChild(createCheckMenuItem(string::f("%.0f Hz", frameRate), | |||
menu->addChild(createCheckMenuItem(string::f("%.0f Hz", frameRate), "", | |||
[=]() {return settings::frameSwapInterval == i;}, | |||
[=]() {settings::frameSwapInterval = i;} | |||
)); | |||
@@ -426,7 +426,7 @@ struct ViewButton : MenuButton { | |||
menu->addChild(new ui::MenuSeparator); | |||
menu->addChild(createBoolPtrMenuItem("Hide cursor while dragging", &settings::allowCursorLock)); | |||
menu->addChild(createBoolPtrMenuItem("Hide cursor while dragging", "", &settings::allowCursorLock)); | |||
static const std::vector<std::string> knobModeLabels = { | |||
"Linear", | |||
@@ -437,20 +437,20 @@ struct ViewButton : MenuButton { | |||
static const std::vector<int> knobModes = {0, 2, 3}; | |||
menu->addChild(createSubmenuItem("Knob mode", knobModeLabels[settings::knobMode], [=](ui::Menu* menu) { | |||
for (int knobMode : knobModes) { | |||
menu->addChild(createCheckMenuItem(knobModeLabels[knobMode], | |||
menu->addChild(createCheckMenuItem(knobModeLabels[knobMode], "", | |||
[=]() {return settings::knobMode == knobMode;}, | |||
[=]() {settings::knobMode = (settings::KnobMode) knobMode;} | |||
)); | |||
} | |||
})); | |||
menu->addChild(createBoolPtrMenuItem("Scroll wheel knob control", &settings::knobScroll)); | |||
menu->addChild(createBoolPtrMenuItem("Scroll wheel knob control", "", &settings::knobScroll)); | |||
KnobScrollSensitivitySlider* knobScrollSensitivitySlider = new KnobScrollSensitivitySlider; | |||
knobScrollSensitivitySlider->box.size.x = 250.0; | |||
menu->addChild(knobScrollSensitivitySlider); | |||
menu->addChild(createBoolPtrMenuItem("Lock module positions", &settings::lockModules)); | |||
menu->addChild(createBoolPtrMenuItem("Lock module positions", "", &settings::lockModules)); | |||
} | |||
}; | |||
@@ -561,12 +561,12 @@ struct AudioInterfaceWidget : ModuleWidget { | |||
menu->addChild(new MenuSeparator); | |||
menu->addChild(createCheckMenuItem("Master audio module", | |||
menu->addChild(createCheckMenuItem("Master audio module", "", | |||
[=]() {return module->isMaster();}, | |||
[=]() {module->setMaster();} | |||
)); | |||
menu->addChild(createBoolPtrMenuItem("DC blocker", &module->dcFilterEnabled)); | |||
menu->addChild(createBoolPtrMenuItem("DC blocker", "", &module->dcFilterEnabled)); | |||
} | |||
}; | |||
@@ -202,7 +202,7 @@ struct CV_GateWidget : ModuleWidget { | |||
menu->addChild(new MenuSeparator); | |||
menu->addChild(createBoolPtrMenuItem("Velocity mode", &module->velocityMode)); | |||
menu->addChild(createBoolPtrMenuItem("Velocity mode", "", &module->velocityMode)); | |||
menu->addChild(createMenuItem("Panic", "", | |||
[=]() {module->midiOutput.panic();} | |||
@@ -251,11 +251,11 @@ struct MIDI_CCWidget : ModuleWidget { | |||
menu->addChild(new MenuSeparator); | |||
menu->addChild(createBoolPtrMenuItem("Smooth CC", &module->smooth)); | |||
menu->addChild(createBoolPtrMenuItem("Smooth CC", "", &module->smooth)); | |||
menu->addChild(createBoolPtrMenuItem("MPE mode", &module->mpeMode)); | |||
menu->addChild(createBoolPtrMenuItem("MPE mode", "", &module->mpeMode)); | |||
menu->addChild(createBoolPtrMenuItem("CC 0-31 controls are 14-bit", &module->lsbMode)); | |||
menu->addChild(createBoolPtrMenuItem("CC 0-31 controls are 14-bit", "", &module->lsbMode)); | |||
} | |||
}; | |||
@@ -506,7 +506,7 @@ struct MIDI_CVWidget : ModuleWidget { | |||
menu->addChild(new MenuSeparator); | |||
menu->addChild(createBoolPtrMenuItem("Smooth pitch/mod wheel", &module->smooth)); | |||
menu->addChild(createBoolPtrMenuItem("Smooth pitch/mod wheel", "", &module->smooth)); | |||
static const std::vector<int> clockDivisions = {24 * 4, 24 * 2, 24, 24 / 2, 24 / 4, 24 / 8, 2, 1}; | |||
static const std::vector<std::string> clockDivisionLabels = {"Whole", "Half", "Quarter", "8th", "16th", "32nd", "12 PPQN", "24 PPQN"}; | |||
@@ -515,7 +515,7 @@ struct MIDI_CVWidget : ModuleWidget { | |||
Menu* createChildMenu() override { | |||
Menu* menu = new Menu; | |||
for (size_t i = 0; i < clockDivisions.size(); i++) { | |||
menu->addChild(createCheckMenuItem(clockDivisionLabels[i], | |||
menu->addChild(createCheckMenuItem(clockDivisionLabels[i], "", | |||
[=]() {return module->clockDivision == clockDivisions[i];}, | |||
[=]() {module->clockDivision = clockDivisions[i];} | |||
)); | |||
@@ -534,7 +534,7 @@ struct MIDI_CVWidget : ModuleWidget { | |||
Menu* createChildMenu() override { | |||
Menu* menu = new Menu; | |||
for (int c = 1; c <= 16; c++) { | |||
menu->addChild(createCheckMenuItem((c == 1) ? "Monophonic" : string::f("%d", c), | |||
menu->addChild(createCheckMenuItem((c == 1) ? "Monophonic" : string::f("%d", c), "", | |||
[=]() {return module->channels == c;}, | |||
[=]() {module->setChannels(c);} | |||
)); | |||
@@ -219,9 +219,9 @@ struct MIDI_GateWidget : ModuleWidget { | |||
menu->addChild(new MenuSeparator); | |||
menu->addChild(createBoolPtrMenuItem("Velocity mode", &module->velocityMode)); | |||
menu->addChild(createBoolPtrMenuItem("Velocity mode", "", &module->velocityMode)); | |||
menu->addChild(createBoolPtrMenuItem("MPE mode", &module->mpeMode)); | |||
menu->addChild(createBoolPtrMenuItem("MPE mode", "", &module->mpeMode)); | |||
menu->addChild(createMenuItem("Panic", "", | |||
[=]() {module->panic();} | |||
@@ -492,7 +492,7 @@ struct MIDI_MapWidget : ModuleWidget { | |||
menu->addChild(new MenuSeparator); | |||
menu->addChild(createBoolPtrMenuItem("Smooth CC", &module->smooth)); | |||
menu->addChild(createBoolPtrMenuItem("Smooth CC", "", &module->smooth)); | |||
} | |||
}; | |||