Skip to content

@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()

ts
new Grid(options?: GridOptions): Grid

Defined in: src/typescript/lib/layout/Grid.ts:34

Parameters

options?

GridOptions

Returns

Grid

Overrides

LayoutManager.constructor

Methods

attach()

ts
attach(container: Component): this

Defined in: src/typescript/lib/layout/LayoutManager.ts:58

Associates this layout manager with a container component.

Parameters

container

Component

The container component to attach to.

Returns

this

Inherited from

LayoutManager.attach


delLayoutConstraints()

ts
delLayoutConstraints(component: Component): undefined | LayoutConstraints

Defined in: src/typescript/lib/layout/LayoutManager.ts:276

Removes and returns the stored layout constraints for a component.

Parameters

component

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()

ts
detach(): this

Defined in: src/typescript/lib/layout/LayoutManager.ts:67

Dissociates this layout manager from its container.

Returns

this

Inherited from

LayoutManager.detach


doLayout()

ts
doLayout(): void

Defined 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

LayoutManager.doLayout


getClassName()

ts
getClassName(): string

Defined 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

LayoutManager.getClassName


getColRowCount()

ts
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()

ts
getColumns(): number

Defined 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()

ts
getComponentSpacing(): number

Defined 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()

ts
getContainer(): null | Component

Defined 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

LayoutManager.getContainer


getId()

ts
getId(): string

Defined 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

LayoutManager.getId


getLayoutConstraints()

ts
getLayoutConstraints(component: Component): undefined | LayoutConstraints

Defined in: src/typescript/lib/layout/LayoutManager.ts:291

Returns the stored layout constraints for a component.

Parameters

component

Component

The component to look up.

Returns

undefined | LayoutConstraints

The stored constraints, or undefined if none are set.

Inherited from

LayoutManager.getLayoutConstraints


getMaxSize()

ts
getMaxSize(): null | Size

Defined 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

LayoutManager.getMaxSize


getMinSize()

ts
getMinSize(): null | Size

Defined 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

LayoutManager.getMinSize


getPreferredSize()

ts
getPreferredSize(): null | Size

Defined 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()

ts
getRows(): number

Defined 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()

ts
isStretching(): boolean

Defined 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()

ts
placeComponent(
   component: Component, 
   x: number, 
   y: number, 
   maxWidth: number, 
   maxHeight: number, 
   fill?: null | FillType, 
   anchor?: null | AnchorType): void

Defined 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

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

LayoutManager.placeComponent


setColumns()

ts
setColumns(columns: number): this

Defined 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()

ts
setComponentSpacing(spacing: number): this

Defined 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()

ts
setId(id: string): this

Defined 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

LayoutManager.setId


setLayoutConstraints()

ts
setLayoutConstraints(component: Component, constraints?: LayoutConstraints): undefined | LayoutConstraints

Defined in: src/typescript/lib/layout/LayoutManager.ts:260

Stores layout constraints for a component, or removes them if constraints is undefined.

Parameters

component

Component

The component whose constraints are being set.

constraints?

LayoutConstraints

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()

ts
setRows(rows: number): this

Defined 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()

ts
setStretching(stretching: boolean): this

Defined 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