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

Author Topic: sf::Text bounds not updated  (Read 3295 times)

0 Members and 1 Guest are viewing this topic.

Perde

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
sf::Text bounds not updated
« on: May 31, 2012, 12:35:35 am »
Okay, I have a little problem with sf::Text that I need some help with, or some clarification.

Basically this happens:
sf::Text text;
std::cout << text.getGlobalBounds().width << std::endl; // 0
text.setString("");
std::cout << text.getGlobalBounds().width << std::endl; // 0
text.setString("a");
std::cout << text.getGlobalBounds().width << std::endl; // 16
text.setString("");
std::cout << text.getGlobalBounds().width << std::endl; //16

In words: Once sf::Text had some sort of string and is set to an empty string it still keeps the bounds of the previous one.

Now I'd like to know if this is intended, if I'm doing something wrong or if this shouldn't be that way. Is there maybe a better way to clear the string?

[edit]
Oh yes, I'm using 2.0 RC.
« Last Edit: May 31, 2012, 12:59:12 am by Perde »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: sf::Text bounds not updated
« Reply #1 on: May 31, 2012, 01:46:50 am »
There will be a reimplementation of the getGlobalBounds() function, see issue #216
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Perde

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: sf::Text bounds not updated
« Reply #2 on: May 31, 2012, 01:51:14 am »
Ah, I didn't see that. It behaves strangely indeed, but this thing I couldn't find a workaround for.

Anyway, thank you for pointing me there.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Text bounds not updated
« Reply #3 on: June 01, 2012, 08:20:20 pm »
but this thing I couldn't find a workaround for.
Take a look at the links in the GitHub issue, in a forum thread I proposed a solution.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Perde

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: sf::Text bounds not updated
« Reply #4 on: June 02, 2012, 01:53:32 pm »
I will do that, but I have found a solution already. It's not the most elegant, but all I have to do is remind myself of it when this will be fixed/updated.

The problem I had was with the text-input of my gui-system. Whenever the last character got removed the cursor would stay on a wrong position. Now, whenever the string is empty it gets set to the relative position of the control, and not the sf::text bounds anymore.