Instant properties: size

The instant property size represents the size of a rectangle stored within a rect operand and is expressed as a point value. Alternatively, if used in context of an array member or a local array, the property represents the number of entries within the array.

Declaration

Form 1:

point rect.size

Form 2:

int32 array.size

Discussion

The first version of the size instant property is used in context of a rect operand. A rect operand stores the coordinates of a rectangle in its both values point1 and point2, which accordingly represent the rectangle's top-left and bottom-right corners. As such, both corners can be evaluated and adjusted individually.

The instant property size, in contrast, provides a more convenient way to access and modify the rectangle's coordinates. Reading the property results in the size of the rectangle, calculated from the difference between the coordinates of the bottom-right and the top-left corners. In turn, modifying the size property changes the coordinates of the bottom-right corner only, resulting in a rectangle with the new size without changing the rectangle's origin position. For example:

var rect r = <100,200,110,220>; // Read the rectangle size var point result = r.size; // result = <10,20> // Modify the rectangle size r.size = <50,100>; // r = <100,200,150,300>

The second version of the size instant property is used in context of an array operand. The read access to the property returns the number of elements within this array: this means the maximal capacity determined in the declaration of the array. Please note, this version of the size instant property is read-only. The size of an existing array can't change at the runtime. For example:

array string keywords[10]; array string items[2,4]; var int32 result = keywords.size; // result = 10 var int32 result = items.size; // result = 8 keywords.size = 20; // Chora compiler error

Usage in Inspector

When working with Inspector you can easily access, evaluate and modify the size of a rectangle. For this purpose select in Inspector the desired rect property or attribute and click on the small triangle on its left side to expand and display the subordinated values. The size is displayed in Inspector as two individual values w and h representing the width and the height of the rectangle: