SFML community forums

Help => Graphics => Topic started by: slimmeke on August 07, 2013, 01:53:19 pm

Title: Label and text position does not match
Post by: slimmeke 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?
Title: Re: Label and text position does not match
Post by: Laurent 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.
Title: Re: Label and text position does not match
Post by: slimmeke 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?
Title: Re: Label and text position does not match
Post by: Laurent 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.