@wonderlandlabs-pixi-ux/resizer
v1.2.5
Published
Resizer component for wonderlandlabs-pixi-ux with interactive handles
Readme
@wonderlandlabs-pixi-ux/resizer
Resize handles for PixiJS containers.
Installation
yarn add @wonderlandlabs-pixi-ux/resizerPrimary API
enableHandles(container, rect, config): ResizerStoreResizerStore
Basic Usage
import { Application, Container, Graphics, Rectangle } from 'pixi.js';
import { enableHandles } from '@wonderlandlabs-pixi-ux/resizer';
const app = new Application();
await app.init({ width: 900, height: 600 });
const box = new Container();
const shape = new Graphics();
shape.rect(0, 0, 240, 140).fill(0x4da3ff);
box.addChild(shape);
app.stage.addChild(box);
const handles = enableHandles(box, new Rectangle(80, 80, 240, 140), {
app,
mode: 'EDGE_AND_CORNER',
size: 12,
color: { r: 0.2, g: 0.6, b: 1 },
minSize: { x: 200, y: 200 },
drawRect: (rect) => {
// rect is reported in the resizer coordinate space (see "Coordinate Model")
box.position.set(rect.x, rect.y);
shape.clear().rect(0, 0, rect.width, rect.height).fill(0x4da3ff);
},
onRelease: (rect) => {
console.log('final', rect.width, rect.height);
},
});
handles.setVisible(true);
handles.setRect(new Rectangle(100, 100, 300, 160));Coordinate Model
resizertreats rectangle values as world/frame coordinates.- Handles are assumed to live on a layer that is not offset or scaled relative to global space.
resizerdoes not compensate for handle-layer transforms (position/scale/rotation/skew).- Ideally, use the final front-most container on
app.stagefor handles, or a child of such a container that remains untransformed. - If your target lives in a transformed local space, convert in your consumer (
drawRect/onRelease). deltaSpacecontrols which container pointer deltas are measured in.
EnableHandlesConfig
{
app: Application,
drawRect?: (rect: Rectangle, container: Container) => void,
onRelease?: (rect: Rectangle) => void,
size?: number,
color?: { r: number, g: number, b: number },
constrain?: boolean,
mode?: 'ONLY_EDGE' | 'ONLY_CORNER' | 'EDGE_AND_CORNER',
deltaSpace?: Container,
minSize?: { x: number, y: number },
}mode Behavior
ONLY_CORNER: Shows 4 handles at the corners (top-left,top-right,bottom-left,bottom-right).ONLY_EDGE: Shows 4 handles at edge midpoints (top-center,middle-right,bottom-center,middle-left).EDGE_AND_CORNER: Shows all 8 handles.
Hook Notes
drawRect(rect, container)- Called during resolve after internal rectangle state changes.
- Use this to redraw your target visuals from current rectangle state.
onRelease(rect)- Called once when drag ends.
ResizerStore Methods
setRect(rect)setVisible(visible)removeHandles()asRectisDraggingisRunninggetColor()
