Gosu
Public Member Functions | List of all members
Gosu::TextInput Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TextInput()

Gosu::TextInput::TextInput ( )

◆ ~TextInput()

virtual Gosu::TextInput::~TextInput ( )
virtual

Member Function Documentation

◆ caret_pos()

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.

◆ feed_sdl_event()

bool Gosu::TextInput::feed_sdl_event ( void *  event)

◆ filter()

virtual std::string Gosu::TextInput::filter ( std::string  text) const
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 58 of file TextInput.hpp.

References text().

◆ selection_start()

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().

◆ set_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.

◆ set_selection_start()

void Gosu::TextInput::set_selection_start ( unsigned  pos)

Sets the start of the selection as returned by selection_start.

◆ set_text()

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.

◆ text()

std::string Gosu::TextInput::text ( ) const

Referenced by filter().


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