Easy Problem

Started by SeetyDog, 23 July 2018, 16:57:46

SeetyDog

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

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:
Code (cpp) Select
#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();
   }
}

SeetyDog

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)