Browse Source

Enable MenuOverlay darkening again. Use MenuOverlay subclass for

ModuleBrowser. Consume all keys/buttons in MenuOverlay.
tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
a93ebf8e28
3 changed files with 31 additions and 22 deletions
  1. +1
    -0
      include/ui/MenuOverlay.hpp
  2. +7
    -14
      src/app/ModuleBrowser.cpp
  3. +23
    -8
      src/ui/MenuOverlay.cpp

+ 1
- 0
include/ui/MenuOverlay.hpp View File

@@ -13,6 +13,7 @@ struct MenuOverlay : widget::OpaqueWidget {
void step() override;
void onButton(const event::Button& e) override;
void onHoverKey(const event::HoverKey& e) override;
void onAction(const event::Action& e) override;
};




+ 7
- 14
src/app/ModuleBrowser.cpp View File

@@ -5,6 +5,7 @@
#include <widget/OpaqueWidget.hpp>
#include <widget/TransparentWidget.hpp>
#include <widget/ZoomWidget.hpp>
#include <ui/MenuOverlay.hpp>
#include <ui/ScrollWidget.hpp>
#include <ui/SequentialLayout.hpp>
#include <ui/MarginLayout.hpp>
@@ -101,23 +102,15 @@ static ModuleWidget* chooseModel(plugin::Model* model) {
// Widgets


struct BrowserOverlay : widget::OpaqueWidget {
struct BrowserOverlay : ui::MenuOverlay {
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.
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 {
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;



+ 23
- 8
src/ui/MenuOverlay.cpp View File

@@ -7,40 +7,55 @@ namespace ui {

void MenuOverlay::draw(const DrawArgs& args) {
// 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);
}


void MenuOverlay::step() {
// Adopt parent's size
box.size = parent->box.size;
box = parent->box.zeroPos();

Widget::step();
}


void MenuOverlay::onButton(const event::Button& e) {
OpaqueWidget::onButton(e);
if (e.isConsumed() && e.getTarget() != this)
return;

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) {
OpaqueWidget::onHoverKey(e);
if (e.isConsumed())
return;

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();
}




Loading…
Cancel
Save