In order to implement a text field element successfully, we need to define how it responds to input correctly. Firstly, let's set up a new element type by creating the text field element class and implementing the constructor, as shown here:
GUI_Textfield::GUI_Textfield(const std::string& l_name, GUI_Interface* l_owner) : GUI_Element(l_name, GUI_ElementType::Textfield , l_owner){}
This element can also have a default text value when loaded, so let's express that by providing a custom version of the ReadIn
method:
void GUI_Textfield::ReadIn(std::stringstream& l_stream){ std::string content; Utils::ReadQuotedString(l_stream, content); m_visual.m_text.setString(content); }
As you probably know, text fields do not change state if a mouse button is released. This allows them to be focused until a mouse click is registered elsewhere. We have already implemented that functionality in the GUI_Interface
class as the DefocusTextfields
method. All that's left to...