Dynamically change element content

While Transform lets you change the appearance of elements or groups of elements, there might be occasions where you want to switch between a list of behaviors based on some condition. This is analogous to a switch statement or if…else statement in other languages.

For example, you might want to show a different background for early morning, morning, lunch, afternoon, evening, and night.

Condition statements in Watch Face Format allow you to include different parts of your watch face scene depending on the evaluation of expressions, for example:

<Condition>
    <Expressions>
        <Expression name="is_early_morning">
            <![CDATA[[HOUR_0_23] >= 6 && [HOUR_0_23] < 8]]
        </Expression>
        <Expression name="is_morning">
            <![CDATA[[HOUR_0_23] < 12]]
        </Expression>
        ...
    </Expressions>
    <Compare expression="is_early_morning">
        <!-- Early morning content here -->
        <Group ... />
    </Compare>
    <Compare expression="is_morning">
        <!-- Morning content here -->
        <Group ... />
    </Compare>
    ...
    <!-- The "else" case -->
    <Default>
        <!-- content -->
    </Default>
</Condition>

A few things to note about conditions:

  1. The first Compare element where the expression is true is used, and others are ignored.
  2. Owing to the XML format, it can often be easiest to wrap the expression definition in a CDATA element as shown here, as this avoids the need for XML escaping using entity elements such as &gt; and &amp;.
  3. Condition structures can be nested.