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

Button widget.

Base classes

template<class UserInterface>
class BasicWidget<UserInterface> new in Git master
Templated abstract base for stateful widgets.

Constructors, destructors, conversion operators

Button(Anchor anchor, Icon icon, ButtonStyle style = ButtonStyle::Default) explicit
Construct an icon button.
Button(Anchor anchor, Containers::StringView text, const TextProperties& textProperties, ButtonStyle style = ButtonStyle::Default) explicit
Construct a text button.
Button(Anchor anchor, Containers::StringView text, ButtonStyle style = ButtonStyle::Default) explicit
Button(Anchor anchor, Icon icon, Containers::StringView text, const TextProperties& textProperties, ButtonStyle style = ButtonStyle::Default) explicit
Construct an icon + text button.
Button(Anchor anchor, Icon icon, Containers::StringView text, ButtonStyle style = ButtonStyle::Default) explicit
Button(NonOwnedT, Anchor anchor, Icon icon, ButtonStyle style = ButtonStyle::Default) explicit
Construct a non-owned icon button.
Button(NonOwnedT, Anchor anchor, Containers::StringView text, const TextProperties& textProperties, ButtonStyle style = ButtonStyle::Default) explicit
Construct a non-owned text button.
Button(NonOwnedT, Anchor anchor, Containers::StringView text, ButtonStyle style = ButtonStyle::Default) explicit
Button(NonOwnedT, Anchor anchor, Icon icon, Containers::StringView text, const TextProperties& textProperties, ButtonStyle style = ButtonStyle::Default) explicit
Construct a non-owned icon + text button.
Button(NonOwnedT, Anchor anchor, Icon icon, Containers::StringView text, ButtonStyle style = ButtonStyle::Default) explicit
Button(NoCreateT) explicit
Construct with no underlying node.

Public functions

auto style() const -> ButtonStyle
Style.
auto setStyle(ButtonStyle style) -> Button&
Set style.
auto icon() const -> Icon
Icon.
auto setIcon(Icon icon) -> Button&
Set icon.
auto setText(Containers::StringView text, const TextProperties& textProperties = {}) -> Button&
Set text.
auto onTrigger(Containers::Function<void()>&& function) -> DataHandle
Connect to the button being triggered.
auto onTriggerScoped(Containers::Function<void()>&& function) -> EventConnection
Scoped connection to the button being triggered.
auto backgroundData() const -> DataHandle
Background data.
auto iconData() const -> DataHandle
Icon data or DataHandle::Null.
auto textData() const -> DataHandle
Text data or DataHandle::Null.

Function documentation

Magnum::Ui::Button::Button(Anchor anchor, Icon icon, ButtonStyle style = ButtonStyle::Default) explicit

Construct an icon button.

Parameters
anchor Positioning anchor
icon Button icon. Passing Icon::None makes the button empty.
style Button style

The button can be subsequently converted to text-only or icon + text using setIcon() and setText(). Use onTrigger() to connect the button to an action.

Magnum::Ui::Button::Button(Anchor anchor, Containers::StringView text, const TextProperties& textProperties, ButtonStyle style = ButtonStyle::Default) explicit

Construct a text button.

Parameters
anchor Positioning anchor
text Button text. Passing an empty string makes the button empty.
textProperties Text shaping and layouting properties
style Button style

The button can be subsequently converted to icon-only or icon + text using setIcon() and setText(). Use onTrigger() to connect the button to an action.

Magnum::Ui::Button::Button(Anchor anchor, Containers::StringView text, ButtonStyle style = ButtonStyle::Default) explicit

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

Magnum::Ui::Button::Button(Anchor anchor, Icon icon, Containers::StringView text, const TextProperties& textProperties, ButtonStyle style = ButtonStyle::Default) explicit

Construct an icon + text button.

Parameters
anchor Positioning anchor
icon Button icon. Passing Icon::None creates the button without an icon.
text Button text. Passing an empty string creates the button without a text.
textProperties Text shaping and layouting properties
style Button style

The button can be subsequently converted to icon-only or text-only using setIcon() and setText(). Use onTrigger() to connect the button to an action.

Magnum::Ui::Button::Button(Anchor anchor, Icon icon, Containers::StringView text, ButtonStyle style = ButtonStyle::Default) explicit

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

Magnum::Ui::Button::Button(NonOwnedT, Anchor anchor, Icon icon, ButtonStyle style = ButtonStyle::Default) explicit

Construct a non-owned icon button.

Like Button(Anchor, Icon, ButtonStyle) but the widget node doesn't get removed on destruction. Instead, it gets removed either once any parent node is removed, or when AbstractUserInterface::removeNode() is explicitly called on node().

Magnum::Ui::Button::Button(NonOwnedT, Anchor anchor, Containers::StringView text, const TextProperties& textProperties, ButtonStyle style = ButtonStyle::Default) explicit

Construct a non-owned text button.

Like Button(Anchor, Containers::StringView, const TextProperties&, ButtonStyle) but the widget node doesn't get removed on destruction. Instead, it gets removed either once any parent node is removed, or when AbstractUserInterface::removeNode() is explicitly called on node().

Magnum::Ui::Button::Button(NonOwnedT, Anchor anchor, Containers::StringView text, ButtonStyle style = ButtonStyle::Default) explicit

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

Magnum::Ui::Button::Button(NonOwnedT, Anchor anchor, Icon icon, Containers::StringView text, const TextProperties& textProperties, ButtonStyle style = ButtonStyle::Default) explicit

Construct a non-owned icon + text button.

Like Button(Anchor, Icon, Containers::StringView, const TextProperties&, ButtonStyle) but the widget node doesn't get removed on destruction. Instead, it gets removed either once any parent node is removed, or when AbstractUserInterface::removeNode() is explicitly called on node().

Magnum::Ui::Button::Button(NonOwnedT, Anchor anchor, Icon icon, Containers::StringView text, ButtonStyle style = ButtonStyle::Default) explicit

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

Magnum::Ui::Button::Button(NoCreateT) explicit

Construct with no underlying node.

The instance is equivalent to a moved-out state, i.e. not usable for anything. Move another instance over it to make it useful.

Button& Magnum::Ui::Button::setStyle(ButtonStyle style)

Set style.

Returns Reference to self (for method chaining)

Note that calling this function doesn't change the font if the new style uses a different one, you have to call setText() afterwards to make it pick it up.

Button& Magnum::Ui::Button::setIcon(Icon icon)

Set icon.

Returns Reference to self (for method chaining)

Passing Icon::None removes the icon.

Button& Magnum::Ui::Button::setText(Containers::StringView text, const TextProperties& textProperties = {})

Set text.

Returns Reference to self (for method chaining)

Passing an empty text removes the text.

DataHandle Magnum::Ui::Button::onTrigger(Containers::Function<void()>&& function)

Connect to the button being triggered.

Returns New data handle

Expects that the function is not nullptr. Unless explicitly removed through the returned DataHandle, the callback is active until the button itself is removed. See onTriggerScoped() for an alternative.

Subsequent calls to this function don't replace existing calls but add to them. There is no guarantee on the order in which multiple functions are called.

Delegates to EventLayer::onTapOrClick(), see its documentation for detailed behavior description.

EventConnection Magnum::Ui::Button::onTriggerScoped(Containers::Function<void()>&& function)

Scoped connection to the button being triggered.

Returns Event connection instance

Expects that the function is not nullptr. Compared to onTrigger(), the callback is removed when the returned EventConnection is destructed.

DataHandle Magnum::Ui::Button::backgroundData() const

Background data.

Exposed mainly for testing purposes, not meant to be modified directly.

DataHandle Magnum::Ui::Button::iconData() const

Icon data or DataHandle::Null.

Exposed mainly for testing purposes, not meant to be modified directly.

DataHandle Magnum::Ui::Button::textData() const

Text data or DataHandle::Null.

Exposed mainly for testing purposes, not meant to be modified directly.