SFML community forums

Help => Graphics => Topic started by: Perde on May 31, 2012, 12:35:35 am

Title: sf::Text bounds not updated
Post by: Perde 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.
Title: Re: sf::Text bounds not updated
Post by: eXpl0it3r on May 31, 2012, 01:46:50 am
There will be a reimplementation of the getGlobalBounds() function, see issue #216 (https://github.com/SFML/SFML/issues/216)
Title: Re: sf::Text bounds not updated
Post by: Perde 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.
Title: Re: sf::Text bounds not updated
Post by: Nexus 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.
Title: Re: sf::Text bounds not updated
Post by: Perde 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.