Easy Problem
« on: 23 July 2018, 16:57:46 »
Hello, I am having trouble with the bare minimum code. I have SFML 2.5 properly set up and linked along with TGUI 0.8 properly linked->using the linking tutorial (both dynamically (dlls are in right folder))I did not need to CMAKE and I am using vs2017. SFML test code works fine, per usual. However, I am trying to test if TGUI is properly installed and linked. I cannot see the gui when I compile this minimum code found on the 0.8 tutorial section. This is my first time using TGUI, just need a little help getting started. Thanks

#include <TGUI/TGUI.hpp>
int main(){
   sf::RenderWindow window{sf::VideoMode(1024, 760), "Window" };
   tgui::Gui gui(window);

   while (window.isOpen()){
      sf::Event event;
      while (window.pollEvent(event)){
         gui.handleEvent(event);
         if (event.type == sf::Event::Closed)
            window.close();
      }
      window.clear();
      gui.draw();
      window.display();
   }
   return 0;}// again this code compiles fine, shows the sfml window, but there is nothing else. Just a
                      //blank SFML window :(

*

texus

  • *****
  • 1279
    • View Profile
    • Texus's Blog
Re: Easy Problem
« Reply #1 on: 23 July 2018, 18:17:57 »
The code you showed doesn't actually do anything other than create a blank window. It initializes the gui but doesn't add anything to the gui to show. You still need to add a widget to the gui in order to have something drawn on top of the SFML window. But if that code runs then TGUI has been setup correctly.

Try running something like this to display a button on the screen:
#include <TGUI/TGUI.hpp>
#include <iostream>

int main()
{
   sf::RenderWindow window{sf::VideoMode(1024, 760), "Window" };
   tgui::Gui gui(window);

   auto button = tgui::Button::create("Click me");
   button->connect("pressed", []{ std::cout << "Button was pressed" << std::endl; });
   gui.add(button);

   while (window.isOpen())
    {
      sf::Event event;
      while (window.pollEvent(event))
      {
         gui.handleEvent(event);
         if (event.type == sf::Event::Closed)
            window.close();
      }
      window.clear();
      gui.draw();
      window.display();
   }
}

Re: Easy Problem
« Reply #2 on: 23 July 2018, 18:48:36 »
That makes total sense. I added the code and it compiles, giving me the "Click me" button at the top right corner. Thank you very much texus. 8)