Using variables in .layout files

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

rrees
Just popping in
Just popping in
Posts: 1
Joined: Wed Aug 03, 2011 12:12

Using variables in .layout files

Postby rrees » Wed Aug 03, 2011 12:33

Hey. I was wondering how I would go about not using "magic numbers" for positioning interface elements in the layout files. Is there a way to use variables in .layout files to specify property values? For example, If i have a static text that I am positioning using:
<Property Name="UnifiedAreaRect" Value="{{0.1,0},{0.1,0},{0.9,0},{0.29,0}}" />

Am I able to define variables so I can instead type something along the lines of:
variable1 = 0.1
variable2 = 0.1
variable3 = 0.9
variable4 = 0.29
Static Text 1....
<Property Name="UnifiedAreaRect" Value="{{variable1,0},{variable2,0},{variable3,0},{variable4,0}}" />

Furthermore, is it possible to modify these variables after existence? For example equivalent to:
variable2 += 0.1
variable4 += 0.1
Static Text 2....
<Property Name="UnifiedAreaRect" Value="{{variable1,0},{variable2,0},{variable3,0},{variable4,0}}" />

...resulting in the second text being placed below the first text. This would allow switching many text positions or adding new texts very easily instead of having to modify all the "magic numbers" for each position over and over again.

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Using variables in .layout files

Postby Jamarr » Thu Aug 04, 2011 00:16

No to both. At least not to my knowledge.

You may want to take a look at Layout Containers (note that these can be used .layout files as well, ex here) which were added in v0.7.2. These may not fit your needs perfectly but should get you pretty close. Also note that these containers have planned updates for v0.8, so if you have any concerns/needs feel free to make suggestions.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

ShadowTiger
Quite a regular
Quite a regular
Posts: 46
Joined: Fri Mar 19, 2010 05:31

Re: Using variables in .layout files

Postby ShadowTiger » Thu Aug 04, 2011 01:24

Heres two ways that you can do it.

1) Create a script or small program that will let you edit the layout file. Then you can have a text file with all the variables, and have your program substitute the values.

2) Create your windows using C++ instead of the layout file. This is what I do. If you don't need the flexibility to change your windows without recompiling your program, this will obviously allow you to use variables and to create for loops to create windows and such.

In my project we actually created a tool that creates c++ code automatically for static elements and then I use loops and such for the dynamic elements. If your project is large enough in scope I suggest doing something like this.

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Using variables in .layout files

Postby Kulik » Thu Aug 04, 2011 10:44

I actually suggested exactly this feature but for looknfeels, perhaps it can be done for all CEGUI assets.

However designing it properly is hard, I don't want a simple preprocessor since that would be hard to deal with in visual tools, I will think about it further.

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Using variables in .layout files

Postby Jamarr » Thu Aug 04, 2011 16:19

ShadowTiger wrote:Create your windows using C++ instead of the layout file. This is what I do. If you don't need the flexibility to change your windows without recompiling your program, this will obviously allow you to use variables and to create for loops to create windows and such. In my project we actually created a tool that creates c++ code automatically for static elements and then I use loops and such for the dynamic elements. If your project is large enough in scope I suggest doing something like this.


or you could just use Lua ;)
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 7 guests