npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pixi-flex-layout-v6-ts

v1.1.0

Published

Flex layouts for pixi.js powered by Yoga

Downloads

2

Readme

pixi-flex-layout

NPM Version

Flex layouts for pixi.js v6 powered by Yoga example

Installation

npm install pixi-flex-layout --save

Usage

import { initializeYogaLayout, yogaSetRenderer } from "pixi-flex-layout";
initializeYogaLayout();
yogaSetRenderer(pixiRenderer);

const containerStyle  = {
    justifyContent: "space-between",
    flexWrap: "wrap",
    width: 200
};

const container = new PIXI.Container();
container.flex = true;
container.yoga.fromConfig(containerStyle)
container.yoga.flexDirection = "row";
container.yoga.animationConfig = {
    time: 200,
    easing: t => t
}

for(let i =0; i < 10;i++){
  const foo = new PIXI.Text(i+"00");
  container.addChild(foo)
}

Live and editable examble can be found on https://fireveined.github.io/pixi-flex-layout/test.html

TypeDoc on https://fireveined.github.io/pixi-flex-layout/doc/index.html

Initializing flex

initializeYogaLayout(options: IFlexLayoutOptions)

Invoke once on app startup to initialize pixi.js polyfills. Supported options: usePixiSharedTicker: boolean, default true

yogaSetRenderer(renderer: renderer: PIXI.WebGLRenderer | PIXI.CanvasRenderer)

pixi-flex-layout will use renderer events to prevent unnecessary updateTransform calls. It's not neccesary, but will speed up calculations a lot.

PIXI.Container.flex: boolean

True to enable flex layout for direct children of container, or false to disable flex when flexRecursive is set

PIXI.Container.flexRecursive: boolean

True to enable flex layout for ALL children of container (eg. whole scene)

_DisplayObject.__hasYoga: boolean

Checks if object has Yoga node bound

Setting styles

Styles can be se directly:

object.yoga.width = "50%";
object.yoga.paddingTop = 20;
object.yoga.alignItems = "center";

Or using config

const containerStyle: YogaLayoutConfig  = {
    justifyContent: "space-between",
    flexWrap: "wrap",
    width: 200
};
object.yoga.fromConfig(containerStyle);

All styles from https://yogalayout.com/ are suported with shorthands for:

obj.yoga.padding = [10, 10, 10, 10];
obj.yoga.paddingAll = 10;  
obj.yoga.paddingTop = 30;

The same for margin and border properties.

Size controlling

obj.yoga.rescaleToYoga: boolean can be used and then pixi width/height will be controlled by yoga and set to match layout values.

obj.yoga.keepAspectRatio: boolean can be used to keep aspect ratio of objects. Defaults to true on PIXI.Text and PIXI.Sprite.

obj.yoga.[width|height] can take values:

obj.yoga.width = 100; // pixels
obj.yoga.height = "30%" // 30% of parent
obj.yoga.width = "auto"; // default 
obj.yoga.height = "pixi"; // use value from PIXIobject.height property 

Animations

Animations can be enabled by setting animationConfig:

obj.yoga.animationConfig = {
    time: 200 // duration of animation in ms
    easing: t => t 
}

Todos

  • Build and use new Yoga version (current yoga-layout-prebuilt is quite old)
  • More readable doc with examples
  • Support for font baselines

Known bugs

  • minWidth/minHeight/maxWidth/maxHeight sometimes don't work as expected when commbined with position: absolute or paddings/margins (Yoga bug)

License

MIT