One of the purpose of the Canvas2D feature is to use it to build Graphical User Interfaces.
One key feature that helps making this easier is to provide a Positioning Engine for the primitives (in order to avoid positioning them with absolute coordinates) by relying on a higher level set of features which drive positions and sizes, based on criteria that make more sense to GUI based programming.
To make things clearer you have two distinct modes:
position property (or x & x which are shortcuts to position.x & position.y) to specify where your primitive is going to be positioned. By doing this you don't use the positioning engine.position property, the position will be computed by the Positioning Engine and the result will be stored in the actualPosition and actualSize properties. Setting the position property in this mode will lead to unexpected results.Three concepts are introduced to help on this matter:
actualSize property. The Positioning engine allocate this area and its position based on the margin and marginAlignment properties. If no Margin/Alignment are specified then the size and position are used.padding property, if any. If there's no padding, the content area is the same as the primitive area.Alignment: a primitive can use only a portion of the Layout Area it's assigned to. To help define how it should be positioned into this Area you can rely on Absolute Positioning (defined by the position property of the primitive) or on Alignment using the marginAlignment property to :
Stretch (which also will drive the Size property of the Primitive) the primitive Surface Area to fit its parent Content Area on either or both Horizontal/Vertical axes.
Note: alignment will consider the actualScale and rotation of the primitive, this this PG -
Both margin and padding properties are defined with the PrimitiveThickness type. Let's see what this type can do:
top, left, right and bottom.The distance can be expressed in many ways:
Auto: this is the default value which means the edge is not taking into consideration to compute the Bounding Rectangle.
The opposite edge (Top for Bottom, Right for Left and vice and versa) as well as the Primitive size Width or Height (depending on the concerned axis) will be use to compute the Bounding Rectangle.
The Layout Engine is assigned to a given primitive and then is responsible to distribute the available space and assign the layoutArea and layoutAreaPos to each direct child primitive.
Note that depending on the Layout Engine, the Layout Area assigned to child primitive may overlap or not, it's a design choice made during the Layout Engine conception.
When no Layout Engine is assigned the CanvasLayoutEngine is used by default, its role is fairly easy: it assigns the whole Content Area of the primitive its assigned to as the Layout Area to use for each child. That's it, every child primitive share the same Area. No particular setting as to be provided to use this Layout Engine, that's why it's the one used by default.
More complex Layout Engine such as the GridLayoutEngine can be used to achieve a more sophisticated distribution of the available area. The user define a set of Grid Rows and Columns that subdivide the area into many sub areas called cell and each direct child primitive is assigned to a particular cell (or multiple one when spanning is used).
Note: GridLayout is not available yet, the only second layout is the StackPanelLayoutEngine.