Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Label and text position does not match  (Read 1142 times)

0 Members and 1 Guest are viewing this topic.

slimmeke

  • Guest
Label and text position does not match
« on: August 07, 2013, 01:53:19 pm »
Hey guys

I'm writing a game engine for my new game with SFML (2.1). But when I writing my Label class (label with background) I got a problem.

You can see the problem in the attachment.
The position of the text is not the same then the position of the Background RectangleShape.
And the positions are the same

void Label::setPosition(float x, float y)
{
        background_.setPosition(x, y);
        text_.setPosition(x, y);
}

Is this normal that the position of a Text object is not the same as a position of a RectangleShape?
What can I do to fix this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Label and text position does not match
« Reply #1 on: August 07, 2013, 01:59:01 pm »
Texts will always have a small margin at the top. This is because they are aligned on the baseline, not on the top.

So the rectangle and text are at the same position; it's just that the text has this small margin on top.
Laurent Gomila - SFML developer

slimmeke

  • Guest
Re: Label and text position does not match
« Reply #2 on: August 07, 2013, 02:01:40 pm »
I didn't know that.

Is this a fixed margin or is this a margin related with the chars size?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Label and text position does not match
« Reply #3 on: August 07, 2013, 02:08:12 pm »
The size between the baseline and the top is fixed. So the margin depend on the size of the characters.
Laurent Gomila - SFML developer