Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Text displaying square  (Read 1831 times)

0 Members and 1 Guest are viewing this topic.

Heryon

  • Newbie
  • *
  • Posts: 9
    • View Profile
sf::Text displaying square
« on: June 21, 2017, 02:58:26 am »
Hi, I have this code:
Code: [Select]
void TextEditor::handleEvent(const sf::Event& p_event)
{
   if(p_event.type == sf::Event::KeyPressed && p_event.key.code == sf::Keyboard::Return)
      addLine();

   else if(p_event.type == sf::Event::TextEntered)
      write(p_event);
}

void TextEditor::addLine()
{
   sf::String s(m_text.getString())
   s += "\n";
   m_text.setString(s);
}

void TextEditor::write(const sf::Event& p_event)
{
   sf::String s(m_text.getString());

   if(p_event.key.code != sf::Keyboard::BackSpace && p_event.key.code != sf::Keyboard::Return)
      s += static_cast<char>(p_event.text.unicode);

   m_text.setString(s);
}

When I press Return with this code, the Text goes to the next line but also writes a square at the beginning of the line.
If I comment the conditions which calls write(), no square is printed.
So why am I getting this strange behaviour?

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: sf::Text displaying square
« Reply #1 on: June 22, 2017, 12:15:44 pm »
The line break is a character you'll receive as sf::Event::TextEntered, but it's not printable (therefore resulting in the square box).

 

anything