callback not triggered

Started by gale, 09 September 2013, 15:58:33

gale

Hi!

My problem is that the code never enter in "while (gui.pollCallback(callback))" part. so buttons and objects never trigger
essential code ( I removed not tgui related parts ):

int main(void)
{
// server - console
sf::RenderWindow window(sf::VideoMode(800, 600), "",sf::Style::Titlebar);
tgui::Gui gui(window);

    if ( !gui.setGlobalFont("fonts/DejaVuSans.ttf") || !gui.loadWidgetsFromFile("widgets/form.txt") )
return 1;

    while (window.isOpen())
    {
        sf::Event _event;
        while (window.pollEvent(_event))
        {
            gui.handleEvent(_event);

tgui::Callback callback;
while (gui.pollCallback(callback))
{
if (callback.id == 1)
window.close();
}

window.clear();
gui.draw();
window.display();
        }
    }

gui.removeAllWidgets();

return 0;
}



form.txt is :

// This file was generated by TGUI Form Builder v0.2.x - 2013.07.04

Window: ""
{
    Button: "btnCloseServer"
    {
        ConfigFile = "widgets/Black.conf"
        Position   = (300,530)
        Size       = (200,50)
        Text       = "CloseServer"
        TextSize   = 27
        TextColor  = (200,200,200)
        CallbackID = 1
    }

    CheckBox: "cbPassword"
    {
        ConfigFile = "widgets/Black.conf"
        Position   = (50,50)
        Size       = (32,32)
        Checked    = 0
        Text       = ""
        TextSize   = 32
        TextColor  = (200,200,200)
        CallbackID = 0
    }

    Label: "lbpass"
    {
        Position         = (50,20)
        Text             = "Server additional pass"
        TextSize         = 20
        TextColor        = (255,255,255)
        BackgroundColor  = (0,0,0,0)
        CallbackID       = 0
    }

    Button: "btnRefreshpass"
    {
        ConfigFile = "widgets/Black.conf"
        Position   = (290,50)
        Size       = (110,30)
        Text       = "Refresh"
        TextSize   = 20
        TextColor  = (200,200,200)
        CallbackID = 2
    }

    EditBox: "ebpass"
    {
        ConfigFile          = "widgets/Black.conf"
        Position            = (90,50)
        Size                = (190,30)
        Text                = ""
        TextSize            = 25
        MaximumCharacters   = 0
        Borders             = (6,4,6,4)
        TextColor           = (200,200,200)
        SelectedTextColor   = (255,255,255)
        SelectedTextBackgroundColor = (10,110,255)
        SelectionPointColor = (110,110,255)
        SelectionPointWidth = 2
        CallbackID          = 0
    }

    Button: "btnOnline"
    {
        ConfigFile = "widgets/Black.conf"
        Position   = (50,130)
        Size       = (116,44)
        Text       = "Online List"
        TextSize   = 0
        TextColor  = (200,200,200)
        CallbackID = 3
    }

}

texus


gale

uhm, so it cant be done.

I immediatly try to do something like :
gui.get("btnName")->setCallbackId(1);

But obviusly nothing happens :)


so widgets wont work without that buildform review. I'll wait to do gui until that time.

thanks for support

texus

The callback id does get set, but it is the binding that doesn't happen.
So in your code you should have this:
gui.get("btnName")->bindCallback(tgui::Button::LeftMouseClicked);

Thats the part that isn't done automatically yet when loading from a file.

texus

Callbacks can now be loaded from widget files.

The widget files need to contain lines like these:
Callback = LeftMouseClicked
CallbackId = 1


You can pass multiple callbacks by placing a comma between them:
Callback = Focused, Unfocused

Also because of how the new form builder is written, you will also be able to change the callbacks from within the form builder.