Subscribe to the window events that reach an element, without replacing any of its own callbacks.
The on_* callbacks keep one callback per element and slot, so a second registration replaces the first. A subscription is added beside them: the element's own callback runs first, then every matching subscriber in the order they subscribed. unbind(id) removes the callbacks and every subscriber of the element together.
The filter is the one the window's event source uses, and an unset field matches anything. Events reach an element as follows:
- MOUSE_BUTTON_PRESSED and MOUSE_BUTTON_RELEASED when the pointer is over it, with the button.
- MOUSE_MOTION while the pointer is over it. A filter with no button receives this hover motion. A filter with a button receives the drag of that button, which continues outside the element until the release and starts on press, as on_drag does.
- MOUSE_ENTERED and MOUSE_EXITED when the pointer enters or leaves it.
- MOUSE_SCROLLED while the pointer is over it.
- KEY_PRESSED, KEY_RELEASED and KEY_REPEAT of a key, while it has focus. A filter for these must name the key.
- TEXT_INPUT while it has focus.
- WINDOW_FOCUS_GAINED and WINDOW_FOCUS_LOST when it gains or loses focus.
- Parameters
-
| filter | What to receive. |
| fn | Called for each matching event. |
- Returns
- False, subscribing nothing, when receives() refuses the filter or fn is empty.
Definition at line 163 of file Context.cpp.
164{
166 return false;
167
168 if (filter.key_code) {
169 const IO::Keys key = *filter.key_code;
170 const int key_code = static_cast<int>(key);
173 std::make_shared<Vruta::Event>(
174 subscribed_key_events(
m_window, key,
176 m_name +
"_subscribed_key_" + std::to_string(key_code));
177 }
178 }
179
180 m_callbacks[id].subscribers.push_back({ .filter = filter, .fn = std::move(fn) });
181 return true;
182}
std::unordered_set< int > m_subscribed_keys
void handle_subscribed_key(IO::Keys key, const Core::WindowEvent &event)
Vruta::EventManager & m_event_manager
std::shared_ptr< Core::Window > m_window
static bool receives(const Vruta::WindowEventFilter &filter) noexcept
Whether an element can receive what a filter asks for.
std::unordered_map< uint32_t, ElementCallbacks > m_callbacks
References handle_subscribed_key(), MayaFlux::Vruta::WindowEventFilter::key_code, m_callbacks, m_event_manager, m_name, m_subscribed_keys, m_window, and receives().
Referenced by operator=(), and MayaFlux::Portal::Forma::Detail::DocumentWalk< Source, Access >::wire().