The text field element

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

Get SFML Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.