Skip to content
pixi-silk
GitHub repository
Class

Panel

import { Panel } from 'pixi-silk/ui/panel';

Experimental

A panel drawn on the canvas, with no DOM: a title bar, a body that scrolls, edges to resize and a chevron that folds it. Drag the title bar to move it, and drop it near a screen edge to dock it there. Size, position and folding glide on springs. Text is SilkText.

The body is Panel.content, a flex column. Add rows, fields or a widget to it. With scroll: false it fills the body instead, for widgets that scroll on their own like the layer tree.

Example#

const panel = new Panel({ title: 'Layers', dock: 'left', width: 240, viewport: camera.state });

panel.content.add(tree, { grow: 1, onSize: (w, h) => tree.resize(w, h) });
app.stage.addChild(panel);

Panels do not stack or tab into each other: two panels docked to the same edge overlap unless you set insets.

Experimental: the API may change in a minor release.

Extends#

  • Container

Constructors#

Constructor#

new Panel(options?: PanelOptions): Panel;

Experimental

Parameters#

ParameterType
optionsPanelOptions

Returns#

Panel

Overrides#

Container.constructor

Properties#

PropertyModifierTypeDescriptionDefined in
actionsreadonlyFlexContainerExperimental A flex row at the right of the title bar for buttons of your own.ui/panels/Panel.ts:273
contentreadonlyFlexContainerExperimental The body: a flex column. With scroll, it scrolls inside Panel.scroll.ui/panels/Panel.ts:267
headerreadonlyFlexContainerExperimental The title bar, a flex row.ui/panels/Panel.ts:271
insetspublicPanelInsetsExperimental Space kept free along the screen edges. Applies from the next layout.ui/panels/Panel.ts:287
marginpublicnumberExperimental Gap to the screen edge when docked. Applies from the next layout.ui/panels/Panel.ts:285
maxHeightpublicnumberExperimental Largest height a resize allows. Infinity for no limit.ui/panels/Panel.ts:283
maxWidthpublicnumberExperimental Largest width a resize allows. Infinity for no limit.ui/panels/Panel.ts:281
minHeightpublicnumberExperimental Smallest height a resize leaves. Applies from the next resize.ui/panels/Panel.ts:279
minWidthpublicnumberExperimental Smallest width a resize leaves. Applies from the next resize.ui/panels/Panel.ts:277
scrollreadonlyScrollView | nullExperimental The scroller around content, or null with scroll: false.ui/panels/Panel.ts:269
statereadonlyPanelStateExperimental Folding, docking and drag state, as signals.ui/panels/Panel.ts:263
themereadonlyPanelThemeExperimental Colours, radius and font, resolved from the theme option.ui/panels/Panel.ts:265
titleTextreadonlySilkTextExperimental The title text.ui/panels/Panel.ts:275

Accessors#

collapsed#

Get Signature#

get collapsed(): boolean;

Experimental

True while folded to the title bar.

Returns

boolean


docked#

Get Signature#

get docked(): boolean;

Experimental

True when docked to an edge or a corner.

Returns

boolean


headerHeight#

Get Signature#

get headerHeight(): number;

Experimental

Title bar height.

Returns

number


shownRect#

Get Signature#

get shownRect(): PanelRect;

Experimental

The rectangle drawn now, in the parent’s space: position, width and the folded or unfolded height.

Returns

PanelRect


title#

Get Signature#

get title(): string;

Experimental

The title text.

Returns

string

Set Signature#

set title(text: string): void;

Experimental

Sets Panel.title.

Parameters
ParameterType
textstring
Returns

void

Methods#

collapse()#

collapse(): this;

Experimental

Folds the body away.

Returns#

this


destroy()#

destroy(options?: DestroyOptions): void;

Experimental

Stops the motion and signal subscriptions. Destroys children unless options says otherwise.

Parameters#

ParameterType
options?DestroyOptions

Returns#

void

Overrides#

Container.destroy

dockTo()#

dockTo(dock: PanelDock | null): this;

Experimental

Docks to an edge or a corner, or floats with null.

Parameters#

ParameterType
dockPanelDock | null

Returns#

this


dragBy()#

dragBy(
   dx: number, 
   dy: number, 
   pointer?: PointData
): void;

Experimental

Moves or resizes as a press dragged by (dx, dy) in the parent’s space does. pointer is where the pointer is now, for docking. Pointer moves call this.

Parameters#

ParameterType
dxnumber
dynumber
pointer?PointData

Returns#

void


expand()#

expand(): this;

Experimental

Unfolds the body.

Returns#

this


hitTest()#

hitTest(global: PointData): boolean;

Experimental

True when a point in the stage’s space is over the panel as drawn.

Parameters#

ParameterType
globalPointData

Returns#

boolean


moveTo()#

moveTo(
   x: number, 
   y: number, 
   animate?: boolean
): this;

Experimental

Floats at (x, y) in the parent’s space. Undocks a docked panel. animate: false jumps there.

Parameters#

ParameterTypeDefault value
xnumberundefined
ynumberundefined
animatebooleantrue

Returns#

this


release()#

release(): void;

Experimental

Ends a press: a tap on the chevron folds, a drag that ends near an edge docks there.

Returns#

void


resizeTo()#

resizeTo(
   width: number, 
   height: number, 
   animate?: boolean
): this;

Experimental

Sets the floating size, within the limits. A panel docked to an edge keeps spanning it. animate: false jumps.

Parameters#

ParameterTypeDefault value
widthnumberundefined
heightnumberundefined
animatebooleantrue

Returns#

this


setViewport()#

setViewport(width: number, height: number): this;

Experimental

Sets the screen size the panel docks in, for apps that track the size themselves instead of passing signals.

Parameters#

ParameterType
widthnumber
heightnumber

Returns#

this


tick()#

tick(dt: number): boolean;

Experimental

Advances the motion by dt seconds (only needed with ticker: null). Returns true while moving.

Parameters#

ParameterType
dtnumber

Returns#

boolean


toggle()#

toggle(): this;

Experimental

Folds or unfolds.

Returns#

this