| @@ -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 { | struct State { | ||||
| widget::Widget *rootWidget = NULL; | widget::Widget *rootWidget = NULL; | ||||
| /** State widgets | /** State widgets | ||||
| @@ -32,6 +32,9 @@ struct Widget { | |||||
| virtual ~Widget(); | virtual ~Widget(); | ||||
| void setPos(math::Vec pos); | |||||
| void setSize(math::Vec size); | |||||
| virtual math::Rect getChildrenBoundingBox(); | virtual math::Rect getChildrenBoundingBox(); | ||||
| /** Returns `v` transformed into the coordinate system of `relative` */ | /** Returns `v` transformed into the coordinate system of `relative` */ | ||||
| virtual math::Vec getRelativeOffset(math::Vec v, Widget *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 onAction(const event::Action &e) {} | ||||
| virtual void onChange(const event::Change &e) {} | virtual void onChange(const event::Change &e) {} | ||||
| virtual void onZoom(const event::Zoom &e) {recurseEvent(&Widget::onZoom, 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) {} | |||||
| }; | }; | ||||
| @@ -27,7 +27,9 @@ static std::set<plugin::Model*> sFavoriteModels; | |||||
| struct BrowserOverlay : widget::OpaqueWidget { | struct BrowserOverlay : widget::OpaqueWidget { | ||||
| void step() override { | void step() override { | ||||
| box = parent->box.zeroPos(); | 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 { | void onButton(const event::Button &e) override { | ||||
| @@ -14,6 +14,18 @@ Widget::~Widget() { | |||||
| clearChildren(); | 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::Rect Widget::getChildrenBoundingBox() { | ||||
| math::Vec min = math::Vec(INFINITY, INFINITY); | math::Vec min = math::Vec(INFINITY, INFINITY); | ||||
| math::Vec max = math::Vec(-INFINITY, -INFINITY); | math::Vec max = math::Vec(-INFINITY, -INFINITY); | ||||