remove redundant computation for window_relative
This commit is contained in:
parent
ac340869a7
commit
93b33c433b
2 changed files with 10 additions and 4 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Raven {
|
||||
|
||||
Point Widget::window_relative() {
|
||||
Point Widget::compute_window_relative() {
|
||||
Point point = { 0, 0 };
|
||||
for (Widget* parent = m_parent; parent; parent = parent->parent()) {
|
||||
point.add(parent->rect().x(), parent->rect().y());
|
||||
|
@ -51,10 +51,13 @@ void Widget::move_to(double x, double y) {
|
|||
}
|
||||
|
||||
void Widget::do_layout() {
|
||||
if (m_layout)
|
||||
if (m_layout) {
|
||||
m_layout->run();
|
||||
}
|
||||
|
||||
m_window_relative = compute_window_relative();
|
||||
}
|
||||
|
||||
void Widget::set_layout(std::shared_ptr<Layout> layout) {
|
||||
m_layout = layout;
|
||||
m_layout->bind_to(this);
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
void set_rect(Box rect) { m_rect = rect; reflow(); }
|
||||
void set_rect(Box rect, bool is_pure) { m_rect = rect; if (!is_pure) { reflow(); } }
|
||||
|
||||
Point window_relative();
|
||||
Point &window_relative() { return m_window_relative; };
|
||||
|
||||
WidgetType type() { return m_type; }
|
||||
ControlWidgetType control_type() { return m_control_type; }
|
||||
|
@ -114,16 +114,19 @@ protected:
|
|||
virtual void on_paint() {}
|
||||
|
||||
void set_did_init(bool did_init) { m_did_init = did_init; }
|
||||
Point compute_window_relative();
|
||||
|
||||
void do_layout();
|
||||
|
||||
void repaint();
|
||||
void reflow();
|
||||
private:
|
||||
void do_layout();
|
||||
void handle_repaint_rect(RepaintRectEvent &event);
|
||||
void handle_relayout_subtree(RelayoutSubtreeEvent &event);
|
||||
void handle_mouse_move_event(MouseMoveEvent &event);
|
||||
void handle_mouse_button_event(MouseButtonEvent &event);
|
||||
|
||||
Point m_window_relative { 0, 0 };
|
||||
Box m_rect { 0, 0, 0, 0 };
|
||||
std::vector<std::shared_ptr<Widget>> m_children;
|
||||
Widget *m_parent { nullptr };
|
||||
|
|
Loading…
Reference in a new issue