SFML community forums

Help => Graphics => Topic started by: iride on May 26, 2015, 06:05:51 am

Title: making a rectangle enclosing a text
Post by: iride on May 26, 2015, 06:05:51 am
float height = m_text.getFont()->getLineSpacing(m_text.getCharacterSize()) / 2.f;
m_rect.setSize({ m_rect.getSize().x, m_text.getLocalBounds().height + height});
window.draw(m_text); window,draw(m_rect);

when the text has letters it looks fine
(http://i.imgur.com/qxYTGoz.png)

but when the text is just like "..." the rectangle's height is shorter than it should be
(http://i.imgur.com/jJeyzff.png)

how can i solve this issue?
Title: Re: making a rectangle enclosing a text
Post by: dabbertorres on May 26, 2015, 08:19:13 am
Not sure if this will fix it, but sf::Font::getLineSpacing() won't do what you're wanting, I think.
I'd make the height of m_rect simply equal to m_text.getCharacterSize().

That way, you get the actual size of a character, rather than the bounding rectangle (which changes if the text changes).
Title: Re: making a rectangle enclosing a text
Post by: FRex on May 26, 2015, 12:14:39 pm
Bounds rectangle has non zero left and top. I've marked the actual bounds in your second image (with faint red). That should let you understand what's wrong easily.
(http://i59.tinypic.com/90afed.png)