Skip to content

@jimka/typescript-ui / layout / Fit

Class: Fit

Defined in: src/typescript/lib/layout/Fit.ts:28

A layout manager that expects exactly one child component and positions it inside the container's entire inner bounds. The default fill mode is FillType.BOTH — the child stretches to fill the bounds. Pass fill: FillType.NONE (or call Fit.setFill) to centre the child at its preferred size instead; HORIZONTAL / VERTICAL stretch on one axis and centre on the other. Throws if the container holds more than one component.

Extends

Constructors

new Fit()

ts
new Fit(options?: FitOptions): Fit

Defined in: src/typescript/lib/layout/Fit.ts:32

Parameters

options?

FitOptions

Returns

Fit

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/Fit.ts:211

Places the single child component inside the container's inner bounds using the configured fill mode.

Returns

void

Remarks

Throws if the container holds more than one component. With the default FillType.BOTH the child is sized to the full bounds; with FillType.NONE it is placed at its preferred size and centred via the inherited anchor-displacement logic in placeComponent.

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


getComponent()

ts
getComponent(): 
  | undefined
  | null
| Component<ComponentOptions>

Defined in: src/typescript/lib/layout/Fit.ts:181

Returns the single child component of the container, or undefined if the container is empty.

Returns

| undefined | null | Component<ComponentOptions>

The child component, or undefined.

Remarks

Throws if the container holds more than one component.


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


getFill()

ts
getFill(): FillType

Defined in: src/typescript/lib/layout/Fit.ts:59

Returns the fill mode applied to the single child.

Returns

FillType

The current FillType.


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/Fit.ts:147

Returns the maximum size of the single child component plus the container perimeter.

Returns

null | Size

The maximum {width, height}, or null if there is no container or no child.

Overrides

LayoutManager.getMaxSize


getMinSize()

ts
getMinSize(): null | Size

Defined in: src/typescript/lib/layout/Fit.ts:115

Returns the minimum size of the single child component plus the container perimeter.

Returns

null | Size

The minimum {width, height}, or null if there is no container or no child.

Overrides

LayoutManager.getMinSize


getPreferredSize()

ts
getPreferredSize(): null | Size

Defined in: src/typescript/lib/layout/Fit.ts:83

Returns the preferred size of the single child component plus the container perimeter.

Returns

null | Size

The preferred {width, height}, or null if there is no container or no child.

Overrides

LayoutManager.getPreferredSize


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


setFill()

ts
setFill(fill: FillType): this

Defined in: src/typescript/lib/layout/Fit.ts:72

Sets the fill mode applied to the single child.

Parameters

fill

FillType

BOTH stretches the child to fill (default), NONE centres it at its preferred size, HORIZONTAL / VERTICAL stretch on one axis and centre on the other.

Returns

this

This layout manager, for method chaining.


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