So I'm trying to make a button but I can't resize and center the text because both getLocalBounds and getGlobalBounds are returning 0. Here is the code:
void Button::setString(sf::String string)
{
m_string = string;
m_text.setString(m_string);
std::cout << m_text.getGlobalBounds().width; //This returns 0
}
m_text is a private sf::Text variable.
The text is drawn on the screen, the setChar size method works as well. The only thing that isn't right here is that getGlobalBounds().width/height and getLocalBounds().width/height always return 0.
I think I found the problem. If I load the font inside the button constructor like this it works:
m_font.loadFromFile("data/font3.ttf");
m_text.setFont(m_font);
But I can't find a good solution to use the gui.setGlobalFont(font) properly. If you have any ideas please let me know. Thank you!