Getting DRY with style - the nifty kinda way :)

Well, no, not “dry” … but “DRY - (D)on’t (R)epeat (Y)ourself” =)

Suppose for some reason you need a lot of red colored panels in your nifty screen. At the moment you’ll need to do something like this:

<panel id="first" backgroundcolor="#f00f"> ... </panel>
<panel id="second" backgroundcolor="#f00f"> ... </panel>
<panel id="third" backgroundcolor="#f00f"> ... </panel>
...
<panel id="fortytwo" backgroundcolor="#f00f"> ... </panel>

So far so good, but what if you change your mind and want green panels instead? Ugly - no, not the color ;) - but you’ll now have to change all this backgroundColor definitions. Quite ugly.

Introducing Nifty Styles
So what we really want, is to specify the color of the panels only one time and use it multiple times.
So with Nifty 0.0.3 you’ll be able to use style definitions to get DRY =)

<style id="my-panel-style">
  <attributes backgroundColor="#f00f"></attributes>
</style>
<panel id="first" style="my-panel-style"> ...</panel>

This way you can define common attributes once and use them multiple times! This principle will be extended to attributes, effects, fonts and so on. This is not only nifty but will naturally lead to UI-skins! Imagine you have all your style definitions in one big “style.xml”. So you could define colors, fonts, effects, etc. once in this file. Changing this single file or including another style.xml whould change your whole UI!

Nifty indeed :)

And still work in Progress too =)

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image