remove automatic event propagation
This commit is contained in:
parent
69d8e0a689
commit
3a9b530a08
3 changed files with 6 additions and 20 deletions
|
@ -18,17 +18,12 @@ enum class EventType {
|
||||||
};
|
};
|
||||||
|
|
||||||
class Event {
|
class Event {
|
||||||
private:
|
|
||||||
bool m_accepted { false };
|
|
||||||
public:
|
public:
|
||||||
Event() {}
|
Event() {}
|
||||||
|
|
||||||
virtual EventType type() { return EventType::NoneEvent; }
|
virtual EventType type() { return EventType::NoneEvent; }
|
||||||
virtual const char *name() { return "NoneEvent"; }
|
virtual const char *name() { return "NoneEvent"; }
|
||||||
|
|
||||||
void accept() { m_accepted = true; }
|
|
||||||
bool accepted() { return m_accepted; }
|
|
||||||
|
|
||||||
virtual ~Event() = default;
|
virtual ~Event() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -100,8 +100,6 @@ void Widget::reflow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::handle_repaint_rect(RepaintRectEvent &event) {
|
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();
|
auto painter = m_window->painter();
|
||||||
if (!m_did_init || !painter.can_paint())
|
if (!m_did_init || !painter.can_paint())
|
||||||
return;
|
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();
|
do_layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::handle_mouse_move_event(MouseMoveEvent &event) {
|
void Widget::handle_mouse_move_event(MouseMoveEvent &event) {
|
||||||
event.accept(); // we will do our own propagation logic
|
|
||||||
|
|
||||||
bool update_focus_to = true;
|
bool update_focus_to = true;
|
||||||
if (!m_rect.contains_point(event.point())) {
|
if (!m_rect.contains_point(event.point())) {
|
||||||
// we just became unfocused
|
// we just became unfocused
|
||||||
|
@ -204,8 +203,6 @@ void Widget::handle_mouse_move_event(MouseMoveEvent &event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::handle_mouse_button_event(MouseButtonEvent &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();
|
bool update_activation_to = event.was_left_button_pressed();
|
||||||
|
|
||||||
if (!m_rect.contains_point(event.point())) {
|
if (!m_rect.contains_point(event.point())) {
|
||||||
|
@ -259,7 +256,7 @@ void Widget::dispatch_event(Event &event) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EventType::RelayoutSubtree: {
|
case EventType::RelayoutSubtree: {
|
||||||
handle_relayout_subtree();
|
handle_relayout_subtree(reinterpret_cast<RelayoutSubtreeEvent&>(event));
|
||||||
break;
|
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 */
|
||||||
|
@ -269,12 +266,6 @@ void Widget::dispatch_event(Event &event) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event.accepted()) {
|
|
||||||
for (auto& child : m_children) {
|
|
||||||
child->dispatch_event(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
void do_layout();
|
void do_layout();
|
||||||
void handle_repaint_rect(RepaintRectEvent &event);
|
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_move_event(MouseMoveEvent &event);
|
||||||
void handle_mouse_button_event(MouseButtonEvent &event);
|
void handle_mouse_button_event(MouseButtonEvent &event);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue