Alignment
Key Properties
flowAlign: IFlowAlign | IFlowAxisAlign
Defines how child elements are aligned. Default is top-left.
ts
type IFlowAlign =
| 'top-left'
| 'top'
| 'top-right'
| 'right'
| 'bottom-right'
| 'bottom'
| 'bottom-left'
| 'left'
| 'center'
| IBaseLineAlign
// baseline support in future
type IBaseLineAlign = 'baseline-left' | 'baseline-center' | 'baseline-right'You can further configure axis alignment within each line.
ts
interface IFlowAxisAlign {
content?: IFlowAlign
x?: IAxisAlign // x-axis alignment within a row, default is from
y?: IAxisAlign // y-axis alignment within a row, default is from
}
// from means align to the start of the axis, to means align to the end
type IAxisAlign = 'from' | 'center' | 'to'Row Y-axis alignment
Row X-axis alignment
Belongs To
Flow Element
Example
Top-left alignment
ts
// #自动布局 - 对齐内容 [左上角对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: 'top-left', // 左上角对齐
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Top-center alignment
ts
// #自动布局 - 对齐内容 [顶部居中对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: 'top', // 顶部居中对齐
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Top-right alignment
ts
// #自动布局 - 对齐内容 [右上角对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: 'top-right', // 右上角对齐
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Left alignment
ts
// #自动布局 - 对齐内容 [左对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: 'left', // 左对齐
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Center alignment
ts
// #自动布局 - 对齐内容 [居中对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: 'center', // 居中对齐
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Right alignment
ts
// #自动布局 - 对齐内容 [右对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: 'right', // 右对齐
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Bottom-left alignment
ts
// #自动布局 - 对齐内容 [左下角对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: 'bottom-left', // 左下角对齐
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Bottom-center alignment
ts
// #自动布局 - 对齐内容 [底部居中对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: 'bottom', // 底部居中对齐
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Bottom-right alignment
ts
// #自动布局 - 对齐内容 [右下角对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: 'bottom-right', // 右下角对齐
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Center alignment with row top alignment
ts
// #自动布局 - 对齐内容 [居中对齐,且行内顶部对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: { // 居中对齐,且行内顶部对齐
content: 'center',
y: 'from'
},
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Center alignment with row center alignment
ts
// #自动布局 - 对齐内容 [居中对齐,且行内居中对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: { // 居中对齐,且行内居中对齐
content: 'center',
y: 'center'
},
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)Center alignment with row bottom alignment
ts
// #自动布局 - 对齐内容 [居中对齐,且行内底部对齐]
import { Leafer, Box } from 'leafer-ui'
import { Flow } from '@leafer-in/flow' // 导入自动布局插件
const leafer = new Leafer({ view: window })
const flow = new Flow({
flowAlign: { // 居中对齐,且行内底部对齐
content: 'center',
y: 'to'
},
fill: '#676',
width: 100,
height: 100,
children: [
new Box({ fill: '#FF4B4B', children: [{ tag: 'Text', text: '1', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 20 }] }),
new Box({ fill: '#FEB027', children: [{ tag: 'Text', text: '2', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 40 }] }),
new Box({ fill: '#79CB4D', children: [{ tag: 'Text', text: '3', fill: 'white', textAlign: 'center', verticalAlign: 'middle', width: 25, height: 30 }] })
],
})
leafer.add(flow)