Conditional Visibility

From DevWiki

Jump to: navigation, search

Applications,Boxee GUI API



The power of the skinning engine is based on the ability to show and hide controls using conditional statements. Conditions can me compared and combined with no limit. The logic is simple true/false logic. You can also specify how the control should transition between a visible state and a hidden state using Animations.

Boolean Conditions

All controls can benefit from "conditional visibility" support. This means that, instead of specifying just true and false for the <visible> tag, you can also provide one of the many built-in Boolean Conditions.

Allow Hidden Focus

One thing you will notice, is that when a control is hidden, it can't be focused. This means you can't move to a control and have it automatically become visible (eg even if it had Control.HasFocus(myID) it wouldn't come back on, as Boxee wouldn't allow navigation to the hidden control). To solve this issue, you can use:

  1. <visible allowhiddenfocus="true">Control.HasFocus(21)</visible>

on a control of <id> 21. This will allow the control to be focusable even when it's hidden. When the user moves to the hidden control, it will automatically unhide itself, due to the Control.HasFocus(21) visibility condition.

Combining Conditions

You can combine two (or more) of the above settings by using + as an AND operator, | as an OR operator, ! as a NOT operator, and [ and ] to bracket expressions. For example, <visible>Player.HasVideo + Player.Rewinding</visible> will only show the control when the player is Rewinding a video, whereas <visible>Player.Seeking | Player.Muted</visible> will show the control if a video is Muted, or Seeking.

The AND operator takes precedence over the OR operator when evaluating the logic, and operators are read from left to right. So if you want to show something when condition1 OR condition2 is true AND condition3 is true, you can do:

  1. <visible>[condition1 | condition2] + condition3</visible>

Note that if you missed the brackets, then it would actually be reading if condition1 or (condition2 and condition3) due to AND taking precedence over OR.

Some pointers on boolean logic:

The following holds true:

A + [B | C] = A + B| A + C
A | [B + C] = [A | B] + [A | C]

![A + B] =! A |! B
![A | B] =! A +! B

A common mistake is to do something like this:

! A |! B |! C

This is false only if A, B and C are all simultaneously true (as it's the same as !(A + B + C)), and you may have possibly been after

! A +! B +! C

which is false if A is true, or B is true, or C is true.


Simple true/false, in this case the control will be visible:

  1. <visible>true</visible>

The following control will be visible if the player is seeking OR paused OR forwarding OR rewinding AND the player is NOT caching.

  1. <visible>[Player.Seeking | Player.Paused | Player.Forwarding | Player.Rewinding] + !Player.Caching</visible>

The following control will be visible if there is currently fullscreen video AND the boxee_video_context window is NOT visible.

  1. <visible>Window.IsActive(FullscreenVideo) + Player.HasVideo + !Window.IsVisible(boxee_video_context.xml)</visible>

The following control will be visible if a control with <id> of "52" has focus.

  1. <visible>Control.HasFocus(52)</visible>
Personal tools