Mathematical UI directives

From GECK
(Redirected from Abs (UI Directive))
Jump to: navigation, search

These directives are a series of traits that performs mathematical functions on an element in a user interface XML block.

  • Copy - copies its value. Has some other behavior, check examples below.
  • Add - performs mathematical addition.
  • Sub - performs mathematical subtraction.
  • Mul/Mult - performs mathematical multiplication.
  • Div - performs mathematical division.
  • Mod - performs mathematical modulo.
  • Round - performs mathematical rounding.
  • Floor - returns the nearest integer number that is less than a float variable.
  • Ceil - returns the nearest integer number that is higher than a float variable.
  • Min - returns the value the previous value or copies its own depending on which one is less.
  • Max - returns the value the previous value or copies its own depending on which one is more.

Using add, sub, mul, div and other mathematical operation traits which do not copy their value will change the already present value, allowing to make counters and such.

All of these, as well as Logical UI directives, can be nested to form their own sub-blocks which can have their own Condition UI directives.

Example

 <add> 10 </add> 

Adds 10 to the element it's used in.

 <sub> 20 </sub> 

Subtracts 20 from the element it's used in.

 <mul> 2 </mul> 

Multiplies by 2 the element it's used in.

 <div> 3 </div> 

Divides by 3 the element it's used in.

 <_sum> <add src="me()" trait="_variable"/> </_sum> 

This trait will sum up every _variable every time it gets updated with a new value.

 <copy> 6 </copy> <min> 3 </min> 

This will return 3, because out of 6 and 3, it is the minimum.

 <copy> th </copy> <copy src="me()" trait="wid"/> 

This will copy the value of the width trait, because two consecutive copy traits have a special behavior where the first one's value is appended to the second's trait.

Unique Cases

<abs>, <floor>, <ceil> and <round> are unique cases. They should take no nested value/expression, and be left blank. For example:

<x>
    <copy> -321.456 </copy>
    <mul> 3.14159 </mul>
    <abs></abs>
    <floor></floor>
</x>

<x> would then contain 1009.0

These operators can behave unexpectedly if a nested value/expression is inserted into them:

<x>
 <copy> 5 </copy>
 <abs> -5 </abs>
</x>

<x> would contain 0, since it will add -5 to the accumulated value before the <abs> operator, then compute the absolute value.

See Also