TextField¶
A simple single-line editable text field.
Declaration¶
namespace bdn::ui {
class TextField : public View
}
Example¶
#include <bdn/ui/TextField.h>
//...
auto textField = std::make_shared<TextField>();
textField->text = "Hello world!";
textField->onSubmit() += [](auto event) {
// Do something on submit
};
Properties¶
-
Property<std::string> text
The text displayed in the text field.
-
A placeholder text displayed when the text field is empty.
-
Property<AutocorrectionType> autocorrectionType
The autocorrection type used by the text field.
If not set, the platform's default behavior will be used. If set to
AutocorrectionType::Yes
, the text field will display typing suggestions and apply platform-specific autocorrection and autocomplete.Note that on Android, the implementation of the software keyboard may override the behavior indicated by the
autocorrectionType
property.This property is supported on Android and iOS only.
Warning
On Android, this function uses the
EditText
widget's input type flagTYPE_TEXT_FLAG_NO_SUGGESTIONS
to deactivate autocorrection, autocomplete, and typing suggestions. Based on the software keyboard implementation used by the operating system, this flag may or may not have an effect. Setting theautocorrectionType
property toAutocorrectionType::No
is hence not a guarantee that autocorrection will be deactivated on Android. -
Property<ReturnKeyType> returnKeyType
The type of return key to use when displaying a software keyboard.
Defaults to
ReturnKeyType::Default
which corresponds to input actionIME_ACTION_UNSPECIFIED
on Android and toUIReturnKeyDefault
on iOS. The default indicates that the operating system should decide what return key type to display. Typically, iOS will show "return" and Android will show "return" or "done" in the return key button. SeeReturnKeyType
for details.This property is supported on Android and iOS only.
-
Property<TextInputType> textInputType
The type of content that the user is supposed to enter.
Defaults to
TextInputType::Text
which corresponds toUIKeyboardTypeDefault
on iOS andInputType::TYPE_CLASS_TEXT
on Android.This property is supported on Android and iOS only.
-
Property<bool> obscureInput
Controls whether the text field should hide the users input or not.
The default is false.
Note that on Android this is only supported for certain
TextInputType
s, namelyText
andNumber
.This property is supported on Android and iOS only.
Stylesheet¶
-
{ "font" : Font }
Controls the font of the TextField.
Actions¶
-
void submit()
Informs observers of the
onSubmit()
notifier about a submit event. -
void focus()
Sets focus to the text field.
Events¶
-
Notifier<const SubmitEvent &> &onSubmit()
Notifies subscribers when the Enter key is pressed by the user.
Subscribe to this notifier if you want to be notified about submit events posted to the text field. Submit events are posted when the user presses the Enter key or when
submit()
is called programmatically.
Relationships¶
Inherits from: View