Label Widget Not showing up when Compiling
« on: 13 April 2014, 02:02:11 »
Hi, I was told to come here because of the GUI objects I was after, I have successfully installed TGUI and everything is loading fine, but when I load the Label of the Login Tutorial with a few changes, the Text for the "Username" and "Password" doesnt show up, any ideas?

Code: [Select]
#include <TGUI/TGUI.hpp>

void loadWidgets(tgui::Gui& gui)
{
    // Create the background image
    tgui::Picture::Ptr picture(gui);

    // Create the username label
    tgui::Label::Ptr labelUsername(gui);
    labelUsername->load("data/TGUI/widgets/White.conf");
    labelUsername->setText("Username:");
    labelUsername->setPosition(70,60);

    // Create the password label
    tgui::Label::Ptr labelPassword(gui);
    labelPassword->setText("Password:");
    labelPassword->setPosition(70,100);

    // Create the username edit box
    tgui::EditBox::Ptr editBoxUsername(gui, "Username");
    editBoxUsername->load("data/TGUI/widgets/White.conf");
    editBoxUsername->setSize(170,27);
    editBoxUsername->setPosition(140,58);

    // Create the password edit box (we will copy the previously created edit box)
    tgui::EditBox::Ptr editBoxPassword = gui.copy(editBoxUsername, "Password");
    editBoxPassword->setPosition(140, 100);
    editBoxPassword->setPasswordCharacter('*');

    // Create the login button
    tgui::Button::Ptr button(gui);
    button->load("data/TGUI/widgets/White.conf");
    button->setSize(80, 22);
    button->setPosition(140,140);
    button->setText("Login");
    button->bindCallback(tgui::Button::LeftMouseClicked);
    button->setCallbackId(1);

    // Create the register button
    tgui::Button::Ptr regbutton = gui.copy(button, "Register");
    regbutton->setPosition(230, 140);
    regbutton->bindCallback(tgui::Button::LeftMouseClicked);
    regbutton->setCallbackId(1);
}

int main()
{
    // Create the window
    sf::RenderWindow window(sf::VideoMode(422, 250), "TGUI window");
    tgui::Gui gui(window);

    // Load the widgets
    loadWidgets(gui);

    // Main loop
    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
            gui.handleEvent(event);
        }

        // The callback loop
        tgui::Callback callback;
        while (gui.pollCallback(callback))
        {
            // Make sure tha callback comes from the button
            if (callback.id == 1)
            {
                // Get the username and password
                tgui::EditBox::Ptr editBoxUsername = gui.get("Username");
                tgui::EditBox::Ptr editBoxPassword = gui.get("Password");

                sf::String username = editBoxUsername->getText();
                sf::String password = editBoxPassword->getText();

                // Continue here by checking if the username and password are correct ...
            }
        }

        window.clear(sf::Color::White);

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

        window.display();
    }

    return EXIT_SUCCESS;
}

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Label Widget Not showing up when Compiling
« Reply #1 on: 13 April 2014, 11:08:20 »
You forgot to load a font.

Add this after creating the gui:
Code: [Select]
gui.setGlobalFont("data/TGUI/fonts/DejaVuSans.ttf");
I had to add that to even get the text in the buttons and editbox to show up.

But on top of this, the labels are white, so is your background. So also try changing the text color:
Code: [Select]
labelUsername->setTextColor(sf::Color::Black);