|
Gosu
|
TextInput instances are invisible objects that build a text string from input, using the current operating system's keyboard layout. More...
Public Member Functions | |
| TextInput () | |
| virtual | ~TextInput () |
| std::string | text () const |
| void | set_text (const std::string &text) |
| Replaces the current text by the given string and positions the cursor at the end of the text, with an empty selection. More... | |
| unsigned | caret_pos () const |
| Index of the character that comes after the caret. More... | |
| void | set_caret_pos (unsigned pos) |
| Sets the caret position as returned by caret_pos. More... | |
| unsigned | selection_start () const |
| If there is a selection, the selection_start() member yields its beginning, using the same indexing scheme as caret_pos. More... | |
| void | set_selection_start (unsigned pos) |
| Sets the start of the selection as returned by selection_start. More... | |
| bool | feed_sdl_event (void *event) |
| virtual std::string | filter (std::string text) const |
| Overridable filter that is applied to all new text that is entered. More... | |
| void | insert_text (std::string text) |
| Replaces the current selection (if any) and inserts the given string at the current caret position. More... | |
| void | delete_forward () |
| Deletes the current selection, if any, or the next character. More... | |
| void | delete_backward () |
| Deletes the current selection, if any, or the previous character. More... | |
TextInput instances are invisible objects that build a text string from input, using the current operating system's keyboard layout.
At its most basic form, you only need to create a new TextInput instance and pass it to your window via set_text_input. Until you call this function again, passing nullptr, the TextInput object will build a text that can be accessed via TextInput::text(). A TextInput object is purely abstract. It is up to you to actually draw a text field. TextInput only provides a portable base for your own GUI to build upon.
Definition at line 21 of file TextInput.hpp.
| Gosu::TextInput::TextInput | ( | ) |
|
virtual |
| unsigned Gosu::TextInput::caret_pos | ( | ) | const |
Index of the character that comes after the caret.
When the text is empty, this is always 0. For ease of use in C++, this counts bytes, not codepoints in the UTF-8 encoded string.
| void Gosu::TextInput::delete_backward | ( | ) |
Deletes the current selection, if any, or the previous character.
Referenced by filter().
| void Gosu::TextInput::delete_forward | ( | ) |
Deletes the current selection, if any, or the next character.
Referenced by filter().
| bool Gosu::TextInput::feed_sdl_event | ( | void * | event | ) |
|
virtual |
Overridable filter that is applied to all new text that is entered.
Allows for context-sensitive filtering/extending/... of new characters. The return value will be inserted at caret_pos.
Definition at line 60 of file TextInput.hpp.
References delete_backward(), delete_forward(), insert_text(), and text().
| void Gosu::TextInput::insert_text | ( | std::string | text | ) |
Replaces the current selection (if any) and inserts the given string at the current caret position.
The filter method will not be applied before appending the string.
Referenced by filter().
| unsigned Gosu::TextInput::selection_start | ( | ) | const |
If there is a selection, the selection_start() member yields its beginning, using the same indexing scheme as caret_pos.
If there is no selection, selection_start() is equal to caret_pos().
| void Gosu::TextInput::set_caret_pos | ( | unsigned | pos | ) |
Sets the caret position as returned by caret_pos.
You usually also want to use set_selection_start.
| void Gosu::TextInput::set_selection_start | ( | unsigned | pos | ) |
Sets the start of the selection as returned by selection_start.
| void Gosu::TextInput::set_text | ( | const std::string & | text | ) |
Replaces the current text by the given string and positions the cursor at the end of the text, with an empty selection.
| std::string Gosu::TextInput::text | ( | ) | const |
Referenced by filter().
1.8.13