infinite-canvas-tutorial
infinite-canvas-tutorial copied to clipboard
Implement flex layout
If we want to place a paragraph in a container, keeping it centered horizontally and vertically:
const container = new Rect({
x: 0,
y: 0,
width: 100,
height: 100,
display: 'flex',
alignItems: 'center',
justifyContent: 'center'
});
const paragraph = new Text({
content: 'Line 1 \n Line 2 \n Line 3',
});
container.appendChild(paragraph);
So we need the help of layout engine such as Yoga.
Other flex layout implementations: