Browse Source

Add Reposition and Resize events.

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
91f72a1ada
4 changed files with 32 additions and 1 deletions
  1. +12
    -0
      include/event.hpp
  2. +5
    -0
      include/widget/Widget.hpp
  3. +3
    -1
      src/app/ModuleBrowser.cpp
  4. +12
    -0
      src/widget/Widget.cpp

+ 12
- 0
include/event.hpp View File

@@ -241,6 +241,18 @@ struct Zoom : Event {
};


/** Occurs when Widget::setPos() is called.
*/
struct Reposition : Event {
};


/** Occurs when Widget::setSize() is called.
*/
struct Resize : Event {
};


struct State {
widget::Widget *rootWidget = NULL;
/** State widgets


+ 5
- 0
include/widget/Widget.hpp View File

@@ -32,6 +32,9 @@ struct Widget {

virtual ~Widget();

void setPos(math::Vec pos);
void setSize(math::Vec size);

virtual math::Rect getChildrenBoundingBox();
/** Returns `v` transformed into the coordinate system of `relative` */
virtual math::Vec getRelativeOffset(math::Vec v, Widget *relative);
@@ -143,6 +146,8 @@ struct Widget {
virtual void onAction(const event::Action &e) {}
virtual void onChange(const event::Change &e) {}
virtual void onZoom(const event::Zoom &e) {recurseEvent(&Widget::onZoom, e);}
virtual void onReposition(const event::Reposition &e) {}
virtual void onResize(const event::Resize &e) {}
};




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

@@ -27,7 +27,9 @@ static std::set<plugin::Model*> sFavoriteModels;
struct BrowserOverlay : widget::OpaqueWidget {
void step() override {
box = parent->box.zeroPos();
widget::OpaqueWidget::step();
// Only step if visible, since there are potentially thousands of descendants that don't need to be stepped.
if (visible)
widget::OpaqueWidget::step();
}

void onButton(const event::Button &e) override {


+ 12
- 0
src/widget/Widget.cpp View File

@@ -14,6 +14,18 @@ Widget::~Widget() {
clearChildren();
}

void Widget::setPos(math::Vec pos) {
box.pos = pos;
event::Reposition eReposition;
onReposition(eReposition);
}

void Widget::setSize(math::Vec size) {
box.size = size;
event::Resize eResize;
onResize(eResize);
}

math::Rect Widget::getChildrenBoundingBox() {
math::Vec min = math::Vec(INFINITY, INFINITY);
math::Vec max = math::Vec(-INFINITY, -INFINITY);


Loading…
Cancel
Save