ModuleBrowser. Consume all keys/buttons in MenuOverlay.tags/v2.0.0
@@ -13,6 +13,7 @@ struct MenuOverlay : widget::OpaqueWidget { | |||||
void step() override; | void step() override; | ||||
void onButton(const event::Button& e) override; | void onButton(const event::Button& e) override; | ||||
void onHoverKey(const event::HoverKey& e) override; | void onHoverKey(const event::HoverKey& e) override; | ||||
void onAction(const event::Action& e) override; | |||||
}; | }; | ||||
@@ -5,6 +5,7 @@ | |||||
#include <widget/OpaqueWidget.hpp> | #include <widget/OpaqueWidget.hpp> | ||||
#include <widget/TransparentWidget.hpp> | #include <widget/TransparentWidget.hpp> | ||||
#include <widget/ZoomWidget.hpp> | #include <widget/ZoomWidget.hpp> | ||||
#include <ui/MenuOverlay.hpp> | |||||
#include <ui/ScrollWidget.hpp> | #include <ui/ScrollWidget.hpp> | ||||
#include <ui/SequentialLayout.hpp> | #include <ui/SequentialLayout.hpp> | ||||
#include <ui/MarginLayout.hpp> | #include <ui/MarginLayout.hpp> | ||||
@@ -101,23 +102,15 @@ static ModuleWidget* chooseModel(plugin::Model* model) { | |||||
// Widgets | // Widgets | ||||
struct BrowserOverlay : widget::OpaqueWidget { | |||||
struct BrowserOverlay : ui::MenuOverlay { | |||||
void step() override { | void step() override { | ||||
box = parent->box.zeroPos(); | |||||
// Only step if visible, since there are potentially thousands of descendants that don't need to be stepped. | // Only step if visible, since there are potentially thousands of descendants that don't need to be stepped. | ||||
if (visible) | |||||
OpaqueWidget::step(); | |||||
if (isVisible()) | |||||
MenuOverlay::step(); | |||||
} | } | ||||
void onButton(const event::Button& e) override { | |||||
OpaqueWidget::onButton(e); | |||||
if (e.getTarget() != this) | |||||
return; | |||||
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) { | |||||
hide(); | |||||
e.consume(this); | |||||
} | |||||
void onAction(const event::Action& e) override { | |||||
hide(); | |||||
} | } | ||||
}; | }; | ||||
@@ -447,7 +440,7 @@ struct ModuleBrowser : widget::OpaqueWidget { | |||||
} | } | ||||
void step() override { | void step() override { | ||||
box = parent->box.zeroPos().grow(math::Vec(-70, -70)); | |||||
box = parent->box.zeroPos().grow(math::Vec(-40, -40)); | |||||
sidebar->box.size.y = box.size.y; | sidebar->box.size.y = box.size.y; | ||||
@@ -7,40 +7,55 @@ namespace ui { | |||||
void MenuOverlay::draw(const DrawArgs& args) { | void MenuOverlay::draw(const DrawArgs& args) { | ||||
// Possible translucent background | // Possible translucent background | ||||
// nvgRect(args.vg, 0, 0, VEC_ARGS(box.size)); | |||||
// nvgFillColor(args.vg, nvgRGBAf(0, 0, 0, 0.25)); | |||||
// nvgFill(args.vg); | |||||
nvgRect(args.vg, 0, 0, VEC_ARGS(box.size)); | |||||
nvgFillColor(args.vg, nvgRGBAf(0, 0, 0, 0.333)); | |||||
nvgFill(args.vg); | |||||
OpaqueWidget::draw(args); | OpaqueWidget::draw(args); | ||||
} | } | ||||
void MenuOverlay::step() { | void MenuOverlay::step() { | ||||
// Adopt parent's size | // Adopt parent's size | ||||
box.size = parent->box.size; | |||||
box = parent->box.zeroPos(); | |||||
Widget::step(); | Widget::step(); | ||||
} | } | ||||
void MenuOverlay::onButton(const event::Button& e) { | void MenuOverlay::onButton(const event::Button& e) { | ||||
OpaqueWidget::onButton(e); | OpaqueWidget::onButton(e); | ||||
if (e.isConsumed() && e.getTarget() != this) | if (e.isConsumed() && e.getTarget() != this) | ||||
return; | return; | ||||
if (e.action == GLFW_PRESS) { | if (e.action == GLFW_PRESS) { | ||||
requestDelete(); | |||||
e.consume(this); | |||||
event::Action eAction; | |||||
onAction(eAction); | |||||
} | } | ||||
// Consume all buttons. | |||||
e.consume(this); | |||||
} | } | ||||
void MenuOverlay::onHoverKey(const event::HoverKey& e) { | void MenuOverlay::onHoverKey(const event::HoverKey& e) { | ||||
OpaqueWidget::onHoverKey(e); | OpaqueWidget::onHoverKey(e); | ||||
if (e.isConsumed()) | if (e.isConsumed()) | ||||
return; | return; | ||||
if (e.action == GLFW_PRESS && e.key == GLFW_KEY_ESCAPE) { | if (e.action == GLFW_PRESS && e.key == GLFW_KEY_ESCAPE) { | ||||
requestDelete(); | |||||
e.consume(this); | |||||
event::Action eAction; | |||||
onAction(eAction); | |||||
} | } | ||||
// Consume all keys. | |||||
// Unfortunately this prevents MIDI computer keyboard from playing while a menu is open, but that might be a good thing for safety. | |||||
e.consume(this); | |||||
} | |||||
void MenuOverlay::onAction(const event::Action& e) { | |||||
requestDelete(); | |||||
} | } | ||||