From 91f72a1ada74edd289070ac41beaa447b7062978 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 9 Feb 2019 19:59:06 -0500 Subject: [PATCH] Add Reposition and Resize events. --- include/event.hpp | 12 ++++++++++++ include/widget/Widget.hpp | 5 +++++ src/app/ModuleBrowser.cpp | 4 +++- src/widget/Widget.cpp | 12 ++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/event.hpp b/include/event.hpp index c126073e..e518f4e6 100644 --- a/include/event.hpp +++ b/include/event.hpp @@ -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 diff --git a/include/widget/Widget.hpp b/include/widget/Widget.hpp index 91bac5de..33fa10e5 100644 --- a/include/widget/Widget.hpp +++ b/include/widget/Widget.hpp @@ -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) {} }; diff --git a/src/app/ModuleBrowser.cpp b/src/app/ModuleBrowser.cpp index ccc782b8..d8122f6f 100644 --- a/src/app/ModuleBrowser.cpp +++ b/src/app/ModuleBrowser.cpp @@ -27,7 +27,9 @@ static std::set 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 { diff --git a/src/widget/Widget.cpp b/src/widget/Widget.cpp index da565ca3..1a75df8b 100644 --- a/src/widget/Widget.cpp +++ b/src/widget/Widget.cpp @@ -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);