refactor: 内置组件关于定位以及一部分 props 的实现

This commit is contained in:
AncTe committed 2026-11-20 21:17:50 +08:00
1 parent b253feebd0
commit 853e3c4af4
10 files changed
+327 -280

No files matched your search

@@ -1,47 +1,58 @@
import { SetupComponentOptions } from '@motajs/system';
import { ElementLocator } from '@motajs/render';
import { DefaultProps } from '@motajs/render-vue';
import { computed, defineComponent } from 'vue';
import { Winskin } from './winskin';
import { ITextureManager } from '../material';
import { isNil } from 'lodash-es';
import { RectRCircleParams } from '@motajs/render';
export interface BackgroundProps extends DefaultProps {
loc: ElementLocator;
winskin?: ImageIds;
/** 使用 winskin 作为背景,此时 `color` 和 `border` 无效 */
winskin?: string;
/** 边框宽度,当使用 `winskin` 作为背景时,默认为 32,否则默认为 2 */
borderWidth?: number;
/** 填充颜色 */
color?: CanvasStyle;
/** 边框颜色 */
border?: CanvasStyle;
/** 非 `winskin` 模式下,圆角矩形的参数,默认为 [4] */
circle?: RectRCircleParams;
/** 使用的贴图管理器 */
manager?: ITextureManager;
}
const backgroundProps = {
props: ['loc', 'winskin', 'color', 'border']
props: ['winskin', 'borderWidth', 'color', 'border', 'manager', 'circle']
} satisfies SetupComponentOptions<BackgroundProps>;
/**
* 背景组件,与 Selection 类似,不过绘制的是背景,而不是选择光标,参数参考 {@link BackgroundProps},用例如下:
* ```tsx
* // 使用 winskin2.png 作为背景
* <Background loc={[8, 8, 160, 160]} winskin="winskin2.png" />
* <Background loc={[8, 8, 160, 160]} winskin="winskin2.png" manager={props.state.materials} />
* // 使用指定填充和边框颜色作为背景
* <Background loc={[8, 8, 160, 160]} color="#333" border="gold" />
* ```
*/
export const Background = defineComponent<BackgroundProps>(props => {
const isWinskin = computed(() => !!props.winskin);
const fixedLoc = computed<ElementLocator>(() => {
const [x = 0, y = 0, width = 200, height = 200] = props.loc;
return [x + 2, y + 2, width - 4, height - 4];
});
const isWinskin = computed(() => !isNil(props.winskin));
return () =>
isWinskin.value ? (
<winskin imageName={props.winskin!} loc={props.loc} noanti />
<Winskin
winskin={props.winskin}
manager={props.manager}
borderSize={props.borderWidth}
noanti
/>
) : (
<g-rectr
loc={fixedLoc.value}
fillStyle={props.color}
strokeStyle={props.border}
fill
stroke
lineWidth={2}
circle={[4]}
lineWidth={props.borderWidth ?? 2}
circle={props.circle ?? [4]}
/>
);
}, backgroundProps);
@@ -1,8 +1,6 @@
import { ElementLocator } from '@motajs/render';
import { DefaultProps, GraphicPropsBase } from '@motajs/render-vue';
import { DefaultProps, GraphicPropsBase, lwh } from '@motajs/render-vue';
import { SetupComponentOptions } from '@motajs/system';
import {
computed,
defineComponent,
DefineSetupFnComponent,
onMounted,
@@ -11,12 +9,10 @@ import {
watch
} from 'vue';
export interface IconsProps extends DefaultProps<GraphicPropsBase> {
loc: ElementLocator;
}
export interface IconsProps extends DefaultProps<GraphicPropsBase> {}
const iconsProps = {
props: ['loc']
props: ['loc', 'x', 'y', 'width', 'height']
} satisfies SetupComponentOptions<IconsProps>;
type IconLoc = [
@@ -120,8 +116,7 @@ export function defineIcon<T extends IconsProps>(
return defineComponent<T>(props => {
const path = shallowRef<Path2D>();
const width = computed(() => props.loc[2] ?? 200);
const height = computed(() => props.loc[3] ?? 200);
const [loc, width, height] = lwh(props);
const generatePath = adjustPath(aspect, path, pathDef);
watch(props, () => {
@@ -134,7 +129,7 @@ export function defineIcon<T extends IconsProps>(
return () => (
<g-path
loc={props.loc}
loc={loc.value}
path={path.value}
stroke
lineJoin="round"
@@ -1,4 +1,4 @@
import { DefaultProps, transitionedColor } from '@motajs/render-vue';
import { DefaultProps, lwh, transitionedColor } from '@motajs/render-vue';
import { computed, defineComponent, onUnmounted, ref, watch } from 'vue';
import { TextContent, TextContentProps } from './textbox';
import {
@@ -50,6 +50,10 @@ export type InputEmits = {
const inputProps = {
props: [
'loc',
'x',
'y',
'width',
'height',
'placeholder',
'value',
'multiline',
@@ -90,8 +94,7 @@ export const Input = defineComponent<InputProps, InputEmits, keyof InputEmits>(
const value = ref(props.value ?? '');
const root = ref<Container>();
const width = computed(() => props.loc?.[2] ?? 200);
const height = computed(() => props.loc?.[3] ?? 200);
const [loc, width, height] = lwh(props);
const showText = computed(() => value.value || props.placeholder || '');
const padding = computed(() => props.pad ?? 4);
const textLoc = computed<ElementLocator>(() => [
@@ -241,7 +244,7 @@ export const Input = defineComponent<InputProps, InputEmits, keyof InputEmits>(
return () => (
<container
loc={props.loc}
loc={loc.value}
ref={root}
cursor="text"
onClick={click}
@@ -1,7 +1,7 @@
import { DefaultProps } from '@motajs/render-vue';
import { DefaultProps, lwh } from '@motajs/render-vue';
import { computed, defineComponent, ref, SlotsType, VNode, watch } from 'vue';
import { Selection } from './misc';
import { ElementLocator, Font } from '@motajs/render';
import { ElementLocator, Font, RectRCircleParams } from '@motajs/render';
import { SetupComponentOptions } from '@motajs/system';
import { Scroll } from './scroll';
@@ -16,12 +16,16 @@ export interface ListProps extends DefaultProps {
lineHeight?: number;
/** 字体 */
font?: Font;
/** 使用 winskin 作为光标 */
/** 使用 winskin 作为光标,会忽略 `color` `border` `circle` */
winskin?: ImageIds;
/** 使用指定样式作为光标背景 */
color?: CanvasStyle;
/** 使用指定样式作为光标边框 */
border?: CanvasStyle;
/** 光标的边框宽度,默认为 2 */
borderSize?: number;
/** 使用非 `winskin` 模式时,圆角矩形的圆角参数 */
circle?: RectRCircleParams;
/** 选择图标的不透明度范围 */
alphaRange?: [number, number];
}
@@ -41,11 +45,16 @@ const listProps = {
'list',
'selected',
'loc',
'x',
'y',
'width',
'height',
'lineHeight',
'font',
'winskin',
'color',
'border',
'circle',
'alphaRange'
],
emits: ['update', 'update:selected']
@@ -53,8 +62,16 @@ const listProps = {
export const List = defineComponent<ListProps, ListEmits, keyof ListEmits>(
(props, { emit }) => {
/** 当前选中项 */
const selected = ref(props.selected ?? props.list[0][0]);
const lineHeight = computed(() => props.lineHeight ?? 24);
/** 行高 */
const lh = computed(() => props.lineHeight ?? 24);
/** 当前选中项的索引 */
const index = computed(() =>
props.list.findIndex(([key]) => key === selected.value)
);
const [loc, w] = lwh(props);
const select = (value: string) => {
selected.value = value;
@@ -70,52 +87,34 @@ export const List = defineComponent<ListProps, ListEmits, keyof ListEmits>(
);
return () => (
<Scroll loc={props.loc}>
{props.list.map((v, i) => {
const [key, value] = v;
const loc: ElementLocator = [
0,
lineHeight.value * i,
props.loc[2] ?? 200,
lineHeight.value
];
const selectionLoc: ElementLocator = [
0,
0,
(props.loc[2] ?? 200) - 10,
lineHeight.value
];
const textLoc: ElementLocator = [
10,
lineHeight.value / 2,
void 0,
void 0,
0,
0.5
];
<Scroll loc={loc.value}>
{props.list.map(([key, value], i) => {
return (
<container
loc={loc}
<container // 得加个 container 拓展点击区域
loc={[0, lh.value * i, w.value, lh.value]}
nocache
onClick={() => select(key)}
zIndex={10}
>
{selected.value === key && (
<Selection
loc={selectionLoc}
color={props.color}
border={props.border}
winskin={props.winskin}
alphaRange={props.alphaRange}
/>
)}
<text
loc={textLoc}
loc={[10, lh.value / 2]}
anc={[0, 0.5]}
text={value}
font={props.font}
/>
</container>
);
})}
<Selection
loc={[0, lh.value * index.value, w.value - 10, lh.value]}
color={props.color}
border={props.border}
winskin={props.winskin}
alphaRange={props.alphaRange}
circle={props.circle}
borderSize={props.borderSize}
zIndex={0}
/>
</Scroll>
);
},
@@ -1,11 +1,14 @@
import {
ElementLocator,
CustomRenderItem,
MotaOffscreenCanvas2D
MotaOffscreenCanvas2D,
CanvasStyle,
RectRCircleParams
} from '@motajs/render';
import {
cycledTransition,
DefaultProps,
lwh,
onExcitedFunc,
PathProps
} from '@motajs/render-vue';
@@ -13,8 +16,9 @@ import { computed, defineComponent, ref, watch } from 'vue';
import { TextContent, TextContentProps } from './textbox';
import { Scroll, ScrollExpose, ScrollProps } from './scroll';
import { SetupComponentOptions } from '@motajs/system';
import { clamp } from 'lodash-es';
import { clamp, isNil } from 'lodash-es';
import { cosh, CurveMode } from '@motajs/animate';
import { ITextureManager } from '../material';
interface ProgressProps extends DefaultProps {
/** 进度条的位置 */
@@ -30,7 +34,7 @@ interface ProgressProps extends DefaultProps {
}
const progressProps = {
props: ['loc', 'progress', 'success', 'background', 'lineWidth']
props: ['progress', 'success', 'background', 'lineWidth']
} satisfies SetupComponentOptions<ProgressProps>;
/**
@@ -47,9 +51,7 @@ export const Progress = defineComponent<ProgressProps>(props => {
const element = ref<CustomRenderItem>();
const render = (canvas: MotaOffscreenCanvas2D) => {
const { ctx } = canvas;
const width = props.loc[2] ?? 200;
const height = props.loc[3] ?? 200;
const { ctx, width, height } = canvas;
ctx.lineCap = 'round';
const lineWidth = props.lineWidth ?? 2;
ctx.lineWidth = lineWidth;
@@ -74,7 +76,7 @@ export const Progress = defineComponent<ProgressProps>(props => {
});
return () => {
return <custom ref={element} loc={props.loc} render={render}></custom>;
return <custom ref={element} render={render}></custom>;
};
}, progressProps);
@@ -181,7 +183,7 @@ export interface ScrollTextExpose {
}
const scrollProps = {
props: ['speed', 'loc', 'pad', 'width'],
props: ['speed', 'loc', 'x', 'y', 'width', 'height', 'pad'],
emits: ['scrollEnd']
} satisfies SetupComponentOptions<
ScrollTextProps,
@@ -217,7 +219,7 @@ export const ScrollText = defineComponent<
const scroll = ref<ScrollExpose>();
const speed = ref(props.speed);
const eleHeight = computed(() => props.loc[3] ?? props.width);
const [loc, width, height] = lwh(props);
const pad = computed(() => props.pad ?? 16);
let lastFixedTime = -1;
@@ -267,14 +269,14 @@ export const ScrollText = defineComponent<
return () => (
<Scroll
ref={scroll}
loc={props.loc}
padEnd={eleHeight.value + pad.value}
loc={loc.value}
padEnd={height.value + pad.value}
noscroll
>
<TextContent
{...attrs}
width={props.width - 16}
loc={[8, eleHeight.value + pad.value]}
width={width.value}
loc={[0, height.value + pad.value]}
autoHeight
/>
</Scroll>
@@ -282,16 +284,32 @@ export const ScrollText = defineComponent<
}, scrollProps);
export interface SelectionProps extends DefaultProps {
loc: ElementLocator;
/** 非 `winskin` 模式下,填充颜色 */
color?: CanvasStyle;
/** 非 `winskin` 模式下,描边颜色 */
border?: CanvasStyle;
winskin?: ImageIds;
/** 非 `winskin` 模式下,圆角矩形的圆角参数,默认为 [4] */
circle?: RectRCircleParams;
/** 使用 `winskin` 背景图,会忽略 `color` `border` `circle` 参数 */
winskin?: string;
/** 边框宽度,默认为 2 */
borderSize?: number;
/** winskin 使用的贴图管理器 */
manager?: ITextureManager;
/** 选择图标的不透明度范围 */
alphaRange?: [number, number];
}
const selectionProps = {
props: ['loc', 'color', 'border', 'winskin', 'alphaRange']
props: [
'color',
'border',
'circle',
'winskin',
'borderSize',
'manager',
'alphaRange'
]
} satisfies SetupComponentOptions<SelectionProps>;
/**
@@ -313,52 +331,60 @@ export const Selection = defineComponent<SelectionProps>(props => {
cosh(2, CurveMode.EaseInOut)
)!;
const isWinskin = computed(() => !!props.winskin);
const winskinImage = computed(() =>
isWinskin.value ? core.material.images.images[props.winskin!] : null
);
const fixedLoc = computed<ElementLocator>(() => {
const [x = 0, y = 0, width = 200, height = 200, ax, ay] = props.loc;
return [x + 1, y + 1, width - 2, height - 2, ax, ay];
const isWinskin = computed(() => !isNil(props.winskin));
const winskin = computed(() => {
if (isNil(props.winskin) || !props.manager) {
return null;
} else {
return props.manager.getImageByAlias(props.winskin);
}
});
const renderWinskin = (canvas: MotaOffscreenCanvas2D) => {
const ctx = canvas.ctx;
const image = winskinImage.value;
if (!image) return;
const [, , width = 200, height = 200] = props.loc;
const { ctx, width: w, height: h } = canvas;
if (!winskin.value) return;
const { width, height, source: i } = winskin.value;
// 背景
ctx.drawImage(image, 130, 66, 28, 28, 2, 2, width - 4, height - 4);
const x1 = (2 / 192) * width;
const x2 = (28 / 192) * width;
const x3 = (128 / 192) * width;
const x4 = (130 / 192) * width;
const x5 = (158 / 192) * width;
const y1 = (2 / 128) * height;
const y2 = (28 / 128) * height;
const y3 = (64 / 128) * height;
const y4 = (66 / 128) * height;
const y5 = (94 / 128) * height;
ctx.drawImage(i, x4, y4, x2, y2, 2, 2, w - 4, h - 4);
// 四个角
ctx.drawImage(image, 128, 64, 2, 2, 0, 0, 2, 2);
ctx.drawImage(image, 158, 64, 2, 2, width - 2, 0, 2, 2);
ctx.drawImage(image, 128, 94, 2, 2, 0, height - 2, 2, 2);
ctx.drawImage(image, 158, 94, 2, 2, width - 2, height - 2, 2, 2);
ctx.drawImage(i, x3, y3, x1, y1, 0, 0, 2, 2);
ctx.drawImage(i, x5, y3, x1, y1, w - 2, 0, 2, 2);
ctx.drawImage(i, x3, y5, x1, y1, 0, h - 2, 2, 2);
ctx.drawImage(i, x5, y5, x1, y1, w - 2, h - 2, 2, 2);
// 四条边
ctx.drawImage(image, 130, 64, 28, 2, 2, 0, width - 4, 2);
ctx.drawImage(image, 130, 94, 28, 2, 2, height - 2, width - 4, 2);
ctx.drawImage(image, 128, 66, 2, 28, 0, 2, 2, height - 4);
ctx.drawImage(image, 158, 66, 2, 28, width - 2, 2, 2, height - 4);
ctx.drawImage(i, x4, y3, x2, y1, 2, 0, w - 4, 2);
ctx.drawImage(i, x4, y5, x2, y1, 2, h - 2, w - 4, 2);
ctx.drawImage(i, x3, y4, x1, y2, 0, 2, 2, h - 4);
ctx.drawImage(i, x5, y4, x1, y2, w - 2, 2, 2, h - 4);
};
return () =>
isWinskin.value ? (
<custom
loc={props.loc}
render={renderWinskin}
alpha={alpha.ref.value}
bindings={[winskin.value]}
noanti
/>
) : (
<g-rectr
loc={fixedLoc.value}
circle={[4]}
circle={props.circle ?? [4]}
alpha={alpha.ref.value}
fill
stroke
fillStyle={props.color}
strokeStyle={props.border}
lineWidth={1}
lineWidth={props.borderSize}
/>
);
}, selectionProps);
+147 -127
View File
@@ -11,16 +11,13 @@ import {
import { clamp, isNil } from 'lodash-es';
import { ElementLocator, Font } from '@motajs/render';
import { SetupComponentOptions } from '@motajs/system';
import { DefaultProps } from '@motajs/render-vue';
/** 圆角矩形页码距离容器的边框大小,与 pageSize 相乘 */
const RECT_PAD = 0.1;
import { DefaultProps, lwh } from '@motajs/render-vue';
export interface PageProps extends DefaultProps {
/** 共有多少页 */
pages: number;
/** 页码组件的定位 */
loc: ElementLocator;
loc?: ElementLocator;
/** 当前页码 */
page?: number;
/** 页码的字体 */
@@ -59,7 +56,17 @@ type PageSlots = SlotsType<{
}>;
const pageProps = {
props: ['pages', 'loc', 'page', 'font', 'hideIfSingle'],
props: [
'pages',
'loc',
'x',
'y',
'width',
'height',
'page',
'font',
'hideIfSingle'
],
emits: ['pageChange', 'update:page']
} satisfies SetupComponentOptions<
PageProps,
@@ -115,8 +122,7 @@ export const Page = defineComponent<
const font = computed(() => props.font ?? new Font());
const isFirst = computed(() => nowPage.value === 0);
const isLast = computed(() => nowPage.value === props.pages - 1);
const width = computed(() => props.loc[2] ?? 200);
const height = computed(() => props.loc[3] ?? 200);
const [loc, width, height] = lwh(props);
const round = computed(() => font.value.size / 4);
const nowPageFont = computed(() => Font.clone(font.value, { weight: 700 }));
/** 页码的横向间距 */
@@ -135,6 +141,7 @@ export const Page = defineComponent<
const rightColor = computed(() => (isLast.value ? '#666' : '#ddd'));
let updating = false;
/** 更新页码矩形的位置 */
const updatePagePos = () => {
if (updating) return;
updating = true;
@@ -147,13 +154,14 @@ export const Page = defineComponent<
const center = width.value / 2;
const size = font.value.size * 1.5;
const int = size + interval.value;
nowPageLoc.value = [center, 0, size, size, 0.5, 0];
leftPageLoc.value = [center - int, 0, size, size, 0.5, 0];
leftLoc.value = [center - int * 2, 0, size, size, 0.5, 0];
rightPageLoc.value = [center + int, 0, size, size, 0.5, 0];
rightLoc.value = [center + int * 2, 0, size, size, 0.5, 0];
nowPageLoc.value = [center, 0, size, size];
leftPageLoc.value = [center - int, 0, size, size];
leftLoc.value = [center - int * 2, 0, size, size];
rightPageLoc.value = [center + int, 0, size, size];
rightLoc.value = [center + int * 2, 0, size, size];
};
/** 更新箭头的尺寸 */
const updateArrowPath = () => {
const rectSize = font.value.size * 1.5;
const size = font.value.size;
@@ -170,11 +178,11 @@ export const Page = defineComponent<
rightArrow.value = right;
};
/** 更新页码矩形和文字的位置 */
const updateRectAndText = () => {
const size = font.value.size * 1.5;
const pad = RECT_PAD * size;
rectLoc.value = [pad, pad, size - pad * 2, size - pad * 2];
textLoc.value = [size / 2, size / 2, void 0, void 0, 0.5, 0.5];
rectLoc.value = [0, 0, size, size];
textLoc.value = [size / 2, size / 2];
};
watch(font, () => {
@@ -236,118 +244,130 @@ export const Page = defineComponent<
expose<PageExpose>({ changePage, movePage, now });
return () => {
return (
<container loc={props.loc}>
<container loc={contentLoc.value}>
{slots.default?.(nowPage.value)}
return () => (
<container loc={loc.value}>
<container loc={contentLoc.value}>
{slots.default?.(nowPage.value)}
</container>
<container loc={pageLoc.value} hidden={hide.value} nocache>
<container
key={1}
loc={leftLoc.value}
anc={[0.5, 0]}
onClick={lastPage}
cursor="pointer"
nocache
>
<g-rectr
loc={rectLoc.value}
circle={[round.value]}
strokeStyle={leftColor.value}
lineWidth={1}
stroke
></g-rectr>
<g-path
path={leftArrow.value}
stroke
lineJoin="round"
lineCap="round"
strokeStyle={leftColor.value}
lineWidth={2}
></g-path>
</container>
<container loc={pageLoc.value} hidden={hide.value} nocache>
<container
key={1}
loc={leftLoc.value}
onClick={lastPage}
cursor="pointer"
nocache
>
<g-rectr
loc={rectLoc.value}
circle={[round.value]}
strokeStyle={leftColor.value}
lineWidth={1}
stroke
></g-rectr>
<g-path
path={leftArrow.value}
stroke
strokeStyle={leftColor.value}
lineWidth={1}
></g-path>
</container>
{!isFirst.value && (
<container
key={2}
loc={leftPageLoc.value}
onClick={lastPage}
cursor="pointer"
nocache
>
<g-rectr
loc={rectLoc.value}
circle={[round.value]}
strokeStyle="#ddd"
lineWidth={1}
stroke
></g-rectr>
<text
loc={textLoc.value}
text={nowPage.value.toString()}
font={font.value}
></text>
</container>
)}
<container loc={nowPageLoc.value} key={3} nocache>
<g-rectr
loc={rectLoc.value}
circle={[round.value]}
strokeStyle="#ddd"
fillStyle="#ddd"
lineWidth={1}
fill
stroke
></g-rectr>
<text
loc={textLoc.value}
text={(nowPage.value + 1).toString()}
fillStyle="#222"
font={nowPageFont.value}
></text>
</container>
{!isLast.value && (
<container
key={4}
loc={rightPageLoc.value}
onClick={nextPage}
cursor="pointer"
nocache
>
<g-rectr
loc={rectLoc.value}
circle={[round.value]}
strokeStyle="#ddd"
lineWidth={1}
stroke
></g-rectr>
<text
loc={textLoc.value}
text={(nowPage.value + 2).toString()}
font={font.value}
></text>
</container>
)}
<container
key={5}
loc={rightLoc.value}
onClick={nextPage}
cursor="pointer"
nocache
>
<g-rectr
loc={rectLoc.value}
circle={[round.value]}
strokeStyle={rightColor.value}
lineWidth={1}
stroke
></g-rectr>
<g-path
path={rightArrow.value}
stroke
strokeStyle={rightColor.value}
lineWidth={1}
></g-path>
</container>
<container
key={2}
loc={leftPageLoc.value}
anc={[0.5, 0]}
onClick={lastPage}
cursor="pointer"
hidden={isFirst.value}
nocache
>
<g-rectr
loc={rectLoc.value}
circle={[round.value]}
strokeStyle="#ddd"
lineWidth={1}
stroke
></g-rectr>
<text
loc={textLoc.value}
anc={[0.5, 0.5]}
text={nowPage.value.toString()}
font={font.value}
></text>
</container>
<container
loc={nowPageLoc.value}
anc={[0.5, 0]}
key={3}
nocache
>
<g-rectr
loc={rectLoc.value}
circle={[round.value]}
strokeStyle="#ddd"
fillStyle="#ddd"
lineWidth={1}
fill
stroke
></g-rectr>
<text
loc={textLoc.value}
anc={[0.5, 0.5]}
text={(nowPage.value + 1).toString()}
fillStyle="#222"
font={nowPageFont.value}
></text>
</container>
<container
key={4}
loc={rightPageLoc.value}
anc={[0.5, 0]}
onClick={nextPage}
cursor="pointer"
hidden={isLast.value}
nocache
>
<g-rectr
loc={rectLoc.value}
circle={[round.value]}
strokeStyle="#ddd"
lineWidth={1}
stroke
></g-rectr>
<text
loc={textLoc.value}
anc={[0.5, 0.5]}
text={(nowPage.value + 2).toString()}
font={font.value}
></text>
</container>
<container
key={5}
loc={rightLoc.value}
anc={[0.5, 0]}
onClick={nextPage}
cursor="pointer"
nocache
>
<g-rectr
loc={rectLoc.value}
circle={[round.value]}
strokeStyle={rightColor.value}
lineWidth={1}
stroke
></g-rectr>
<g-path
path={rightArrow.value}
stroke
strokeStyle={rightColor.value}
lineJoin="round"
lineCap="round"
lineWidth={2}
></g-path>
</container>
</container>
);
};
</container>
);
}, pageProps);
@@ -32,6 +32,7 @@ import { clamp } from 'lodash-es';
import { SetupComponentOptions } from '@motajs/system';
import {
DefaultProps,
lwh,
transitioned,
useRendererRoot
} from '@motajs/render-vue';
@@ -72,7 +73,7 @@ export type ScrollSlots = SlotsType<{
}>;
const scrollProps = {
props: ['hor', 'noscroll', 'loc', 'padEnd']
props: ['hor', 'noscroll', 'loc', 'x', 'y', 'width', 'height', 'padEnd']
} satisfies SetupComponentOptions<ScrollProps, {}, string, ScrollSlots>;
/** 滚动条图示的最短长度 */
@@ -124,8 +125,7 @@ export const Scroll = defineComponent<ScrollProps, {}, string, ScrollSlots>(
const scrollAlpha = transitioned(0.5, 100, linear())!;
const width = computed(() => props.loc[2] ?? 200);
const height = computed(() => props.loc[3] ?? 200);
const [loc, width, height] = lwh(props);
const direction = computed(() =>
props.hor ? ScrollDirection.Horizontal : ScrollDirection.Vertical
);
@@ -570,36 +570,34 @@ export const Scroll = defineComponent<ScrollProps, {}, string, ScrollSlots>(
//#endregion
return () => {
return (
<container loc={props.loc} onWheel={wheel} nocache>
<container-custom
loc={[0, 0, width.value, height.value]}
ref={content}
onDown={down}
render={renderContent}
propagate={customPropagate}
zIndex={0}
bindings={[scrollPos.ref.value, contentPos.ref.value]}
onUpdateChildren={updateScroll}
>
{slots.default?.()}
</container-custom>
<custom
nocache
hidden={props.noscroll}
loc={sp.value}
ref={scroll}
render={drawScroll}
onDown={downScroll}
onUp={upScroll}
zIndex={10}
onEnter={enter}
onLeave={leave}
></custom>
</container>
);
};
return () => (
<container loc={loc.value} onWheel={wheel} nocache>
<container-custom
loc={[0, 0, width.value, height.value]}
ref={content}
onDown={down}
render={renderContent}
propagate={customPropagate}
zIndex={0}
bindings={[scrollPos.ref.value, contentPos.ref.value]}
onUpdateChildren={updateScroll}
>
{slots.default?.()}
</container-custom>
<custom
nocache
hidden={props.noscroll}
loc={sp.value}
ref={scroll}
render={drawScroll}
onDown={downScroll}
onUp={upScroll}
zIndex={10}
onEnter={enter}
onLeave={leave}
></custom>
</container>
);
},
scrollProps
);
@@ -1,6 +1,6 @@
import { IHookController } from '@motajs/common';
import { CanvasStyle, Font, IActionEvent, IRenderItem } from '@motajs/render';
import { DefaultProps } from '@motajs/render-vue';
import { DefaultProps, lwh } from '@motajs/render-vue';
import { SetupComponentOptions } from '@motajs/system';
import { clamp, isNil } from 'lodash-es';
import {
@@ -52,6 +52,8 @@ export type SliderEmits = {
const sliderProps = {
props: [
'loc',
'x',
'y',
'width',
'height',
'value',
@@ -88,8 +90,7 @@ export const Slider = defineComponent<
const value = ref(props.value ?? min.value);
const rect = ref<IRenderItem>();
const width = computed(() => props.loc?.[2] ?? props.width ?? 200);
const height = computed(() => props.loc?.[3] ?? props.height ?? 200);
const [loc, width, height] = lwh(props);
const cy = computed(() => height.value / 2);
const sx = computed(() => props.padding ?? 4);
@@ -196,13 +197,7 @@ export const Slider = defineComponent<
});
return () => (
<container
ref={rect}
loc={props.loc}
width={props.width}
height={props.height}
nocache
>
<container ref={rect} loc={loc.value} nocache>
<g-line
line={[sx.value, cy.value, ex.value, cy.value]}
lineCap="round"
@@ -161,8 +161,8 @@ export const TextContent = defineComponent<
const updateLoc = () => {
const height = getHeight();
const [x = 0, y = 0, , h = 0, ax = 0, ay = 0] = props.loc ?? loc.value;
loc.value = [x, y, props.width, props.autoHeight ? height : h, ax, ay];
const [x = 0, y = 0, , h = 0] = props.loc ?? loc.value;
loc.value = [x, y, props.width, props.autoHeight ? height : h];
emit('updateHeight', height);
};
@@ -17,7 +17,7 @@ export interface IWinskinProps extends DefaultProps {
}
const winskinProps = {
props: ['winskin', 'manager', 'texture']
props: ['winskin', 'manager', 'texture', 'borderSize']
} satisfies SetupComponentOptions<IWinskinProps>;
/** winskin 最小单元宽度 */