Undocumented feature: Styles (1 Viewer)

Sambal

Portal Pro
February 4, 2008
144
144
Home Country
Netherlands Netherlands
I was looking for a way to specify global style definitions. You can include a common xml for Controls used the same way on different pages. But what if you want the same styling applied to other controls? You'll end up specifying the same style multiple times. If you change your mind about a certain color later on it is a lot of work to change it all over your skin.

references.xml provides a place to specify default values for control properties. I wanted something like that so i read the wiki part about references.xml. It says the following:
It can also defines styles that can be applied to any control although this feature is not covered in this document.
Sounds promising! So i looked at the MediaPortal sources and found a great but undocumented feature called styles.
Here's how you can use it.

It is possible to define named styles in the references.xml file. You can apply this named style to any Control in your other skin files.

Note: below code blocks are not php code they are xml but i like the syntax highlighting :)

Imagine we want to use a lot of big red text on our screens ( Don't be surprised if you come back to this decision later on :p )

Define a global style named 'Heading1' or some other descriptive name. Every Control we apply 'Heading1' to should have font24 and a red textcolor. You can add as many styles as you need. And you are not limited to just font and color as i used here.
PHP:
// references.xml
<controls>
  <skin>
      ...
  </skin>
  <style Name="Heading1">
	<font>font24</font>
	<textcolor>red</textcolor>
  </style>
  <control>
      ...
Please not that xml attributes are case sensitive, this means 'Name' should be 'Name' and not 'name' or 'nAme'. Same goes for 'Style'!!

Now everywhere you want to use this style you can apply it as shown below
PHP:
    <control Style="Heading1">
      <description>Top title</description>
      <type>label</type>
      <label>This is our title</label>
    </control>

This label is shown big and red.

Styles do not override properties defined in the Control itself. If you specified another font for this label it would show using that font and not the one you defined in the style. The style only provides default values!

I think this can be of great use to guarantee a uniform look throughout a skin.

Happy Skinning,

Sambal
 

Users who are viewing this thread

Top Bottom