SFML community forums

Help => Graphics => Topic started by: Daniel Schreiber Mendes on September 01, 2019, 10:20:48 pm

Title: sf::Text is slightly off
Post by: Daniel Schreiber Mendes on September 01, 2019, 10:20:48 pm
Hello,
I just have a sf::Text named content and want to set its position but it seems to be off about 7 Pixels vertically all the time. What am I doing wrong?
content.setPosition(0, 0);
 
std::cout << content.getPosition().x << ", " << content.getPosition().y << std::endl;
 
gives me (0, 0); thats what it should be.
But it looks like this (ignore the label ):
(https://postimg.cc/cKx2PHck)
I am not changing its position in any way despite the first line. So where does the offset come from?
Thanks for any help!
Title: Re: sf::Text is slightly off
Post by: Laurent on September 02, 2019, 02:38:52 pm
Unlike other drawables, sf::Text aligns its glyphs to its base-line, not to its top. The margin that you see is empty space that could be used by taller glyphs. You can retrieve it in text.getLocalBounds().top, and thus easily adjust the position accordingly if you need to.
Title: Re: sf::Text is slightly off
Post by: Daniel Schreiber Mendes on September 02, 2019, 03:01:07 pm
Ah alright thanks a lot