SFML community forums

Help => Graphics => Topic started by: texus on January 03, 2012, 04:55:59 pm

Title: Text.GetLocalBounds ignores spaces at the beginning and end?
Post by: texus on January 03, 2012, 04:55:59 pm
When I fill a sf::Text with a string that starts or ends with spaces then the GetLocalBounds and GetGlobalBounds functions don't return the correct width.

Here is an example code:
Code: [Select]
sf::Text text("     test     ");
float Width = text.GetGlobalBounds().Width;

Width will be 49 (with the default font).
This is only the width of the "test", so the spaces are ignored.
The width should be something like 127 (this is what FindCharacterPosition returned).
Title: Text.GetLocalBounds ignores spaces at the beginning and end?
Post by: Laurent on January 03, 2012, 04:58:19 pm
Yep, this is a bug in the current implementation. It'll be easy to fix.
Title: Text.GetLocalBounds ignores spaces at the beginning and end?
Post by: Mario on January 05, 2012, 12:51:24 am
Before you fix this, I think both flavors might be interesting for this, depending on what you're using it for, e.g. for some mouse over stuff you might prefer just getting the rectangle where characters are actually drawn.
Title: Text.GetLocalBounds ignores spaces at the beginning and end?
Post by: Laurent on January 05, 2012, 07:57:01 am
Quote
Before you fix this, I think both flavors might be interesting for this, depending on what you're using it for, e.g. for some mouse over stuff you might prefer just getting the rectangle where characters are actually drawn.

I don't think that this should be the default behaviour for such a function.
Title: Text.GetLocalBounds ignores spaces at the beginning and end?
Post by: Mario on January 05, 2012, 04:25:11 pm
No, the default behaviour/return value should get you the complete rectangle. I was thinking more about something like an additional GetLocalTrimmedBounds() or something similar.
Title: Text.GetLocalBounds ignores spaces at the beginning and end?
Post by: Laurent on January 05, 2012, 04:30:12 pm
Is it really needed? Who uses text with whitespace at the beginning or at the end?
Title: Text.GetLocalBounds ignores spaces at the beginning and end?
Post by: Mario on January 05, 2012, 04:33:54 pm
Not sure, for the odd cases. I'd skip it, if it's adding significant overhead - keeping it otherwise.

The program could print text at fixed positions showing some dynamic text loaded from a text file (probably multi line) with leading or trailing spaces you don't want to trim by hand and still keep the borders to where there's real text.
Title: Text.GetLocalBounds ignores spaces at the beginning and end?
Post by: Laurent on January 05, 2012, 04:39:28 pm
Let's keep that for later ;)