Converting TGUI 0.6 project to TGUI 0.8.5

  • 1 Replies
  • 29 Views
Converting TGUI 0.6 project to TGUI 0.8.5
« on: 11 August 2019, 04:14:03 »
So a while back I was working on something using TGUI 0.6 and now i'd like to move onto TGUI 0.8 only grabbing the basic import and event setup.

However, as there is still documentation missing. I'm not sure how to do this.

Should i really go back to 0.6 ?  :-\

i've attached the source of the old project after removing parts that were too similar.

*

texus

  • *****
  • 1414
    • View Profile
    • Texus's Blog
Re: Converting TGUI 0.6 project to TGUI 0.8.5
« Reply #1 on: 11 August 2019, 09:55:18 »
You would basically just have to read the 0.8 tutorials and relearn how widgets are created now and rewrite the code that deals with the gui.
If you don't want to rewrite your code then you will have to stick with 0.6, there have been 4 active years between those two version so a lot has changed (with most of the changes between 0.6 and 0.7).

Looking at the code you basically need the following changes:

Lines like
tgui::Checkbox::Ptr syncbox(gui);
basically have to be changed to
tgui::Checkbox::Ptr syncbox = tgui::Checkbox::create();  // You could use "auto" as type here, to not write "Checkbox" twice
gui.add(syncbox);

In 0.6 I think you still had to have a theme to render something, since 0.7 there actually is a default White theme that gets used if you don't set any theme. I'll just assume you want to keep using the Black theme. You will have to change THEME_CONFIG_FILE to "data/themes/Black.txt" as that is where the new Black theme would be located.

For the Black theme you will have to create a Theme object somewhere. Assuming you only use a single theme you can set it as a default as well. The "theme" object has to remain alive, if the variable is destructed (e.g. when it goes out of scope) then the built-in White theme will automatically be used again.
tgui::Theme theme{THEME_CONFIG_FILE};
tgui::Theme::setDefault(&theme);
If you have a default theme that you want to use then you can just remove lines like
syncbox->load(THEME_CONFIG_FILE);
If you don't have a default theme, then you need to replace the lines with something like
syncbox->setRenderer(theme.getRenderer("CheckBox"));

The biggest difference is probably going to be the callback code. TGUI 0.6 queued callbacks and let you get them later with pollCallback. (This code is so old that I had already forgotten that it used to work like that). Since TGUI 0.7 the callbacks are like interrupts, your callback function will be called immediately. You should definitely read the signal tutorial.
How you need to change the code depends on the structure of your code. If your code is really all in one big main function, then you should actually be able to port it without too much changes.
knob1->bindCallback(tgui::Knob::ValueChanged);
knob1->setCallbackId(Knob_CALLBACK_ID + 1);
and
case Knob_CALLBACK_ID + 1:
{
        [...]
        break;
}
would become
knob1->connect("ValueChanged", [&]{
    [...]
});

Those are just the differences that I saw when scrolling to the code. It is possible that there are other differences, but the biggest changes happened in the way widgets are created and their events. The functions of the widgets themselves (e.g. setPosition, addItem, setSelectedItem, etc.) will mostly be compatible.