changing theme files
« on: 16 October 2014, 14:06:47 »
I read this on your blog
Quote
Thinking about a new design...

// Load one theme that is shared between widgets
tgui::Theme theme{"Black.conf"};

// Create widgets based on that theme
auto button = tgui::Button::create(theme);

// Change the theme for all connected widgets on the fly
theme->changeProperty("Button", "TextColorNormal", "(200, 200, 200)");

Wow, this sounds good. What would happen if I create an element with a theme object and later I want to change a property on this element only? Reminds me a little of the setGlobalTextSize() issues.

A short user story how I use tgui:
I have several game states (startup, main menu, game lobby, game room, ..). No two states can be active at the same time. I share a global tgui::gui between all states. When a new state is transitioned into, all widgets get removed from the global tgui::gui and the specific state widgets get reloaded.
Each state has it's own gui elements and it's own theme.conf. On state creation I load everything with element::create("myState.conf") and hide() and show() and connect() accordingly. Then on some elements, I change properties via getRenderer() because I didn't want an extra theme.conf for a single Button. Sometimes gui elements need to be created dynamically. That is, when game objects offer to be configured. These objects have a tgui::Widget::Ptr getConfigWidget() interface and the state loops over the objects to get the widgets and add them to the tgui::gui.

« Last Edit: 16 October 2014, 14:10:53 by Heinrich »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: changing theme files
« Reply #1 on: 16 October 2014, 15:27:21 »
Quote
What would happen if I create an element with a theme object and later I want to change a property on this element only?
If you change the theme then it changes on all widgets. But currently the plan is to duplicate the theme on a getRenderer call. So when you do "button->getRenderer()->setXyz(xyz);" then the theme is cloned and the change is made in the theme of that one button. Any changes to the original theme will no longer affect the button.

But this is not something you should worry about. I actually don't have the time to add features, especially as big as the theme rewrite. The exact way of how the themes and renderer classes work together hasn't been decided and I'm still far away from actually implementing this Theme class.

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: changing theme files
« Reply #2 on: 16 October 2014, 17:58:39 »
Looks like a serious project. It's good to see how some people use tgui, that way I can try to keep everything compatible or even make things easier when I rewrite a big part of my gui.

Quote
Then on some elements, I change properties via getRenderer() because I didn't want an extra theme.conf for a single Button
The Theme class would simply contain the same contents as the .conf files. So you would just have to make a changeProperty call on the theme before you pass it to the widget instead of needing an entirely different file where only one line has changed. The renderer could perhaps be kept internally and no longer needed directly. But it's too early to think about that.

Just in case you didn't know this yet: in v0.7 you don't need a separate file for every button. You can have multiple sections for buttons (or other widgets), just give them a name other than the default "Button" and pass the name as second parameter of the Button::create function.

Re: changing theme files
« Reply #3 on: 17 October 2014, 01:31:51 »
Just in case you didn't know this yet: in v0.7 you don't need a separate file for every button. You can have multiple sections for buttons (or other widgets), just give them a name other than the default "Button" and pass the name as second parameter of the Button::create function.

I didn't. That's pretty handy.