remove automatic event propagation

This commit is contained in:
hippoz 2022-06-11 20:42:21 +03:00
parent 69d8e0a689
commit 3a9b530a08
No known key found for this signature in database
GPG key ID: 7C52899193467641
3 changed files with 6 additions and 20 deletions

View file

@ -18,17 +18,12 @@ enum class EventType {
};
class Event {
private:
bool m_accepted { false };
public:
Event() {}
virtual EventType type() { return EventType::NoneEvent; }
virtual const char *name() { return "NoneEvent"; }
void accept() { m_accepted = true; }
bool accepted() { return m_accepted; }
virtual ~Event() = default;
};

View file

@ -100,8 +100,6 @@ void Widget::reflow() {
}
void Widget::handle_repaint_rect(RepaintRectEvent &event) {
event.accept(); // immediately accept the event - we will do our own propagation logic
auto painter = m_window->painter();
if (!m_did_init || !painter.can_paint())
return;
@ -163,13 +161,14 @@ void Widget::handle_repaint_rect(RepaintRectEvent &event) {
}
}
void Widget::handle_relayout_subtree() {
void Widget::handle_relayout_subtree(RelayoutSubtreeEvent &event) {
for (auto child : m_children) {
child->dispatch_event(event);
}
do_layout();
}
void Widget::handle_mouse_move_event(MouseMoveEvent &event) {
event.accept(); // we will do our own propagation logic
bool update_focus_to = true;
if (!m_rect.contains_point(event.point())) {
// we just became unfocused
@ -204,8 +203,6 @@ void Widget::handle_mouse_move_event(MouseMoveEvent &event) {
}
void Widget::handle_mouse_button_event(MouseButtonEvent &event) {
event.accept(); // we will do our own propagation logic
bool update_activation_to = event.was_left_button_pressed();
if (!m_rect.contains_point(event.point())) {
@ -259,7 +256,7 @@ void Widget::dispatch_event(Event &event) {
break;
}
case EventType::RelayoutSubtree: {
handle_relayout_subtree();
handle_relayout_subtree(reinterpret_cast<RelayoutSubtreeEvent&>(event));
break;
}
/* these events aren't handled here, as they won't be dispatched to us from other places */
@ -269,12 +266,6 @@ void Widget::dispatch_event(Event &event) {
break;
}
}
if (!event.accepted()) {
for (auto& child : m_children) {
child->dispatch_event(event);
}
}
}
}

View file

@ -120,7 +120,7 @@ protected:
private:
void do_layout();
void handle_repaint_rect(RepaintRectEvent &event);
void handle_relayout_subtree();
void handle_relayout_subtree(RelayoutSubtreeEvent &event);
void handle_mouse_move_event(MouseMoveEvent &event);
void handle_mouse_button_event(MouseButtonEvent &event);