mirror of
https://github.com/motajs/template.git
synced 2026-11-30 02:34:30 +08:00
docs: 补充文字 typer 演示
This commit is contained in:
1 parent
c6f1755a59
commit
928903b497
3 files changed
+225
No files matched your search
@@ -0,0 +1,72 @@
|
||||
import { Font } from '@motajs/render';
|
||||
import { defineComponent, markRaw } from 'vue';
|
||||
import { TextContent } from '../../../../../packages-user/client-base/src/components/textbox';
|
||||
import {
|
||||
TextAlign,
|
||||
TextContentTyper
|
||||
} from '../../../../../packages-user/client-base/src/components/textboxTyper';
|
||||
|
||||
const TEXT = '字体与字号\n行高与对齐\n颜色来自 typer';
|
||||
|
||||
const LEFT = markRaw(
|
||||
new TextContentTyper({
|
||||
font: new Font('Verdana', 18),
|
||||
lineHeight: 8,
|
||||
textAlign: TextAlign.Left,
|
||||
fillStyle: '#e8f0ff'
|
||||
})
|
||||
);
|
||||
|
||||
const CENTER = markRaw(
|
||||
new TextContentTyper({
|
||||
font: new Font('Georgia', 18),
|
||||
lineHeight: 12,
|
||||
textAlign: TextAlign.Center,
|
||||
fillStyle: '#7ee787'
|
||||
})
|
||||
);
|
||||
|
||||
const RIGHT = markRaw(
|
||||
new TextContentTyper({
|
||||
font: new Font('Courier New', 16),
|
||||
lineHeight: 6,
|
||||
textAlign: TextAlign.Right,
|
||||
fillStyle: '#f2b84b'
|
||||
})
|
||||
);
|
||||
|
||||
// typer 配置:字体、字号、行高、对齐与填充色分别写在三个 typer 上
|
||||
export default defineComponent(() => {
|
||||
return () => (
|
||||
<container loc={[0, 0, 480, 320]}>
|
||||
<g-rect loc={[0, 0, 480, 320]} fillStyle="#141a22" />
|
||||
|
||||
<g-rect loc={[24, 52, 132, 210]} fillStyle="#101820" />
|
||||
<g-rect loc={[174, 52, 132, 210]} fillStyle="#101820" />
|
||||
<g-rect loc={[324, 52, 132, 210]} fillStyle="#101820" />
|
||||
|
||||
<text loc={[32, 24]} text="左对齐" fillStyle="#8b98a8" />
|
||||
<text loc={[182, 24]} text="居中" fillStyle="#8b98a8" />
|
||||
<text loc={[332, 24]} text="右对齐" fillStyle="#8b98a8" />
|
||||
|
||||
<TextContent
|
||||
loc={[32, 72, 116, 170]}
|
||||
autoHeight
|
||||
typer={LEFT}
|
||||
text={TEXT}
|
||||
/>
|
||||
<TextContent
|
||||
loc={[182, 72, 116, 170]}
|
||||
autoHeight
|
||||
typer={CENTER}
|
||||
text={TEXT}
|
||||
/>
|
||||
<TextContent
|
||||
loc={[332, 72, 116, 170]}
|
||||
autoHeight
|
||||
typer={RIGHT}
|
||||
text={TEXT}
|
||||
/>
|
||||
</container>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
import { defineComponent, markRaw, nextTick, ref } from 'vue';
|
||||
import {
|
||||
TextContent,
|
||||
TextContentExpose
|
||||
} from '../../../../../packages-user/client-base/src/components/textbox';
|
||||
import { TextContentTyper } from '../../../../../packages-user/client-base/src/components/textboxTyper';
|
||||
|
||||
const TYPER = markRaw(
|
||||
new TextContentTyper({
|
||||
interval: 80,
|
||||
lineHeight: 6,
|
||||
fillStyle: '#e8f0ff'
|
||||
})
|
||||
);
|
||||
|
||||
const TEXT =
|
||||
'第一行:点击开始后逐字出现。\n' +
|
||||
'[c=#f2b84b]第二行:interval 控制每个字的间隔。[/c]\n' +
|
||||
'[w=8]等待八个字的打字时间后继续。\n' +
|
||||
'[c=#7ee787]最后一行:可以随时立即显示全文。[/c]';
|
||||
|
||||
// 打字演示:初始不开始,按按钮后才逐字显示;重播与立即显示都是真实方法
|
||||
export default defineComponent(() => {
|
||||
const content = ref<TextContentExpose>();
|
||||
const started = ref(false);
|
||||
const status = ref('等待开始');
|
||||
|
||||
const start = async () => {
|
||||
if (!started.value) {
|
||||
started.value = true;
|
||||
await nextTick();
|
||||
}
|
||||
content.value?.retype();
|
||||
};
|
||||
|
||||
const reveal = () => {
|
||||
content.value?.showAll();
|
||||
};
|
||||
|
||||
return () => (
|
||||
<container loc={[0, 0, 480, 320]}>
|
||||
<g-rect loc={[0, 0, 480, 320]} fillStyle="#141a22" />
|
||||
|
||||
<text loc={[40, 24]} text="打字演示" fillStyle="#cfe0ff" />
|
||||
<text loc={[40, 48]} text={status.value} fillStyle="#8b98a8" />
|
||||
|
||||
<g-rect loc={[24, 76, 432, 150]} fillStyle="#101820" />
|
||||
<TextContent
|
||||
ref={content}
|
||||
loc={[40, 90, 400, 120]}
|
||||
autoHeight
|
||||
typer={TYPER}
|
||||
text={started.value ? TEXT : ''}
|
||||
onTypeStart={() => {
|
||||
if (started.value) status.value = '正在打字';
|
||||
}}
|
||||
onTypeEnd={() => {
|
||||
if (started.value) status.value = '打字结束';
|
||||
}}
|
||||
/>
|
||||
|
||||
<container loc={[40, 246, 120, 30]} onClick={start}>
|
||||
<g-rectr
|
||||
loc={[0, 0, 120, 30]}
|
||||
circle={[6]}
|
||||
fillStyle="#2f6fed"
|
||||
/>
|
||||
<text loc={[14, 7]} text="开始 / 重播" fillStyle="#ffffff" />
|
||||
</container>
|
||||
<container loc={[176, 246, 120, 30]} onClick={reveal}>
|
||||
<g-rectr
|
||||
loc={[0, 0, 120, 30]}
|
||||
circle={[6]}
|
||||
fillStyle="#33465f"
|
||||
/>
|
||||
<text loc={[14, 7]} text="立即显示" fillStyle="#e8f0ff" />
|
||||
</container>
|
||||
</container>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
import { Font } from '@motajs/render';
|
||||
import { defineComponent, markRaw } from 'vue';
|
||||
import { TextContent } from '../../../../../packages-user/client-base/src/components/textbox';
|
||||
import {
|
||||
TextContentTyper,
|
||||
WordBreak
|
||||
} from '../../../../../packages-user/client-base/src/components/textboxTyper';
|
||||
|
||||
const TEXT =
|
||||
'alpha beta gamma Supercalifragilisticexpialidocious delta epsilon';
|
||||
|
||||
const NONE = markRaw(
|
||||
new TextContentTyper({
|
||||
font: new Font('Verdana', 14),
|
||||
lineHeight: 4,
|
||||
wordBreak: WordBreak.None,
|
||||
fillStyle: '#f2b84b'
|
||||
})
|
||||
);
|
||||
|
||||
const SPACE = markRaw(
|
||||
new TextContentTyper({
|
||||
font: new Font('Verdana', 14),
|
||||
lineHeight: 4,
|
||||
wordBreak: WordBreak.Space,
|
||||
fillStyle: '#7ee787'
|
||||
})
|
||||
);
|
||||
|
||||
const ALL = markRaw(
|
||||
new TextContentTyper({
|
||||
font: new Font('Verdana', 14),
|
||||
lineHeight: 4,
|
||||
wordBreak: WordBreak.All,
|
||||
fillStyle: '#58c4dd'
|
||||
})
|
||||
);
|
||||
|
||||
// 折行规则:None 一行到底,Space 在空格与 CJK 处折行,All 任意字符可折行
|
||||
export default defineComponent(() => {
|
||||
return () => (
|
||||
<container loc={[0, 0, 480, 320]}>
|
||||
<g-rect loc={[0, 0, 480, 320]} fillStyle="#141a22" />
|
||||
|
||||
<g-rect loc={[20, 52, 136, 220]} fillStyle="#101820" />
|
||||
<g-rect loc={[172, 52, 136, 220]} fillStyle="#101820" />
|
||||
<g-rect loc={[324, 52, 136, 220]} fillStyle="#101820" />
|
||||
|
||||
<text loc={[28, 24]} text="None" fillStyle="#8b98a8" />
|
||||
<text loc={[180, 24]} text="Space" fillStyle="#8b98a8" />
|
||||
<text loc={[332, 24]} text="All" fillStyle="#8b98a8" />
|
||||
|
||||
<TextContent
|
||||
loc={[28, 72, 120, 180]}
|
||||
autoHeight
|
||||
typer={NONE}
|
||||
text={TEXT}
|
||||
/>
|
||||
<TextContent
|
||||
loc={[180, 72, 120, 180]}
|
||||
autoHeight
|
||||
typer={SPACE}
|
||||
text={TEXT}
|
||||
/>
|
||||
<TextContent
|
||||
loc={[332, 72, 120, 180]}
|
||||
autoHeight
|
||||
typer={ALL}
|
||||
text={TEXT}
|
||||
/>
|
||||
</container>
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user