WIP

A button is a fundamental element of any GUI and at the same time it is easy enough to use as an example for creating themes.

In TWL every widget has states and the Button widget has the following states:

  • keyboardFocus
  • disabled
  • hover
  • pressed
  • armed
  • selected (only for a toggle button / check box etc)
First we need a PNG file which contains images for the various states of a button. Luckily we don't need an image for every combination of states.

button.png

Now we need to load this PNG file and define the areas:

<images file="button.png">
    <area name="-buttonA" xywh="0,0,150,21"/>
    <area name="-buttonB" xywh="150,0,150,21"/>
    <area name="-buttonC" xywh="300,0,150,21"/>
    ....
</images>
These 3 area elements above are now used to represent various button states:
<images file="button.png">
    ....
    <select name="button.background" border="5,0">
        <alias ref="-buttonB" if="armed"/>
        <alias ref="-buttonC" if="hover"/>
        <alias ref="-buttonA"/>
    </select>
</images>
This select element behaves like this pseudo code:
if(armed) {
    draw("-buttonB");
} else if(hover) {
    draw("-buttonC");
} else {
    draw("-buttonA");
}
Now we have an image which we can use in a button theme:
<theme name="button" ref="-defaults">
    <param name="background"><image>button.background</image></param>
    <param name="border"><border>background.border</border></param>
</theme>
This will assign the image we created above as background image for a button widget. It will also use the border we defined on the image as the border for the widget.

Creator: Matthias Mann on 2010/06/08 14:28
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 1.8.17790 - Documentation