Button not showing
« on: 07 May 2018, 21:48:16 »
I'm trying to get a simple button showing but it does not work.
Code: [Select]
try {
        tgui::Button::Ptr button = tgui::Button::create("Test Button");

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

        gui.add(button);
    }
    catch (tgui::Exception exception)
    {
        std::cout << exception.what() << std::endl;
    }

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

*

texus

  • *****
  • 1254
    • View Profile
    • Texus's Blog
Re: Button not showing
« Reply #1 on: 07 May 2018, 22:07:22 »
The code itself looks fine.
You should try to minimize the code and show a complete example code.
« Last Edit: 07 May 2018, 22:09:18 by texus »

Re: Button not showing
« Reply #2 on: 08 May 2018, 16:41:17 »
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?

*

texus

  • *****
  • 1254
    • View Profile
    • Texus's Blog
Re: Button not showing
« Reply #3 on: 08 May 2018, 18:34:19 »
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.