add relayout event
This commit is contained in:
parent
441d4091cb
commit
eedf38f9a8
6 changed files with 59 additions and 9 deletions
|
@ -13,7 +13,8 @@ enum class EventType {
|
||||||
MouseMove,
|
MouseMove,
|
||||||
WidgetRepaintRequested,
|
WidgetRepaintRequested,
|
||||||
FocusUpdate,
|
FocusUpdate,
|
||||||
ActivationUpdate
|
ActivationUpdate,
|
||||||
|
WidgetRelayoutRequestedEvent
|
||||||
};
|
};
|
||||||
|
|
||||||
class Event {
|
class Event {
|
||||||
|
@ -78,6 +79,14 @@ public:
|
||||||
void set_should_do_group(bool should_do_group) { m_should_do_group = should_do_group; }
|
void set_should_do_group(bool should_do_group) { m_should_do_group = should_do_group; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WidgetRelayoutRequestedEvent : public Event {
|
||||||
|
public:
|
||||||
|
WidgetRelayoutRequestedEvent() {}
|
||||||
|
|
||||||
|
EventType get_type() { return EventType::WidgetRelayoutRequestedEvent; }
|
||||||
|
const char *get_name() { return "WidgetRelayoutRequestedEvent"; }
|
||||||
|
};
|
||||||
|
|
||||||
class FocusUpdateEvent : public Event {
|
class FocusUpdateEvent : public Event {
|
||||||
private:
|
private:
|
||||||
bool m_focus_status;
|
bool m_focus_status;
|
||||||
|
|
|
@ -24,7 +24,7 @@ void Layout::run() {
|
||||||
row_largest_height = c->get_current_geometry().get_height();
|
row_largest_height = c->get_current_geometry().get_height();
|
||||||
}
|
}
|
||||||
auto new_geometry = Box{ point.get_x(), point.get_y(), c->get_current_geometry().get_width(), c->get_current_geometry().get_height() };
|
auto new_geometry = Box{ point.get_x(), point.get_y(), c->get_current_geometry().get_width(), c->get_current_geometry().get_height() };
|
||||||
c->set_current_geometry(std::move(new_geometry));
|
c->set_current_geometry(std::move(new_geometry), true);
|
||||||
point.add(c->get_current_geometry().get_width() + m_margin, 0);
|
point.add(c->get_current_geometry().get_width() + m_margin, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,10 @@
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
void Widget::do_layout() {
|
void Widget::do_layout() {
|
||||||
if (m_layout)
|
if (m_layout) {
|
||||||
m_layout->run();
|
m_layout->run();
|
||||||
|
wants_repaint(); // TODO: should relayout really repaint as well?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::set_layout(Layout *layout) {
|
void Widget::set_layout(Layout *layout) {
|
||||||
|
@ -57,14 +59,35 @@ void Widget::do_generic_paint() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::wants_repaint() {
|
void Widget::wants_repaint() {
|
||||||
|
if (!m_window)
|
||||||
|
return;
|
||||||
|
|
||||||
// TODO: not necessary?
|
// TODO: not necessary?
|
||||||
m_window->widget_repaint(this);
|
m_window->widget_repaint(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::wants_relayout() {
|
||||||
|
if (!m_window)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// TODO: not necessary?
|
||||||
|
m_window->widget_relayout(this);
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::wants_full_repaint() {
|
void Widget::wants_full_repaint() {
|
||||||
|
if (!m_window)
|
||||||
|
return;
|
||||||
|
|
||||||
m_window->dispatch_full_repaint();
|
m_window->dispatch_full_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::wants_full_relayout() {
|
||||||
|
if (!m_window)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_window->dispatch_full_relayout();
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::handle_repaint(WidgetRepaintRequestedEvent &event) {
|
void Widget::handle_repaint(WidgetRepaintRequestedEvent &event) {
|
||||||
// immediately accept the event - we will do our own propagation logic
|
// immediately accept the event - we will do our own propagation logic
|
||||||
event.accept();
|
event.accept();
|
||||||
|
@ -160,6 +183,10 @@ void Widget::dispatch_event(Event &event) {
|
||||||
handle_repaint(reinterpret_cast<WidgetRepaintRequestedEvent&>(event));
|
handle_repaint(reinterpret_cast<WidgetRepaintRequestedEvent&>(event));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case EventType::WidgetRelayoutRequestedEvent: {
|
||||||
|
do_layout();
|
||||||
|
break;
|
||||||
|
}
|
||||||
/* these events aren't handled here, as they won't be dispatched to us from other places */
|
/* these events aren't handled here, as they won't be dispatched to us from other places */
|
||||||
case EventType::FocusUpdate:
|
case EventType::FocusUpdate:
|
||||||
case EventType::ActivationUpdate:
|
case EventType::ActivationUpdate:
|
||||||
|
|
|
@ -55,7 +55,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Box &get_current_geometry() { return m_current_geometry; }
|
Box &get_current_geometry() { return m_current_geometry; }
|
||||||
void set_current_geometry(Box current_geometry) { m_current_geometry = current_geometry; wants_repaint(); }
|
void set_current_geometry(Box current_geometry) { m_current_geometry = current_geometry; wants_full_relayout(); }
|
||||||
|
void set_current_geometry(Box current_geometry, bool is_pure) { m_current_geometry = current_geometry; if (!is_pure) { wants_full_relayout(); } }
|
||||||
|
|
||||||
std::vector<Widget*> &get_children() { return m_children; }
|
std::vector<Widget*> &get_children() { return m_children; }
|
||||||
bool add_child(Widget *child);
|
bool add_child(Widget *child);
|
||||||
|
@ -68,7 +69,7 @@ public:
|
||||||
void set_window(Window *window);
|
void set_window(Window *window);
|
||||||
|
|
||||||
std::shared_ptr<TopLevelStyles> get_styles() { return m_styles; }
|
std::shared_ptr<TopLevelStyles> get_styles() { return m_styles; }
|
||||||
void set_styles(std::shared_ptr<TopLevelStyles> styles) { m_styles = styles; wants_repaint(); }
|
void set_styles(std::shared_ptr<TopLevelStyles> styles) { m_styles = styles; wants_relayout(); }
|
||||||
|
|
||||||
void set_did_init(bool did_init) { m_did_init = did_init; }
|
void set_did_init(bool did_init) { m_did_init = did_init; }
|
||||||
bool get_did_init() { return m_did_init; }
|
bool get_did_init() { return m_did_init; }
|
||||||
|
@ -91,8 +92,7 @@ public:
|
||||||
|
|
||||||
void dispatch_event(Event &event);
|
void dispatch_event(Event &event);
|
||||||
void wants_repaint();
|
void wants_repaint();
|
||||||
void wants_full_repaint();
|
void wants_relayout();
|
||||||
void do_layout();
|
|
||||||
|
|
||||||
virtual ~Widget() {};
|
virtual ~Widget() {};
|
||||||
protected:
|
protected:
|
||||||
|
@ -105,6 +105,9 @@ protected:
|
||||||
virtual void on_activation_update(ActivationUpdateEvent &event) {}
|
virtual void on_activation_update(ActivationUpdateEvent &event) {}
|
||||||
virtual void on_paint() {}
|
virtual void on_paint() {}
|
||||||
private:
|
private:
|
||||||
|
void wants_full_repaint();
|
||||||
|
void wants_full_relayout();
|
||||||
|
void do_layout();
|
||||||
void handle_repaint(WidgetRepaintRequestedEvent& event);
|
void handle_repaint(WidgetRepaintRequestedEvent& event);
|
||||||
void do_generic_paint();
|
void do_generic_paint();
|
||||||
void handle_mouse_move_event(MouseMoveEvent &event);
|
void handle_mouse_move_event(MouseMoveEvent &event);
|
||||||
|
|
|
@ -65,6 +65,11 @@ void Window::widget_repaint(Widget *target) {
|
||||||
target->dispatch_event(event);
|
target->dispatch_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::widget_relayout(Widget *target) {
|
||||||
|
auto event = WidgetRelayoutRequestedEvent();
|
||||||
|
target->dispatch_event(event);
|
||||||
|
}
|
||||||
|
|
||||||
bool Window::dispatch_to_main_widget(Event &event) {
|
bool Window::dispatch_to_main_widget(Event &event) {
|
||||||
if (!m_main_widget)
|
if (!m_main_widget)
|
||||||
return false;
|
return false;
|
||||||
|
@ -78,6 +83,11 @@ bool Window::dispatch_full_repaint() {
|
||||||
return dispatch_to_main_widget(event);
|
return dispatch_to_main_widget(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Window::dispatch_full_relayout() {
|
||||||
|
auto event = WidgetRelayoutRequestedEvent();
|
||||||
|
return dispatch_to_main_widget(event);
|
||||||
|
}
|
||||||
|
|
||||||
void Window::run(bool block) {
|
void Window::run(bool block) {
|
||||||
XEvent e;
|
XEvent e;
|
||||||
|
|
||||||
|
|
|
@ -34,13 +34,14 @@ public:
|
||||||
Widget *get_main_widget() { return m_main_widget; }
|
Widget *get_main_widget() { return m_main_widget; }
|
||||||
void set_main_widget(Widget *main_widget);
|
void set_main_widget(Widget *main_widget);
|
||||||
|
|
||||||
void widget_repaint(Widget *target);
|
|
||||||
|
|
||||||
std::shared_ptr<TopLevelStyles> get_top_level_styles() { return m_top_level_styles; }
|
std::shared_ptr<TopLevelStyles> get_top_level_styles() { return m_top_level_styles; }
|
||||||
|
|
||||||
|
void widget_repaint(Widget *target);
|
||||||
|
void widget_relayout(Widget *target);
|
||||||
|
|
||||||
bool dispatch_repaint_on_box(Box box);
|
bool dispatch_repaint_on_box(Box box);
|
||||||
bool dispatch_full_repaint();
|
bool dispatch_full_repaint();
|
||||||
|
bool dispatch_full_relayout();
|
||||||
bool dispatch_to_main_widget(Event &event);
|
bool dispatch_to_main_widget(Event &event);
|
||||||
|
|
||||||
Box &get_current_geometry() { return m_current_geometry; }
|
Box &get_current_geometry() { return m_current_geometry; }
|
||||||
|
|
Loading…
Reference in a new issue