Compare commits

...

2 Commits

Author SHA1 Message Date
zestack 4c91f0f4f7 refactor: 调整视图剪裁行为 1 year ago
zestack 3a5c29fe0d feat: 自动弹性布局 1 year ago
  1. 15
      src/engineer/render.ts
  2. 18
      src/engineer/types.ts
  3. 21
      src/engineer/utils/clip.ts
  4. 1
      src/engineer/utils/index.ts

@ -9,6 +9,7 @@ import type {
Axis,
Block,
DataRefer,
Theme,
View,
ViewChildren,
Widget,
@ -17,7 +18,7 @@ import { provideBlockId } from './context'
import {
align,
background,
bordering,
bordering, clip,
gap,
insets,
radii,
@ -55,6 +56,14 @@ function isRefer(s: any): s is DataRefer {
&& typeof s.key === 'string'
}
export function 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 {
if (view == null)
return null
@ -128,14 +137,14 @@ export function render(view?: ViewChildren, axis?: Axis): VNodeChild {
textAlign: theme?.textAlign,
lineHeight: theme?.lineHeight,
// clip
overflow: theme?.clip,
...clip(theme?.clip),
}
// note: 在前面初始化 css 时使用了参数 axis,
// 所以在这里复用它用于子视图构建
axis = theme?.axis
if (theme?.flexible) {
if (theme?.flexible || (theme && theme.flexible == null && isFlexible(theme))) {
Object.assign(css, {
display: 'flex',
flexDirection: axis === 'y' ? 'column' : undefined,

@ -252,11 +252,15 @@ export interface Widget {
slots?: Omit<Slots, 'default'>
}
/**
*
*/
export type ClipBehavior =
| 'hidden'
| 'visible'
| 'scroll'
| 'auto'
| 'autoX' // overflow-x: auto; overflow-y: hidden
| 'autoY' // overflow-x: hidden; overflow-y: auto
/**
*
@ -264,9 +268,17 @@ export type ClipBehavior =
*
*/
export interface Theme extends Textual, Flexible, Boxed, Decoration, Spatial, Flexible {
/** 是否开启弹性布局,todo 删除改属性,根据属性判断是否启用 flex 布局 */
/**
*
*
* Flexible
*/
flexible?: boolean
/** 超出视图剪切方式,对应 overflow 属性 */
/**
*
*
* overflow
*/
clip?: ClipBehavior
}

@ -0,0 +1,21 @@
import type { CSSProperties } from 'vue'
import type { ClipBehavior } from '../types'
export function clip(clip: ClipBehavior | undefined): CSSProperties | undefined {
switch (clip) {
case 'autoX':
return {
overflowX: 'auto',
overflowY: 'hidden',
}
case 'autoY':
return {
overflowX: 'hidden',
overflowY: 'auto',
}
default:
return {
overflow: clip,
}
}
}

@ -1,6 +1,7 @@
export * from './align'
export * from './background'
export * from './border'
export * from './clip'
export * from './gap'
export * from './hash'
export * from './insets'

Loading…
Cancel
Save