Magnum::Ui::Input class

Input widget.

Can attach to application-specific keyboard and text input.

Base classes

class Widget
Base for widgets.

Derived classes

class ValidatedInput
Validated input.

Constructors, destructors, conversion operators

Input(Plane& plane, const Anchor& anchor, std::string value, std::size_t maxValueSize, Style style = Style::Default) explicit
Constructor.
Input(Plane& plane, const Anchor& anchor, std::size_t maxValueSize, Style style = Style::Default) explicit

Public functions

auto setStyle(Style style) -> Input&
Set widget style.
auto maxValueSize() const -> std::size_t
Max value size.
auto value() const -> const std::string&
Value.
auto setValue(const std::string& value) -> Input&
Set value.
auto setValue(std::string&& value) -> Input&
auto setValue(Containers::ArrayView<const char> value) -> Input&
template<std::size_t size>
auto setValue(const char(&value)[size]) -> Input&
template<class KeyEvent>
auto handleKeyPress(KeyEvent& keyEvent) -> bool
Handle key press from an application.
template<class TextInputEvent>
auto handleTextInput(TextInputEvent& textInputEvent) -> bool
Handle text input from an application.
auto focused() -> Signal
The widget was focused.
auto blurred() -> Signal
The widget was blurred.
auto valueChanged(const std::string& value) -> Signal
The input value changed.

Private functions

void update() override virtual
Update the widget after its state changed.
auto hoverEvent() override -> bool virtual
Hover event.
auto pressEvent() override -> bool virtual
Press event.
auto releaseEvent() override -> bool virtual
Release event.
auto focusEvent() override -> bool virtual
Focus event.
auto blurEvent() override -> bool virtual
Blur event.

Function documentation

Magnum::Ui::Input::Input(Plane& plane, const Anchor& anchor, std::string value, std::size_t maxValueSize, Style style = Style::Default) explicit

Constructor.

Parameters
plane Plane this widget is a part of
anchor Positioning anchor
value Initial input value
maxValueSize Max input text size
style Widget style

Magnum::Ui::Input::Input(Plane& plane, const Anchor& anchor, std::size_t maxValueSize, Style style = Style::Default) explicit

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

Input& Magnum::Ui::Input::setStyle(Style style)

Set widget style.

Returns Reference to self (for method chaining)

Input& Magnum::Ui::Input::setValue(const std::string& value)

Set value.

Returns Reference to self (for method chaining)

The value is expected to not have more glyphs than the capacity set in constructor.

Input& Magnum::Ui::Input::setValue(std::string&& value)

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

Input& Magnum::Ui::Input::setValue(Containers::ArrayView<const char> value)

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

template<std::size_t size>
Input& Magnum::Ui::Input::setValue(const char(&value)[size])

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

template<class KeyEvent>
bool Magnum::Ui::Input::handleKeyPress(KeyEvent& keyEvent)

Handle key press from an application.

Handles keyboard input like cursor movement or backspace/delete keys. Should be called from within Platform::*Application::keyPressEvent(). Returns true if the event was accepted (and thus the input value changed), false otherwise.

template<class TextInputEvent>
bool Magnum::Ui::Input::handleTextInput(TextInputEvent& textInputEvent)

Handle text input from an application.

Handles UTF-8 text input. Input that makes the value exceed maxValueSize is ignored. Should be called from within Platform::*Application::textInputEvent(). Returns true if the event was accepted (and thus the input value changed), false otherwise.

Signal Magnum::Ui::Input::focused()

The widget was focused.

Text input from the application should be started upon signalling this and passed to handleKeyPress() and handleTextInput().

Signal Magnum::Ui::Input::blurred()

The widget was blurred.

Text input from the application should be stopped upon signalling this.

Signal Magnum::Ui::Input::valueChanged(const std::string& value)

The input value changed.

Useful for attaching input validators.

void Magnum::Ui::Input::update() override virtual private

Update the widget after its state changed.

Expects to do only visual update, should not do any expensive operations like text relayouting.

bool Magnum::Ui::Input::hoverEvent() override virtual private

Hover event.

Returns True if the event was accepted, false if it was ignored

Called when the widget is hovered by the mouse or when the mouse leaves it again. Use Flag::Hovered to check for the state. Default implementation does nothing and returns false.

bool Magnum::Ui::Input::pressEvent() override virtual private

Press event.

Returns True if the event was accepted, false if it was ignored

When the widget is pressed, Flag::Pressed is set and this function is called. Default implementation does nothing and returns false.

bool Magnum::Ui::Input::releaseEvent() override virtual private

Release event.

Returns True if the event was accepted, false if it was ignored

On release after previous press event, Flag::Pressed flag is removed and this function is called. Default implementation does nothing and returns false.

bool Magnum::Ui::Input::focusEvent() override virtual private

Focus event.

Returns True if the event was accepted, false if it was ignored

If both press and release event happened on the same widget, Flag::Active is set and this function is called. Default implementation does nothing and returns false.

bool Magnum::Ui::Input::blurEvent() override virtual private

Blur event.

Returns True if the event was accepted, false if it was ignored

If the widget was active previously and the user tapped outside, Flag::Active is removed and this function is called. Default implementation does nothing and returns false.