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.

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.