PatateDev / sfml-ui

A simple UI library for SFML
GNU Lesser General Public License v3.0
11 stars 1 forks source link

Invalid button size #6

Closed mathdu07 closed 10 years ago

mathdu07 commented 10 years ago

When a button is set with an empty texture, the size is set to 0. Then, even if the texture is loaded after, the size stay to 0.

Code : sf::Texture text1, text2, text3; sf::ui::Button button(text1, text2, text3); std::cout << "Button size : " << button.getSize().x << ";" << button.getSize().y << std::endl; //Equals to 0;0, OK text1.loadFromFile("texture.png"); text2.loadFromFile("texture.png"); text3.loadFromFile("texture.png"); std::cout << "New Button size : " << button.getSize().x << ";" << button.getSize().y << std::endl; //Equals to 0;0, Should equals to texture's size

mathdu07 commented 10 years ago

Calling the function updateSize() after loading a texture fix the issue

Code: sf::Texture text1, text2, text3; sf::ui::Button button(text1, text2, text3); std::cout << "Button size : " << button.getSize().x << ";" << button.getSize().y << std::endl; //Equals to 0;0, OK text1.loadFromFile("texture.png"); text2.loadFromFile("texture.png"); text3.loadFromFile("texture.png"); button.updateSize(); std::cout << "New Button size : " << button.getSize().x << ";" << button.getSize().y << std::endl; //Now equals to texture's size