Page 1 of 1

Using variables in .layout files

Posted: Wed Aug 03, 2011 12:33
by rrees
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.

Re: Using variables in .layout files

Posted: Thu Aug 04, 2011 00:16
by Jamarr
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.

Re: Using variables in .layout files

Posted: Thu Aug 04, 2011 01:24
by ShadowTiger
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.

Re: Using variables in .layout files

Posted: Thu Aug 04, 2011 10:44
by Kulik
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.

Re: Using variables in .layout files

Posted: Thu Aug 04, 2011 16:19
by Jamarr
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 ;)