Magnum::Ui::EventLayer class new in Git master

Event handling layer.

Provides signal/slot-like functionality, connecting events happening on nodes with aribtrary functions handling them.

Base classes

class AbstractLayer new in Git master
Base for data layers.

Constructors, destructors, conversion operators

EventLayer(LayerHandle handle) explicit
Constructor.
EventLayer(const EventLayer&) deleted
Copying is not allowed.
EventLayer(EventLayer&&) noexcept
Move constructor.
~EventLayer() override
Destructor.

Public functions

auto operator=(const EventLayer&) -> EventLayer& deleted
Copying is not allowed.
auto operator=(EventLayer&&) -> EventLayer& noexcept
Move assignment.
auto usedScopedConnectionCount() const -> UnsignedInt
Count of currently active EventConnection instances.
auto usedAllocatedConnectionCount() const -> UnsignedInt
Count of allocated connections.
auto onPress(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a finger / pen tap or left mouse press.
auto onPress(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot) -> DataHandle
auto onPressScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a finger / pen tap or left mouse press.
auto onPressScoped(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot) -> EventConnection
auto onRelease(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a finger / pen tap or left mouse release.
auto onRelease(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot) -> DataHandle
auto onReleaseScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a finger / pen tap or left mouse release.
auto onReleaseScoped(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot) -> EventConnection
auto onTapOrClick(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a finger / pen tap or left mouse click.
auto onTapOrClick(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot) -> DataHandle
auto onTapOrClickScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a finger / pen tap or left mouse click.
auto onTapOrClickScoped(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot) -> EventConnection
auto onMiddleClick(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a middle mouse click.
auto onMiddleClick(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot) -> DataHandle
auto onMiddleClickScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a middle mouse click.
auto onMiddleClickScoped(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot) -> EventConnection
auto onRightClick(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a right mouse click.
auto onRightClick(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot) -> DataHandle
auto onRightClickScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a right mouse click.
auto onRightClickScoped(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot) -> EventConnection
auto onDrag(NodeHandle node, Containers::Function<void(const Vector2&relativePosition)>&& slot) -> DataHandle
Connect to a drag.
auto onDrag(NodeHandle node, Containers::Function<void(const Vector2&position, const Vector2&relativePosition)>&& slot) -> DataHandle
auto onDragScoped(NodeHandle node, Containers::Function<void(const Vector2&relativePosition)>&& slot) -> EventConnection
Scoped connection to a drag.
auto onDragScoped(NodeHandle node, Containers::Function<void(const Vector2&position, const Vector2&relativePosition)>&& slot) -> EventConnection
auto onPinch(NodeHandle node, Containers::Function<void(const Vector2&position, const Vector2&relativeTranslation, const Complex&relativeRotation, Float relativeScaling)>&& slot) -> DataHandle
Connect to a two-finger pinch, zoom or pan gesture.
auto onPinchScoped(NodeHandle node, Containers::Function<void(const Vector2&position, const Vector2&relativeTranslation, const Complex&relativeRotation, Float relativeScaling)>&& slot) -> EventConnection
Scoped connection to a two-finger pinch, zoom or pan gesture.
auto onEnter(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a pointer enter.
auto onEnterScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a pointer enter.
auto onLeave(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a pointer leave.
auto onLeaveScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a pointer leave.
auto onFocus(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a focus.
auto onFocusScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a focus.
auto onBlur(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a blur.
auto onBlurScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a pointer leave.
void remove(DataHandle handle)
Remove a connection.
void remove(LayerDataHandle handle)
Remove a connection assuming it belongs to this layer.

Function documentation

Magnum::Ui::EventLayer::EventLayer(LayerHandle handle) explicit

Constructor.

Parameters
handle Layer handle returned from AbstractUserInterface::createLayer()

Magnum::Ui::EventLayer::EventLayer(EventLayer&&) noexcept

Move constructor.

Performs a destructive move, i.e. the original object isn't usable afterwards anymore.

Magnum::Ui::EventLayer::~EventLayer() override

Destructor.

Expects that usedScopedConnectionCount() is 0.

UnsignedInt Magnum::Ui::EventLayer::usedScopedConnectionCount() const

Count of currently active EventConnection instances.

Always at most usedCount(). The layer is only allowed to be destroyed after all scoped connections are removed, as the EventConnection destructors would then access a dangling layer pointer.

UnsignedInt Magnum::Ui::EventLayer::usedAllocatedConnectionCount() const

Count of allocated connections.

Always at most usedCount(). Counts all connections that capture non-trivially-destructible state or state that's too large to be stored in-place. The operation is done with a $ \mathcal{O}(n) $ complexity where $ n $ is capacity().

DataHandle Magnum::Ui::EventLayer::onPress(NodeHandle node, Containers::Function<void()>&& slot)

Connect to a finger / pen tap or left mouse press.

The slot, optionally receiving a node-relative position of the press, is called when a Pointer::MouseLeft, primary Pointer::Finger or Pointer::Pen press happens on the node. Expects that the slot is not nullptr.

Use onTapOrClick() for a combined press and release. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onPressScoped() for a scoped alternative. PointerEvent::isPrimary()

DataHandle Magnum::Ui::EventLayer::onPress(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

EventConnection Magnum::Ui::EventLayer::onPressScoped(NodeHandle node, Containers::Function<void()>&& slot)

Scoped connection to a finger / pen tap or left mouse press.

Compared to onPress() the connection is removed automatically when the returned EventConnection gets destroyed.

EventConnection Magnum::Ui::EventLayer::onPressScoped(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

DataHandle Magnum::Ui::EventLayer::onRelease(NodeHandle node, Containers::Function<void()>&& slot)

Connect to a finger / pen tap or left mouse release.

The slot, optionally receiving a node-relative position of the release, is called when a Pointer::MouseLeft, primary Pointer::Finger or Pointer::Pen release happens on the node. Expects that the slot is not nullptr.

Use onTapOrClick() for a combined press and release. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onReleaseScoped() for a scoped alternative. PointerEvent::isPrimary()

DataHandle Magnum::Ui::EventLayer::onRelease(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

EventConnection Magnum::Ui::EventLayer::onReleaseScoped(NodeHandle node, Containers::Function<void()>&& slot)

Scoped connection to a finger / pen tap or left mouse release.

Compared to onRelease() the connection is removed automatically when the returned EventConnection gets destroyed.

EventConnection Magnum::Ui::EventLayer::onReleaseScoped(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

DataHandle Magnum::Ui::EventLayer::onTapOrClick(NodeHandle node, Containers::Function<void()>&& slot)

Connect to a finger / pen tap or left mouse click.

The slot, optionally receiving a node-relative position of the tap or click, is called when a Pointer::MouseLeft, primary Pointer::Finger or Pointer::Pen release happens on the node after a previous primary pointer press. If event capture is disabled by any event handler on given node, the slot is called only if the pointer didn't leave the node area between a press and a release. Expects that the slot is not nullptr.

Use onRightClick() and onMiddleClick() to handle Pointer::MouseRight and Pointer::MouseMiddle clicks. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onTapOrClickScoped() for a scoped alternative. PointerEvent::isPrimary()

DataHandle Magnum::Ui::EventLayer::onTapOrClick(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

EventConnection Magnum::Ui::EventLayer::onTapOrClickScoped(NodeHandle node, Containers::Function<void()>&& slot)

Scoped connection to a finger / pen tap or left mouse click.

Compared to onTapOrClick() the connection is removed automatically when the returned EventConnection gets destroyed.

EventConnection Magnum::Ui::EventLayer::onTapOrClickScoped(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

DataHandle Magnum::Ui::EventLayer::onMiddleClick(NodeHandle node, Containers::Function<void()>&& slot)

Connect to a middle mouse click.

The slot, optionally receiving a node-relative position of the click, is called when a Pointer::MouseMiddle release happens on the node after a previous pointer press. If event capture is disabled by any event handler on given node, the slot is called only if the pointer didn't leave the node area between a press and a release. Expects that the slot is not nullptr.

Use onTapOrClick() and onRightClick() to handle Pointer::MouseLeft / Pointer::Finger / Pointer::Pen and Pointer::MouseRight clicks. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onMiddleClickScoped() for a scoped alternative.

DataHandle Magnum::Ui::EventLayer::onMiddleClick(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

EventConnection Magnum::Ui::EventLayer::onMiddleClickScoped(NodeHandle node, Containers::Function<void()>&& slot)

Scoped connection to a middle mouse click.

Compared to onMiddleClick() the connection is removed automatically when the returned EventConnection gets destroyed.

EventConnection Magnum::Ui::EventLayer::onMiddleClickScoped(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

DataHandle Magnum::Ui::EventLayer::onRightClick(NodeHandle node, Containers::Function<void()>&& slot)

Connect to a right mouse click.

The slot, optionally receiving a node-relative position of the click, is called when a Pointer::MouseRight release happens on the node after a previous pointer press. If event capture is disabled by any event handler on given node, the slot is called only if the pointer didn't leave the node area between a press and a release. Expects that the slot is not nullptr.

Use onTapOrClick() and onRightClick() to handle Pointer::MouseLeft / Pointer::Finger / Pointer::Pen and Pointer::MouseRight clicks. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onMiddleClickScoped() for a scoped alternative.

DataHandle Magnum::Ui::EventLayer::onRightClick(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

EventConnection Magnum::Ui::EventLayer::onRightClickScoped(NodeHandle node, Containers::Function<void()>&& slot)

Scoped connection to a right mouse click.

Compared to onRightClick() the connection is removed automatically when the returned EventConnection gets destroyed.

EventConnection Magnum::Ui::EventLayer::onRightClickScoped(NodeHandle node, Containers::Function<void(const Vector2&position)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

DataHandle Magnum::Ui::EventLayer::onDrag(NodeHandle node, Containers::Function<void(const Vector2&relativePosition)>&& slot)

Connect to a drag.

The slot, receiving the movement delta and optionally also a node-relative position at which the move happened, is called when a Pointer::MouseLeft, primary Pointer::Finger or Pointer::Pen move happens on the node. To prevent the slot from being triggered by drags that originated outside of node, it's called only if the move event is captured on given node. Expects that the slot is not nullptr.

Use onPinch() to handle two-finger gestures. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onDragScoped() for a scoped alternative. PointerMoveEvent::isPrimary()

DataHandle Magnum::Ui::EventLayer::onDrag(NodeHandle node, Containers::Function<void(const Vector2&position, const Vector2&relativePosition)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

EventConnection Magnum::Ui::EventLayer::onDragScoped(NodeHandle node, Containers::Function<void(const Vector2&relativePosition)>&& slot)

Scoped connection to a drag.

Compared to onDrag() the connection is removed automatically when the returned EventConnection gets destroyed.

EventConnection Magnum::Ui::EventLayer::onDragScoped(NodeHandle node, Containers::Function<void(const Vector2&position, const Vector2&relativePosition)>&& slot)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

DataHandle Magnum::Ui::EventLayer::onPinch(NodeHandle node, Containers::Function<void(const Vector2&position, const Vector2&relativeTranslation, const Complex&relativeRotation, Float relativeScaling)>&& slot)

Connect to a two-finger pinch, zoom or pan gesture.

The slot is called when two or more Pointer::Finger are pressed and move over the node area. It receives a node-relative centroid position between the two presses, translation of the centroid relative to previous state of the two fingers, their relative rotation and scaling. Platform::TwoFingerGesture is used internally, see its documentation for more information. Expects that the slot is not nullptr.

By default, the gesture is tracked as long as the primary finger is pressed, even if the fingers are outside of the node area. If event capture is disabled by any event handler on given node, the gesture stops being tracked when any of the fingers leave the node area. The gesture also stops being tracked when given node loses visibility to events.

Use onDrag() to handle a regular single-finger, mouse or pen drag. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onPinchScoped() for a scoped alternative.

EventConnection Magnum::Ui::EventLayer::onPinchScoped(NodeHandle node, Containers::Function<void(const Vector2&position, const Vector2&relativeTranslation, const Complex&relativeRotation, Float relativeScaling)>&& slot)

Scoped connection to a two-finger pinch, zoom or pan gesture.

Compared to onPinch() the connection is removed automatically when the returned EventConnection gets destroyed.

DataHandle Magnum::Ui::EventLayer::onEnter(NodeHandle node, Containers::Function<void()>&& slot)

Connect to a pointer enter.

The slot is called when a primary pointer moves over the node area. Expects that the slot is not nullptr.

Use onLeave() to hadle the opposite case. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onEnterScoped() for a scoped alternative. PointerMoveEvent::isPrimary()

EventConnection Magnum::Ui::EventLayer::onEnterScoped(NodeHandle node, Containers::Function<void()>&& slot)

Scoped connection to a pointer enter.

Compared to onEnter() the connection is removed automatically when the returned EventConnection gets destroyed.

DataHandle Magnum::Ui::EventLayer::onLeave(NodeHandle node, Containers::Function<void()>&& slot)

Connect to a pointer leave.

The slot is called when a primary pointer moves out of the node area. Expects that the slot is not nullptr.

Use onEnter() to hadle the opposite case. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onLeaveScoped() for a scoped alternative. PointerMoveEvent::isPrimary()

EventConnection Magnum::Ui::EventLayer::onLeaveScoped(NodeHandle node, Containers::Function<void()>&& slot)

Scoped connection to a pointer leave.

Compared to onLeave() the connection is removed automatically when the returned EventConnection gets destroyed.

DataHandle Magnum::Ui::EventLayer::onFocus(NodeHandle node, Containers::Function<void()>&& slot)

Connect to a focus.

The slot is called when a node is focused. Expects that the slot is not nullptr.

Use onBlur() to hadle the opposite case. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onFocusScoped() for a scoped alternative.

EventConnection Magnum::Ui::EventLayer::onFocusScoped(NodeHandle node, Containers::Function<void()>&& slot)

Scoped connection to a focus.

Compared to onFocus() the connection is removed automatically when the returned EventConnection gets destroyed.

DataHandle Magnum::Ui::EventLayer::onBlur(NodeHandle node, Containers::Function<void()>&& slot)

Connect to a blur.

The slot is called when the node is blurred. Expects that the slot is not nullptr.

Use onFocus() to hadle the opposite case. The returned DataHandle is automatically removed once node or any of its parents is removed, it's the caller responsibility to ensure it doesn't outlive the state captured in the slot. See onBlurScoped() for a scoped alternative.

EventConnection Magnum::Ui::EventLayer::onBlurScoped(NodeHandle node, Containers::Function<void()>&& slot)

Scoped connection to a pointer leave.

Compared to onBlur() the connection is removed automatically when the returned EventConnection gets destroyed.

void Magnum::Ui::EventLayer::remove(DataHandle handle)

Remove a connection.

Delegates to AbstractLayer::remove(DataHandle) and additionally calls a destructor on the captured function state, if it's not trivially destructible. The handle becomes invalid, which means that any existing EventConnection instance for it will not attempt to remove it again.

void Magnum::Ui::EventLayer::remove(LayerDataHandle handle)

Remove a connection assuming it belongs to this layer.

Delegates to AbstractLayer::remove(LayerDataHandle) and additionally calls a destructor on the captured function state, if it's not trivially destructible. The handle becomes invalid, which means that any existing EventConnection instance for it will not attempt to remove it again.