1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Phase 2 验证:DirectWrite 中英文混排文字渲染。
//!
//! 截屏:cargo run --example phase2_text -- --screenshot artifacts/phase2.png
use windui::prelude::*;
fn row_label(text: &str, size: f32, color: u32) -> Element {
Element::label(text)
.font_size(size)
.fg(Color::hex(color))
.height_match()
}
fn main() {
let ui = Element::col()
.fill()
.padding(24)
.spacing(14)
.bg(Color::hex(0xFFFFFF))
.child(
Element::label("windui 文字渲染")
.font_size(28.0)
.fg(Color::hex(0x1A1A2E))
.width_match()
.height(40),
)
.child(
Element::label("基于 DirectWrite 的高质量中文排版")
.font_size(16.0)
.fg(Color::hex(0x555555))
.width_match()
.height(26),
)
// 不同字号
.child(row_label("16px:快速的棕色狐狸 Quick Fox 0123", 16.0, 0x333333).height(26))
.child(row_label("20px:轻量级桌面 GUI 框架", 20.0, 0x0066CC).height(32))
// 彩色块上的白字(验证任意背景合成)
.child(
Element::col()
.width_match()
.height(64)
.bg(Color::hex(0x6C5CE7))
.corner(8.0)
.padding_xy(16, 0)
.child(
Element::label("彩色背景上的白色文字 — 灰度抗锯齿合成")
.font_size(18.0)
.fg(Color::WHITE)
.fill(),
),
)
// 对齐演示
.child(
Element::row()
.width_match()
.height(40)
.spacing(8)
.child(
Element::label("左对齐")
.text_align(Align::Start)
.bg(Color::hex(0xF0F0F0))
.weight(1.0)
.height_match(),
)
.child(
Element::label("居中")
.text_align(Align::Center)
.bg(Color::hex(0xF0F0F0))
.weight(1.0)
.height_match(),
)
.child(
Element::label("右对齐")
.text_align(Align::End)
.bg(Color::hex(0xF0F0F0))
.weight(1.0)
.height_match(),
),
);
App::new("Phase 2 — 文字", 600, 420)
.bg(Color::hex(0xFFFFFF))
.screenshot_from_args()
.content(ui)
.run();
}