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 onPressScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a finger / pen tap or left mouse press.
auto onRelease(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a finger / pen tap or left mouse release.
auto onReleaseScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a finger / pen tap or left mouse release.
auto onTapOrClick(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a finger / pen tap or left mouse click.
auto onTapOrClickScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a finger / pen tap or left mouse click.
auto onMiddleClick(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a middle mouse click.
auto onMiddleClickScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a middle mouse click.
auto onRightClick(NodeHandle node, Containers::Function<void()>&& slot) -> DataHandle
Connect to a right mouse click.
auto onRightClickScoped(NodeHandle node, Containers::Function<void()>&& slot) -> EventConnection
Scoped connection to a right mouse click.
auto onDrag(NodeHandle node, Containers::Function<void(const Vector2&)>&& slot) -> DataHandle
Connect to a drag.
auto onDragScoped(NodeHandle node, Containers::Function<void(const Vector2&)>&& slot) -> EventConnection
Scoped connection to a drag.
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 is called when a Pointer::MouseLeft, Pointer::Finger or Pointer::Pen press happens on the node.

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.

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.

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

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

The slot is called when a Pointer::MouseLeft, Pointer::Finger or Pointer::Pen release happens on the node.

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.

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.

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

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

The slot is called when a Pointer::MouseLeft, Pointer::Finger or Pointer::Pen 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.

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.

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.

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

Connect to a middle mouse click.

The slot 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.

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.

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.

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

Connect to a right mouse click.

The slot 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.

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.

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.

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

Connect to a drag.

The slot, receiving the movement delta, is called when a Pointer::MouseLeft, Pointer::Finger or Pointer::Pen move happens on the node. If event capture is disabled by any event handler on given node, the slot is called only as long as the pointer doesn't leave the node area.

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.

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

Scoped connection to a drag.

Compared to onDrag() 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 pointer moves over the node area.

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.

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 pointer moves out of the node area.

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.

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.

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.

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.