feat: 自动弹性布局

pull/1/head
zestack 1 year ago
parent ddf6148d14
commit 3a5c29fe0d
  1. 12
      src/engineer/render.ts
  2. 12
      src/engineer/types.ts

@ -8,7 +8,7 @@ import { defineComponent, h } from 'vue'
import type { import type {
Axis, Axis,
Block, Block,
DataRefer, DataRefer, Theme,
View, View,
ViewChildren, ViewChildren,
Widget, Widget,
@ -55,6 +55,14 @@ function isRefer(s: any): s is DataRefer {
&& typeof s.key === 'string' && typeof s.key === 'string'
} }
export const isFlexible = (theme: Theme) => {
return theme.axis != null
|| theme.mainAlign != null
|| theme.crossAlign != null
|| theme.wrap != null
|| theme.gap != null
}
export function render(view?: ViewChildren, axis?: Axis): VNodeChild { export function render(view?: ViewChildren, axis?: Axis): VNodeChild {
if (view == null) if (view == null)
return null return null
@ -135,7 +143,7 @@ export function render(view?: ViewChildren, axis?: Axis): VNodeChild {
// 所以在这里复用它用于子视图构建 // 所以在这里复用它用于子视图构建
axis = theme?.axis axis = theme?.axis
if (theme?.flexible) { if (theme?.flexible || (theme && theme.flexible == null && isFlexible(theme))) {
Object.assign(css, { Object.assign(css, {
display: 'flex', display: 'flex',
flexDirection: axis === 'y' ? 'column' : undefined, flexDirection: axis === 'y' ? 'column' : undefined,

@ -264,9 +264,17 @@ export type ClipBehavior =
* *
*/ */
export interface Theme extends Textual, Flexible, Boxed, Decoration, Spatial, Flexible { export interface Theme extends Textual, Flexible, Boxed, Decoration, Spatial, Flexible {
/** 是否开启弹性布局,todo 删除改属性,根据属性判断是否启用 flex 布局 */ /**
*
*
* Flexible
*/
flexible?: boolean flexible?: boolean
/** 超出视图剪切方式,对应 overflow 属性 */ /**
*
*
* overflow
*/
clip?: ClipBehavior clip?: ClipBehavior
} }

Loading…
Cancel
Save