Browse Source

Add OverlayWidget. Make some classes subclass OverlayWidget instead of OpaqueWidget.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
3eb0426315
4 changed files with 39 additions and 7 deletions
  1. +2
    -2
      include/ui/MenuOverlay.hpp
  2. +25
    -0
      include/widget/OverlayWidget.hpp
  3. +8
    -2
      include/widget/event.hpp
  4. +4
    -3
      src/app/ModuleBrowser.cpp

+ 2
- 2
include/ui/MenuOverlay.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "widget/OpaqueWidget.hpp"
#include "widget/OverlayWidget.hpp"
#include "ui/common.hpp"


@@ -8,7 +8,7 @@ namespace ui {


/** Deletes itself from parent when clicked */
struct MenuOverlay : widget::OpaqueWidget {
struct MenuOverlay : widget::OverlayWidget {
void step() override;
void onButton(const widget::ButtonEvent &e) override;
void onHoverKey(const widget::HoverKeyEvent &e) override;


+ 25
- 0
include/widget/OverlayWidget.hpp View File

@@ -0,0 +1,25 @@
#pragma once
#include "widget/OpaqueWidget.hpp"


namespace rack {
namespace widget {


/** Like OpaqueWidget but consumes even more events. */
struct OverlayWidget : OpaqueWidget {
void onHoverScroll(const HoverScrollEvent &e) override {
Widget::onHoverScroll(e);
if (!e.getConsumed())
e.consume(this);
}
void onPathDrop(const PathDropEvent &e) override {
Widget::onPathDrop(e);
if (!e.getConsumed())
e.consume(this);
}
};


} // namespace widget
} // namespace rack

+ 8
- 2
include/widget/event.hpp View File

@@ -11,6 +11,7 @@ namespace widget {
struct Widget;


/** A per-event state shared and writable by all widgets that recursively handle an event. */
struct EventContext {
/** The Widget that consumes the event.
This stops propagation of the event if applicable.
@@ -19,7 +20,7 @@ struct EventContext {
};


/** Base event class */
/** Base class for all events. */
struct Event {
EventContext *context = NULL;

@@ -33,12 +34,14 @@ struct Event {
};


/** An Event prototype with a vector position. */
struct PositionEvent {
/** The pixel coordinate where the event occurred, relative to the Widget it is called on. */
math::Vec pos;
};


/** An Event prototype with a GLFW key. */
struct KeyEvent {
/** GLFW_KEY_* */
int key;
@@ -50,14 +53,17 @@ struct KeyEvent {
int mods;
};

// Events

/** An Event prototype with a Unicode character. */
struct TextEvent {
/** Unicode code point of the character */
int codepoint;
};


// Concrete events


/** Occurs every frame when the mouse is hovering over a Widget.
Recurses until consumed.
If `target` is set, other events may occur on that Widget.


+ 4
- 3
src/app/ModuleBrowser.cpp View File

@@ -1,5 +1,6 @@
#include "app/ModuleBrowser.hpp"
#include "widget/OpaqueWidget.hpp"
#include "widget/OverlayWidget.hpp"
#include "widget/TransparentWidget.hpp"
#include "widget/ZoomWidget.hpp"
#include "ui/ScrollWidget.hpp"
@@ -53,16 +54,16 @@ static float modelScore(plugin::Model *model, const std::string &search) {
}


struct BrowserOverlay : widget::OpaqueWidget {
struct BrowserOverlay : widget::OverlayWidget {
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();
OverlayWidget::step();
}

void onButton(const widget::ButtonEvent &e) override {
OpaqueWidget::onButton(e);
OverlayWidget::onButton(e);
if (e.getConsumed() != this)
return;



Loading…
Cancel
Save