I want to add a button to my window.

Started by Nabeel Nazir, 08 September 2013, 15:54:26

Nabeel Nazir

I am using this code from your tutorials , but its not working , it is saying that there is no addbutton() function
tgui::Button* button = window.addButton();
button->load("TGUI/objects/Button/Black");
button->setText("example button");
button->setSize(200, 50);
button->setPosition(100, 50);


, please help me ! :(

texus

Where did you find that code exactly? That is code for tgui v0.4, while you are either using v0.5 or v0.6.

tgui v0.5:
Code (cpp) Select
tgui::Button* button = window.add<tgui::Button>();
button->load("TGUI/objects/Button/Black");


tgui v0.6:
Code (cpp) Select
tgui::Button::Ptr button(gui);
button->load("TGUI/widgets/Black.conf");


texus

Ah, thanks for pointing that out. Its a small mistake in the tutorial (the tutorials were written while v0.5 was still being changed and it seems like I forgot to update that part of the tutorial after changing the add function).
It has been fixed now.

You should put most trust in the example code, it was updated more regulary.

Nabeel Nazir

#4


#include <SFML/window.hpp>
#include <SFML/system.hpp>
#include <SFML/audio.hpp>
#include <SFML/graphics.hpp>
#include <TGUI/TGUI.hpp>
//#include <SFML/Video.hpp>
//#include <conio.h>

//#include <iostream>

int main()
{
    // Create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
    tgui::Gui gui(window);

    // Load the font (you should check the return value to make sure that it is loaded)
    gui.setGlobalFont("C:/Users/corleone/Documents/Visual Studio 2010/Projects/MySfml/MySfml/TGUI-0.6-alpha2-Visual-C++10-2010-32-bits/TGUI-0.6-alpha2/fonts/DejaVuSans.ttf");

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

            // Pass the event to all the widgets (if there would be widgets)
            gui.handleEvent(event);
        }

        //window.clear();

        // Draw all created widgets
        gui.draw();

tgui::Button::Ptr button(gui);
button->load("C:/Users/corleone/Documents/Visual Studio 2010/Projects/MySfml/MySfml/TGUI-0.6-alpha2-Visual-C++10-2010-32-bits/TGUI-0.6-alpha2/widgets/Button/BabyBlue/Normal.conf");

        window.display();
   








}
return EXIT_SUCCESS;
}



:(