UIEvolutin Inc.
UJML Language Reference
Script Expressions

Script expressions are operations in the scripting language or XML scripting elements that yield a value.

Expressions are scripting operators and identifiers which evaluate to a value of a UJML data type. See Identifiers, Operators, Data Types. You can think of a script expression as being the right-hand side of a scripting assignment statement, except that the result of the expression is used directly instead of assigning it to the variable on the left-hand side. See Variables, Statements. In fact the right-hand side of an assignment statement is a script expression. 

Expressions are commonly a mathematical calculation (for example, 'foo + 25'). Expressions may also be Boolean comparisons returning true or false, function calls, or anything else that yields a value. The parts of an expression may be literals, variables, and function calls—anything that yields a value. See Literals, Variables, Using Functions

Note: The simplest possible expression is a single variable or a literal value, even though this includes no mathematical calculation or function call. For example 'foo' and '25' by themselves are both expressions.

Uses of expressions

As stated above, the result of a scripting expression may be assigned to a variable. Other uses include:

  • A parameter in a function call. See Using Functions.
  • A sub-expression used in a larger expression. For example 'foo + 25' is a sub-expression of 'bar * (foo + 25)'. Sub-expressions may contain sub-expressions.
  • A visual element property value that is evaluated when the visual element is displayed.
  • Any other UJML element that contains a value.
  • Boolean expressions used in a flow control statement. See Flow Control.

Basically you can use a scripting expression in place of a literal anywhere that a value is expected.

Expressions in the scripting language

In the scripting language expressions are simply a combination of operators, literals, and identifiers. See Identifiers, Literals, Operators, Expressions. Sub-expressions are commonly put inside of a pair of parentheses so that the compiler evaluates them first. Expressions used in a script element block are generally part of an assignment statement or a flow control statement. See script. Expressions used inside of an XML property element are placed inside eval elements. See eval.

Expressions in XML scripting

In XML, scripting expressions are provided by any XML scripting element that yields a value. Sub-expressions in XML scripting are simply the XML sub-elements of an XML scripting element and are evaluated first.

The following example shows how to calculate the size and position of a box using mathematical expressions and function calls. It is part of the helloworld4.ujml sample.

// Calculate Width and Height for the box.
mWidth = (&SPACING; * 2) +
    _text_width("&SALUTATION;", &_FONT_SIZE_LARGE;, &_FONT_STYLE_ITALIC;, &_FONT_FACE_SYSTEM;);
mHeight = (&SPACING; * 2) +
    _text_height(&_FONT_SIZE_LARGE;, &_FONT_STYLE_ITALIC;, &_FONT_FACE_SYSTEM;);

// Calculate X and Y to center the box on the screen.
mPosX = (_getIntProperty(&_PROPERTY_INT_SCREEN_WIDTH;) / 2) - (mWidth / 2);
mPosY = (_getIntProperty(&_PROPERTY_INT_SCREEN_HEIGHT;) / 2) - (mHeight / 2);

 

The following example shows how to calculate a new position of a box one movement unit to the right. It then uses a conditional expression to determine if the box has moved off of the screen and relocates it if it has. It is part of the helloworld4.ujml sample.

mPosX = mPosX + &MOVEMENT;;
if (mPosX &_GT;
    (_getIntProperty(&_PROPERTY_INT_SCREEN_WIDTH;) - mWidth))
{
    mPosX = _getIntProperty(&_PROPERTY_INT_SCREEN_WIDTH;) - mWidth;
}

 

The following example shows how to perform a Boolean comparison expression and assigns the result to a boolean variable. It is part of the assignment.ujml sample.

mBooleanVar = (mIntVar &_GT; 99);

 

The following example shows how to display a self-intersecting polygon where the points of the polygon and other property element values are derived from expressions evaluated at run time. It is part of the visualelements.ujml sample.

<polygon>
    <x><eval>mRectX + (mRectWidth / 2)</eval></x>
    <y><eval>mRectY</eval></y>
    <x><eval>mRectX</eval></x>
    <y><eval>mRectY + (mRectHeight / 3)</eval></y>
    <x><eval>mRectX</eval></x>
    <y><eval>mRectY + mRectHeight - (mRectHeight / 3)</eval></y>
    <x><eval>mRectX + (mRectWidth / 5)</eval></x>
    <y><eval>mRectY + mRectHeight</eval></y>
    <x><eval>mRectX + mRectWidth - (mRectWidth / 5)</eval></x>
    <y><eval>mRectY + mRectHeight</eval></y>
    <x><eval>mRectX + mRectWidth</eval></x>
    <y><eval>mRectY + mRectHeight - (mRectHeight / 3)</eval></y>
    <x><eval>mRectX + mRectWidth</eval></x>
    <y><eval>mRectY + (mRectHeight / 3)</eval></y>
    <fg><eval>mForeColor</eval></fg>
    <x-bg><eval>makeColor(mBackColor, mOpacity)</eval></x-bg>
</polygon>
Copyright (c) 2000-2007 UIEvolution, Inc. All rights reserved.
What do you think about this topic? Send feedback!