@jimka/typescript-ui / layout / Grid
Class: Grid
Defined in: src/typescript/lib/layout/Grid.ts:27
A layout manager that tiles children in a uniform grid of equal-sized cells. Row and column counts can be configured explicitly or left at 0 for auto-calculation.
Extends
Constructors
new Grid()
new Grid(options?: GridOptions): GridDefined in: src/typescript/lib/layout/Grid.ts:34
Parameters
options?
Returns
Overrides
Methods
attach()
attach(container: Component): thisDefined in: src/typescript/lib/layout/LayoutManager.ts:58
Associates this layout manager with a container component.
Parameters
container
The container component to attach to.
Returns
this
Inherited from
delLayoutConstraints()
delLayoutConstraints(component: Component): undefined | LayoutConstraintsDefined in: src/typescript/lib/layout/LayoutManager.ts:276
Removes and returns the stored layout constraints for a component.
Parameters
component
The component whose constraints should be removed.
Returns
undefined | LayoutConstraints
The removed constraints, or undefined if none were stored.
Inherited from
LayoutManager.delLayoutConstraints
detach()
detach(): thisDefined in: src/typescript/lib/layout/LayoutManager.ts:67
Dissociates this layout manager from its container.
Returns
this
Inherited from
doLayout()
doLayout(): voidDefined in: src/typescript/lib/layout/Grid.ts:331
Tiles all children in a grid of equal-sized cells, left-to-right then top-to-bottom.
Returns
void
Remarks
When stretching is enabled (default) cells are equal-sized and each child fills its cell. When stretching is disabled, columns remain uniform-width but each row uses the natural heights of its children and components are baseline-aligned within their row, mirroring HBox's baseline-aware placement.
Overrides
getClassName()
getClassName(): stringDefined in: src/typescript/lib/core/BaseObject.ts:44
Returns the runtime class name of this object.
Returns
string
The name of the constructor function as a string.
Inherited from
getColRowCount()
getColRowCount():
| undefined
| {
height: number;
width: number;
}Defined in: src/typescript/lib/layout/Grid.ts:159
Returns the computed cell count for the current component list as {width: rows, height: columns}.
Returns
| undefined | { height: number; width: number; }
An object with width (row count) and height (column count), or undefined if no container is attached.
Remarks
The property names width and height are repurposed here to carry row/column counts rather than pixel dimensions.
getColumns()
getColumns(): numberDefined in: src/typescript/lib/layout/Grid.ts:136
Returns the configured number of columns, or 0 if the grid auto-calculates column count.
Returns
number
The column count.
getComponentSpacing()
getComponentSpacing(): numberDefined in: src/typescript/lib/layout/Grid.ts:115
Returns the gap, in pixels, between adjacent cells (horizontally and vertically).
Returns
number
The current spacing in pixels.
getContainer()
getContainer(): null | ComponentDefined in: src/typescript/lib/layout/LayoutManager.ts:78
Returns the container component this layout manager is attached to.
Returns
null | Component
The attached container, or null if not attached.
Inherited from
getId()
getId(): stringDefined in: src/typescript/lib/core/BaseObject.ts:24
Returns the unique identifier for this object.
Returns
string
The UUID string assigned at construction time.
Inherited from
getLayoutConstraints()
getLayoutConstraints(component: Component): undefined | LayoutConstraintsDefined in: src/typescript/lib/layout/LayoutManager.ts:291
Returns the stored layout constraints for a component.
Parameters
component
The component to look up.
Returns
undefined | LayoutConstraints
The stored constraints, or undefined if none are set.
Inherited from
LayoutManager.getLayoutConstraints
getMaxSize()
getMaxSize(): null | SizeDefined in: src/typescript/lib/layout/Grid.ts:283
Returns the maximum size: the minimum child maximum size multiplied by the computed row/column counts, plus inter-cell spacing.
Returns
null | Size
The maximum {width, height}, or null if no container is attached.
Overrides
getMinSize()
getMinSize(): null | SizeDefined in: src/typescript/lib/layout/Grid.ts:238
Returns the minimum size: the maximum child minimum size multiplied by the computed row/column counts, plus inter-cell spacing.
Returns
null | Size
The minimum {width, height}, or null if no container is attached.
Overrides
getPreferredSize()
getPreferredSize(): null | SizeDefined in: src/typescript/lib/layout/Grid.ts:193
Returns the preferred size: the maximum child preferred size multiplied by the computed row/column counts, plus inter-cell spacing.
Returns
null | Size
The preferred {width, height}, or null if no container is attached.
Overrides
LayoutManager.getPreferredSize
getRows()
getRows(): numberDefined in: src/typescript/lib/layout/Grid.ts:95
Returns the configured number of rows, or 0 if the grid auto-calculates row count.
Returns
number
The row count.
isStretching()
isStretching(): booleanDefined in: src/typescript/lib/layout/Grid.ts:73
Returns whether children stretch to fill their cells.
Returns
boolean
true if stretching is enabled (default).
placeComponent()
placeComponent(
component: Component,
x: number,
y: number,
maxWidth: number,
maxHeight: number,
fill?: null | FillType,
anchor?: null | AnchorType): voidDefined in: src/typescript/lib/layout/LayoutManager.ts:126
Positions and sizes a child component within the given bounds, respecting fill and anchor constraints.
Parameters
component
The child component to position.
x
number
Left edge of the cell in the container's coordinate space.
y
number
Top edge of the cell in the container's coordinate space.
maxWidth
number
Available width for the component.
maxHeight
number
Available height for the component.
fill?
Optional. Fill strategy overriding the component's own constraints.
null | FillType
anchor?
Optional. Anchor point overriding the component's own constraints.
null | AnchorType
Returns
void
Remarks
The method checks the component's stored LayoutConstraints first; the fill and anchor parameters serve as fallbacks. After positioning, doLayout is called on the child so nested layouts are updated in a single pass.
Inherited from
setColumns()
setColumns(columns: number): thisDefined in: src/typescript/lib/layout/Grid.ts:145
Sets the number of columns. Pass 0 to let the grid auto-calculate.
Parameters
columns
number
The desired column count, or 0 for automatic.
Returns
this
setComponentSpacing()
setComponentSpacing(spacing: number): thisDefined in: src/typescript/lib/layout/Grid.ts:125
Sets the gap, in pixels, between adjacent cells. Applied both horizontally (between columns) and vertically (between rows).
Parameters
spacing
number
Spacing in pixels. Falsy values are treated as 0.
Returns
this
setId()
setId(id: string): thisDefined in: src/typescript/lib/core/BaseObject.ts:33
Sets the unique identifier for this object.
Parameters
id
string
The new identifier string to assign.
Returns
this
Inherited from
setLayoutConstraints()
setLayoutConstraints(component: Component, constraints?: LayoutConstraints): undefined | LayoutConstraintsDefined in: src/typescript/lib/layout/LayoutManager.ts:260
Stores layout constraints for a component, or removes them if constraints is undefined.
Parameters
component
The component whose constraints are being set.
constraints?
Optional. The constraints to store; omit to delete existing constraints.
Returns
undefined | LayoutConstraints
The stored constraints, or undefined if they were deleted.
Inherited from
LayoutManager.setLayoutConstraints
setRows()
setRows(rows: number): thisDefined in: src/typescript/lib/layout/Grid.ts:104
Sets the number of rows. Pass 0 to let the grid auto-calculate.
Parameters
rows
number
The desired row count, or 0 for automatic.
Returns
this
setStretching()
setStretching(stretching: boolean): thisDefined in: src/typescript/lib/layout/Grid.ts:84
Sets whether children stretch to fill their cells. When false, each row uses the natural heights of its children and components are baseline-aligned within the row.
Parameters
stretching
boolean
Pass false to enable per-row baseline alignment instead of stretching.
Returns
this