Button not showing

Started by Phisn, 07 May 2018, 21:48:16


I'm trying to get a simple button showing but it does not work.
try {
        tgui::Button::Ptr button = tgui::Button::create("Test Button");

        button->setSize(50, 40);
        button->setPosition(0, 0);
        button->connect("pressed", [this]()

    catch (tgui::Exception exception)
        std::cout << exception.what() << std::endl;

I'm sure that all events are handled and gui.draw() is called (loop).


The code itself looks fine.
You should try to minimize the code and show a complete example code.


Thanks, I already solved it. The problem was that I created tgui::Gui before sf::Renderwindow.
But I still have a question, how can I load fonts and Themes from streams instead of a file?


Loading from a stream is currently not directly supported.

I did however change the design in 0.8 a bit to potentially allow it. You can create your own ThemeLoader class (inheriting from BaseThemeLoader and based on what the DefaultThemeLoader does) and set it with Theme::setThemeLoader.
The theme file currently contain a filename of the font which is then passed to the Deserializer class. If you want to load it from a stream then you would have to overwrite the deserializer via "Deserializer::setFunction(ObjectConverter::Type::Font, func)". The string inside the theme file is passed as parameter to the func.
The same might work for textures, although Texture::setImageLoader might be needed as well.

So if you really want you could add support for it yourself. If someone adds support and shares the code then I'd gladly have a look if it can be merged into TGUI. But it is unlikely that I will write the code myself in the near future.