morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::ui::testing::detail::FakeTextInput Class Referencefinal

A fake TextInputWidget: properties mode, text, placeholder, unit, decimals, icon, caption, captionShown, the field state, and a text cursor. More...

#include <recording_backend.hpp>

Inheritance diagram for morph::ui::testing::detail::FakeTextInput:
morph::ui::testing::detail::FakeField< TextInputWidget > morph::ui::testing::detail::FakeLeaf< TextInputWidget > morph::ui::TextInputWidget morph::ui::FieldWidget morph::ui::Widget

Public Member Functions

void setText (std::string_view text) override
 Records property text; moves the cursor to the end only when the text changes.
void typedByUser (std::string text, std::size_t cursor)
 The text the user typed: the field shows it, and the cursor is at cursor; nothing is logged.
void moveCursorByUser (std::size_t cursor) noexcept
 Moves the cursor as the user's arrow keys or a click would.
std::size_t cursor () const noexcept
 Where the cursor is.
std::string const & text () const noexcept
 The text the field shows.
void setPlaceholder (std::string_view placeholder) override
 Sets the text shown while the field is empty.
void setUnit (std::string_view unit) override
 Sets the unit the input shows, muted, at its trailing edge, inside the field; empty shows none. Called only on a single-line or password input.
void setDecimals (int decimals) override
 Sets the fraction digits a number is entered with: what a backend or a kit may use to align or format the text. Nothing is required of a backend that draws nothing from it. Called only on a single-line or password input.
void setIcon (std::string_view icon) override
 Sets the icon drawn at the field's leading edge; empty shows none. Called once, and only for a single-line or password input that has one.
void setCaption (std::string_view label, bool shown) override
 Sets the field's label, and whether the input draws it as a visible caption above its control. Without shown, the caption is drawn elsewhere (a form's cell), or not at all.
void setOnChange (std::function< void(std::string)> onChange) override
 Sets what a user edit calls, with the whole new text.
void setOnSubmit (std::function< void(std::string)> onSubmit) override
 Sets what a submit (Enter in single-line mode) calls, with the text.
void setOnCommit (std::function< void(std::string)> onCommit) override
 Sets what a commit calls, with the text: Enter in single-line mode, before the submit, or focus leaving the field after an edit.
Public Member Functions inherited from morph::ui::testing::detail::FakeField< TextInputWidget >
void setReadOnly (bool readonly) override
 Records property readonly; RecordingBackend's edits leave a read-only field alone.
void setRequired (bool required) override
 Records property required.
void setErrors (std::vector< std::string > const &errors) override
 Records property errors, as formatList gives the messages.
void setStale (bool stale) override
 Records property stale.
Public Member Functions inherited from morph::ui::testing::detail::FakeLeaf< TextInputWidget >
 FakeLeaf (std::shared_ptr< RecordStore > store, std::string kind, ContainerWidget const *parent, PropList initial={})
 Records the new widget, appended to parent, and logs its creation.
 ~FakeLeaf () override
 Forgets the widget and logs its destruction; its remaining children become roots.
FakeLeaf & operator= (FakeLeaf const &)=delete
void setVisible (bool visible) override
 Records property visible.
void setEnabled (bool enabled) override
 Records property enabled.
void setLayout (LayoutHints const &hints) override
 Records property layout, as formatLayout gives it.
void setDragKey (std::optional< Key > const &key) override
 Records property dragKey and keeps the key for RecordingBackend::drag.
void setDropHandler (std::function< bool(Key const &)> accepts, std::function< void(Key)> onDrop) override
 Records property drop=handler and keeps both handlers for RecordingBackend::drag.
void setAccessibleName (std::string_view name) override
 Records property a11yName.
void setAccessibleRole (std::string_view role) override
 Records property a11yRole.
void setTestId (std::string_view testId) override
 Records property testId.
void setTooltip (std::string_view text) override
 Records property tooltip.
void setSurface (std::string_view surface) override
 Records property surface.
void setKeys (std::vector< std::string > const &chords, std::function< void(std::string)> onChord) override
 Records property keys, the chords joined by commas, and keeps the chords and the handler for RecordingBackend::press.
void focus () override
 Moves the backend's recorded focus here, and logs focus.
void setOnHover (std::function< void()> onHover) override
 Keeps the handler for RecordingBackend::hover.
Public Member Functions inherited from morph::ui::Widget
 Widget (Widget const &)=delete
Widget & operator= (Widget const &)=delete
 Widget (Widget &&)=delete
Widget & operator= (Widget &&)=delete

Additional Inherited Members

Protected Member Functions inherited from morph::ui::testing::detail::FakeLeaf< TextInputWidget >
void set (std::string_view name, std::string value)
 Records a property set through a setter.
Callbacks & callbacks ()
 This widget's handlers.
RecordStore & store () const noexcept
 The store this widget records into.
std::shared_ptr< RecordStore > const & sharedStore () const noexcept
 The store, shared: what a part this widget makes (an overlay's footer) records into.
int id () const noexcept
 This widget's id.

Detailed Description

A fake TextInputWidget: properties mode, text, placeholder, unit, decimals, icon, caption, captionShown, the field state, and a text cursor.

The cursor is a byte offset into the text. A user's edit puts it where the edit left it; setText with the text the field shows leaves it alone, as the contract requires, and setText with another text puts it at the end.

Definition at line 906 of file recording_backend.hpp.

Member Function Documentation

◆ setText()

void morph::ui::testing::detail::FakeTextInput::setText ( std::string_view text)
inlineoverridevirtual

Records property text; moves the cursor to the end only when the text changes.

Parameters
textThe text, UTF-8.

Implements morph::ui::TextInputWidget.

Definition at line 912 of file recording_backend.hpp.

◆ typedByUser()

void morph::ui::testing::detail::FakeTextInput::typedByUser ( std::string text,
std::size_t cursor )
inline

The text the user typed: the field shows it, and the cursor is at cursor; nothing is logged.

Parameters
textThe whole new text.
cursorWhere the cursor ends up; clamped to the text's size.

Definition at line 923 of file recording_backend.hpp.

◆ moveCursorByUser()

void morph::ui::testing::detail::FakeTextInput::moveCursorByUser ( std::size_t cursor)
inlinenoexcept

Moves the cursor as the user's arrow keys or a click would.

Parameters
cursorThe new position; clamped to the text's size.

Definition at line 931 of file recording_backend.hpp.

◆ cursor()

std::size_t morph::ui::testing::detail::FakeTextInput::cursor ( ) const
inlinenodiscardnoexcept

Where the cursor is.

Returns
A byte offset into the text shown.

Definition at line 935 of file recording_backend.hpp.

◆ text()

std::string const & morph::ui::testing::detail::FakeTextInput::text ( ) const
inlinenodiscardnoexcept

The text the field shows.

Returns
The text, unformatted.

Definition at line 939 of file recording_backend.hpp.

◆ setPlaceholder()

void morph::ui::testing::detail::FakeTextInput::setPlaceholder ( std::string_view placeholder)
inlineoverridevirtual

Sets the text shown while the field is empty.

Parameters
placeholderThe text, UTF-8.

Implements morph::ui::TextInputWidget.

Definition at line 941 of file recording_backend.hpp.

◆ setUnit()

void morph::ui::testing::detail::FakeTextInput::setUnit ( std::string_view unit)
inlineoverridevirtual

Sets the unit the input shows, muted, at its trailing edge, inside the field; empty shows none. Called only on a single-line or password input.

Parameters
unitThe unit's display text, UTF-8.

Implements morph::ui::TextInputWidget.

Definition at line 942 of file recording_backend.hpp.

◆ setDecimals()

void morph::ui::testing::detail::FakeTextInput::setDecimals ( int decimals)
inlineoverridevirtual

Sets the fraction digits a number is entered with: what a backend or a kit may use to align or format the text. Nothing is required of a backend that draws nothing from it. Called only on a single-line or password input.

Parameters
decimalsThe places, from 0; -1 when the input does not hold a number.

Implements morph::ui::TextInputWidget.

Definition at line 943 of file recording_backend.hpp.

◆ setIcon()

void morph::ui::testing::detail::FakeTextInput::setIcon ( std::string_view icon)
inlineoverridevirtual

Sets the icon drawn at the field's leading edge; empty shows none. Called once, and only for a single-line or password input that has one.

Parameters
iconAn icon name of the theme's icon set.

Implements morph::ui::TextInputWidget.

Definition at line 944 of file recording_backend.hpp.

◆ setCaption()

void morph::ui::testing::detail::FakeTextInput::setCaption ( std::string_view label,
bool shown )
inlineoverridevirtual

Sets the field's label, and whether the input draws it as a visible caption above its control. Without shown, the caption is drawn elsewhere (a form's cell), or not at all.

Parameters
labelThe label, UTF-8.
shownWhether the input shows it.

Implements morph::ui::TextInputWidget.

Definition at line 945 of file recording_backend.hpp.

◆ setOnChange()

void morph::ui::testing::detail::FakeTextInput::setOnChange ( std::function< void(std::string)> onChange)
inlineoverridevirtual

Sets what a user edit calls, with the whole new text.

Parameters
onChangeThe handler; empty does nothing.

Implements morph::ui::TextInputWidget.

Definition at line 949 of file recording_backend.hpp.

◆ setOnSubmit()

void morph::ui::testing::detail::FakeTextInput::setOnSubmit ( std::function< void(std::string)> onSubmit)
inlineoverridevirtual

Sets what a submit (Enter in single-line mode) calls, with the text.

Parameters
onSubmitThe handler; empty does nothing.

Implements morph::ui::TextInputWidget.

Definition at line 950 of file recording_backend.hpp.

◆ setOnCommit()

void morph::ui::testing::detail::FakeTextInput::setOnCommit ( std::function< void(std::string)> onCommit)
inlineoverridevirtual

Sets what a commit calls, with the text: Enter in single-line mode, before the submit, or focus leaving the field after an edit.

Parameters
onCommitThe handler; empty does nothing.

Implements morph::ui::TextInputWidget.

Definition at line 951 of file recording_backend.hpp.


The documentation for this class was generated from the following file: