Req Suggestion: Include directive with parameters
#46
It's more general. What you get is the ability to pass arbitrary parameters to your includes and then use these values anywhere within the include body. Just so you don't have to copy/paste huge chunks of XML anymore in order to change just a value or two. Includes are now roughly equivalent to "procedures" in programming languages. Here's the final syntax that has been included in Kodi.

Include definitions are still written within <includes> tag, usually in includes.xml. But they can now accept parameters:

Code:
<include name="MyControl">
    <param name="id"/>
    <param name="left" default="120"/>
    <param name="top">225</param>
    <definition>
        <control type="image" id="$PARAM[id]">
            <left>$PARAM[left]</left>
            <top>$PARAM[top]</top>
            <width>370</width>
            <height>40</height>
            <texture>foo.png</texture>
        </control>
    <definition>
</include>

Here, the first part is called parameter list and is specified using <param> tags. When it is present, include body that follows it should be enclosed within <definition> tag. At the moment, parameter list is optional and is mainly used for specifying default values for parameters (such as 120 and 225 above), but is otherwise not mandatory.

The above include can be called like this:

Code:
<include name="MyControl">
    <param name="id" value="52"/>
    <param name="left">300</param>
</include>

This has the exact same effect as if you've written this instead:

Code:
<include name="MyControl">
    <control type="image" id="52">
        <left>300</left>
        <top>225</top>
        <width>370</width>
        <height>40</height>
        <texture>foo.png</texture>
    </control>
</include>

and called it (old-style) like this:

Code:
<include>MyControl</include>

only without added benefits.

Any appropriate value can be passed as parameter in the new include call, including $INFO labels, $LOCALIZE, $VARs, constants, etc. Empty string (value="") can also be passed, for example to override a non-empty default value set in the include definition.

Default values are used as replacement when their parameters are not passed in the include call.

$PARAM references can be specified within both tag values and attributes inside include body, and are expanded to either actual value passed (if it was passed), default value (if set) or empty string, in that order.

Parameters without default values (such as id above) are specified for better readability and documentation purposes only, but are otherwise not necessary and can be omitted. This is really a matter of style, and some skinners might prefer writing explicit parameter lists to specify all parameters referenced in the include body. It's a good practice though, as explicit parameter lists might be better utilized in the future versions of Kodi.

If there are no <param> tags at all, <definition> can be omitted too. This leads to even shorter syntax:

Code:
<include name="MyControl">
    <control type="image" id="$PARAM[id]">
        <left>$PARAM[left]</left>
        <top>$PARAM[top]</top>
        <width>370</width>
        <height>40</height>
        <texture>foo.png</texture>
    </control>
</include>

Includes can call other (nested) includes and even pass them exact parameter values that they've got themselves. This is called parameter forwarding.

Code:
<include name="MyControl">
    ...
    <include name="MyOtherControl">
        <param name="label">$INFO[Player.Title]</param>
        <param name="label2" value="x:$PARAM[left]; y:$PARAM[top]"/>
        <param name="color" value="$PARAM[color]"/>     <!-- forwarding -->
        <param name="id" value="$PARAM[scrollbarid]"/>  <!-- forwarding -->
    </include>
    ...
</include>

Here, $PARAM[color] and $PARAM[scrollbarid] will be forwarded to MyOtherControl only if parameters color and scrollbarid have actually been passed to MyControl, otherwise the default values for color and id (if set in MyOtherControl) will be used instead in the body of MyOtherControl. Composite values containing other characters (such as label2) are not considered as "true" forwarding and always override any default value set in the nested include, even when they expand to empty strings.
Reply
#47
Amazing ! So lets talk about concrete case ...
I'm placing blocs in a 3X3 grid (you can check sshots in ma skin dev thread)
I'm using animations now since I wasn't able to pass through the adaptive <posx> <posy>, etc.

I can finally use this instead :

DEFINITION

Code:
<include name="MyBlocPosition">
    <definition>
            <left>$PARAM[posx]</left>
            <top>$PARAM[posy]</top>
            <width>$PARAM[width]</width>
            <height>$PARAM[height]</height>
    <definition>
</include>

CALL :

Code:
<include name="MyBlocPosition">
    <param name="posx">$VAR[PosX]</param>
    <param name="posy">$VAR[PosY]</param>
    <param name="width">$VAR[SizeX]</param>
    <param name="height">$VAR[SizeY]</param>
</include>


Am I right ?
[Skin] KOver - V1.1.0 Stable (Repo version)
[WIP] ReKOver - Skinning tool project

If I've been helpful or you like my work, hit "THANK USER" button ;) ...
Reply
#48
keep in mind: there is no need to use the definition element inside an include definition if you don't have a parameter list (defaults) defined there.

Code:
<include name="MyBlocPosition">
  <left>$PARAM[posx]</left>
  <top>$PARAM[posy]</top>
  <width>$PARAM[width]</width>
  <height>$PARAM[height]</height>
</include>

This is enough.
Reply
#49
(2015-04-04, 12:23)xhaggi Wrote: keep in mind: there is no need to use the definition element inside an include definition if you don't have a parameter list (defaults) defined there.

Code:
<include name="MyBlocPosition">
  <left>$PARAM[posx]</left>
  <top>$PARAM[posy]</top>
  <width>$PARAM[width]</width>
  <height>$PARAM[height]</height>
</include>

This is enough.
Got it. Excellent ! I'm gone for the week-end but I'll give it try on monday. This looks like a full rewrite and intensive use of it. Thank you guys to bring us this. Awesome perspectives.
[Skin] KOver - V1.1.0 Stable (Repo version)
[WIP] ReKOver - Skinning tool project

If I've been helpful or you like my work, hit "THANK USER" button ;) ...
Reply
#50
Well didn't get it to work. Here is what I used :

Include.xml :
Code:
    <variable name="B1CoordX">
        <!-- Configuring Horizontal Positioning -->
        <value condition="StringCompare(Container.ViewMode,$LOCALIZE[535]) + Skin.String(View1.B1CoordX,A) + Skin.String(View1.BBSizeX,3COLUMN) + Skin.String(View1.BBSepX,NONE)">6</value>
        ...
    </variable>
    <variable name="B1CoordY">
        <!-- Configuring Vertictal Positioning -->
        <value condition="StringCompare(Container.ViewMode,$LOCALIZE[535]) + Skin.String(View1.B1CoordY,A) + Skin.String(View1.BBSizeY,3ROW) + Skin.String(View1.BBSepY,NONE)">6</value>
        <value condition="StringCompare(Container.ViewMode,$LOCALIZE[535]) + Skin.String(View1.B1CoordY,B) + Skin.String(View1.BBSizeY,3ROW) + Skin.String(View1.BBSepY,NONE)">362</value>
        ...
    </variable>
    <variable name="B1SizeX">
        <!-- Configuring Horizontal Size -->
        <value condition="StringCompare(Container.ViewMode,$LOCALIZE[535]) + Skin.String(View1.B1SizeX,3COLUMN)">1908</value>
        <value condition="StringCompare(Container.ViewMode,$LOCALIZE[535]) + Skin.String(View1.B1SizeX,2COLUMN)">1272</value>
        <value>636</value>
    </variable>        
    <variable name="B1SizeY">
        <!-- Configuring Horizontal Size -->
        <value condition="StringCompare(Container.ViewMode,$LOCALIZE[535]) + Skin.String(View1.B1SizeY,3ROW)">1068</value>
        <value condition="StringCompare(Container.ViewMode,$LOCALIZE[535]) + Skin.String(View1.B1SizeY,2ROW)">712</value>
        <value>356</value>
    </variable>        

<!-- Blocs configurator -->
    <include name="B1Conf">
        <left>$PARAM[posx]</left>
        <top>$PARAM[posy]</top>
        <width>$PARAM[sizex]</width>
        <height>$PARAM[sizey]</height>
    </include>

Viewtype50.xml :

Code:
    <include name="B1Conf">
        <param name="posx">$VAR[B1CoordX]</param>
        <param name="posy">$VAR[B1CoordY]</param>
        <param name="sizex">$VAR[B1SizeX]</param>
        <param name="sizey">$VAR[B1SizeY]</param>
    </include>

Always getting Coord : 0,0 Size : 1920x1080.
My Skin Strings are OK, tested with animation positioning. Tried without ViewMode check, same result.
Asking myself if the feature is already usable in 15 alpha 2 ?
[Skin] KOver - V1.1.0 Stable (Repo version)
[WIP] ReKOver - Skinning tool project

If I've been helpful or you like my work, hit "THANK USER" button ;) ...
Reply
#51
You're missing the value attribute.
See this pr for example code in Confluence.
Reply
#52
(2015-04-05, 18:21)BigNoid Wrote: You're missing the value attribute.
See this pr for example code in Confluence.
If you mean using this syntax :

Code:
    <include name="B1Conf">
        <param name="posx" value="$VAR[B1CoordX]" />
        <param name="posy" value="$VAR[B1CoordY]" />
        <param name="sizex" value="$VAR[B1SizeX]" />
        <param name="sizey" value="$VAR[B1SizeY]" />
    </include>

... tried it but no success ...
[Skin] KOver - V1.1.0 Stable (Repo version)
[WIP] ReKOver - Skinning tool project

If I've been helpful or you like my work, hit "THANK USER" button ;) ...
Reply
#53
If the syntax is correct then the values must be wrong. Put the variables in a label to see what their value is. Btw, includes do not get checked again when the view is changed, so not sure if what you are trying here is gonna work out. even if the initial value is correct.
Reply
#54
(2015-04-05, 20:26)BigNoid Wrote: If the syntax is correct then the values must be wrong. Put the variables in a label to see what their value is. Btw, includes do not get checked again when the view is changed, so not sure if what you are trying here is gonna work out. even if the initial value is correct.

Values checked and return status is OK ... Don't know what's wrong. Var is not taken even whithout changing view after MyVideoNav.xml loaded. Moved the bloc directly in MyVideoNav.xml to skip the viewtype ... same result.

EDIT : also tried to set variables values as $NUMBER[xx]
EDIT2 : Replaced $VAR[xx] directly by the numeric value it contains and works fine. Seems that $VAR is not resolved first. Using $VAR in param acts like not using an include and write

Code:
<posx>$VAR[xx]</posx>

... which normally fails. At least for posx / posy / width / height.
[Skin] KOver - V1.1.0 Stable (Repo version)
[WIP] ReKOver - Skinning tool project

If I've been helpful or you like my work, hit "THANK USER" button ;) ...
Reply
#55
Well, of course, includes are really just a copy/paste mechanism that is evaluated only once. Everything is passed as is, only $PARAM references are resolved. In the end, final included body still needs to be valid skin XML -- you cannot use $VARs where you normally wouldn't be able to.
Reply
#56
(2015-04-06, 12:38)rahotep Wrote: Well, of course, includes are really just a copy/paste mechanism that is evaluated only once. Everything is passed as is, only $PARAM references are resolved. In the end, final included body still needs to be valid skin XML -- you cannot use $VARs where you normally wouldn't be able to.
I had good hopes in this. Since $PARAM solved first, thought I could pass through the positioning / sizing $VAR fail. Already managed to fake the $VAR stringcompare fail by replacing them in a list item Property so ... Had to try. Seems that dynamic Positioning / Sizing is still not for today. Would be great to see this coming Wink Not so important since I have the animations working but ... Request more code lines and not as clean as using dynamic positioning. However good job on this. Will see how to integrate it elsewhere in the code.
[Skin] KOver - V1.1.0 Stable (Repo version)
[WIP] ReKOver - Skinning tool project

If I've been helpful or you like my work, hit "THANK USER" button ;) ...
Reply
#57
i've done some tests and using a $VAR as value for a parameter works fine for me.

Definition:
Code:
<variable name="TestVar">
  <value condition="Window.IsActive(home)">Home</value>
  <value>Not Home</value>
</variable>

<include name="TestInclude">
  <control type="label">
    <left>0</left>
    <top>0</top>
    <width>1280</width>
    <label>$PARAM[Label]</label>
    <align>center</align>
  </control>
</include>

Usage (will output "Home" if you put it in your Home.xml otherwise "Not Home"):
Code:
<include name="TestInclude">
  <param name="Label" value="$VAR[TestVar]" />
</include>

I've also checked the corresponding source code and we resolve the includes (with/without parameters) first and process the complete xml (info vars etc.) after that.
The parameter replacement only replaces $PARAM[xxxx] with the corresponding value e.g. $VAR[xxx]. The result will looks like:

Code:
<control type="label">
  <left>0</left>
  <top>0</top>
  <width>1280</width>
  <label>$VAR[TestVar]</label> <!-- this $VAR will be resolved as every other $VAR placed directly in the XML e.g. Home.xml -->
  <align>center</align>
</control>
Reply
#58
just for clarification: Will it pass the "real" Variable, or does it use the fixed variable value from include time?
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#59
(2015-04-07, 12:28)xhaggi Wrote: i've done some tests and using a $VAR as value for a parameter works fine for me.

Seems to be logic. As I understand, the new include procedure doesn't allow to pass through what the skinning engine normally doesn't.

If we don't consider the new include, $VAR works for <label>, <texture>, and as I discovered, <property> tags. It won't work for <posx>, <posy>, <width>, <height> tags, etc. Neither for StringCompare, etc.

So if those don't work outside the include, it won't in $PARAM. Still don't know why $VAR is not universal in the skinning engine but there should be a reason.
[Skin] KOver - V1.1.0 Stable (Repo version)
[WIP] ReKOver - Skinning tool project

If I've been helpful or you like my work, hit "THANK USER" button ;) ...
Reply
#60
(2015-04-07, 19:46)phil65 Wrote: just for clarification: Will it pass the "real" Variable, or does it use the fixed variable value from include time?

The $PARAM[xxx] will be replaced at construction of the window XML by the value you specified for this parameter.
In the case you specify a $VAR[xxx] as value this will be used, not the value the variable will be evaluated at runtime.
Reply

Logout Mark Read Team Forum Stats Members Help
Suggestion: Include directive with parameters0