SFML community forums
Help => Graphics => Topic started by: nietaki on March 18, 2012, 11:03:07 pm
-
I am finishing my TextArea widget and to make things easier for me to implement quickly I treat each word in my TextArea as a separate object. I know the space I should leave between the lines thanks to the sf::Font::getLineSpacing(characterSize) and I figured out I could get the space I should leave between the words just by getting the width of the "space" Glyph. But...
float space_size = 1.0f * font.getGlyph(0x20, characterSize, false).bounds.width;
float bold_space_size = 1.0f * font.getGlyph(0x20, characterSize, true).bounds.width;
std::cout << "spaces " << space_size << " " << bold_space_size <<std::endl;
...it turns out the space character (0x20) has width of a zero.
Is there a good way of getting the width of a space I should leave between two words? Apart from imperfect ideas such as "getting the width of an 'a' glyph" or "getting width of of two words separated with a space and subtracting the sum of the lengths of the individual words"?
-
The "bounds" member of a glyph is its visual bounding rectangle, so it's normal that it's empty for spaces. You must use the "advance" member instead.
-
...and I missed that in a class with 3 members :evil:
Thanks, Laurent!
-
You should have looked at the source code of sf::Text ;)
-
Yeah, I guess it's a clear sign I should stop treating the libraries I use so intensely like a black box ;)
-
Especially SFML, which has a small, simple and well-written code :mrgreen: