docs: 给界面控件补上中文注释

This commit is contained in:
2026-11-19 17:03:44 +08:00
parent 3b737a881f
commit f565f7a3c3
+30
View File
@@ -1,5 +1,7 @@
// 标准控件:滚动列表、日历弹层、日期类型。
import { ScrollView, DatePickerPopup, Date } from "std-widgets.slint"; import { ScrollView, DatePickerPopup, Date } from "std-widgets.slint";
// 一天的展示数据,由 Rust 填好后交给列表。
export struct DayRow { export struct DayRow {
date: string, date: string,
mark: string, mark: string,
@@ -11,6 +13,7 @@ export struct DayRow {
problem: bool, problem: bool,
} }
// 日期框。外框是矩形,点击后弹出日历。
component DateField inherits Rectangle { component DateField inherits Rectangle {
in-out property <Date> date; in-out property <Date> date;
in property <string> title; in property <string> title;
@@ -28,6 +31,7 @@ component DateField inherits Rectangle {
return "" + n; return "" + n;
} }
// 框里显示的日期文字,例如 2026-11-13。
Text { Text {
x: 8px; x: 8px;
width: parent.width - 16px; width: parent.width - 16px;
@@ -39,6 +43,7 @@ component DateField inherits Rectangle {
vertical-alignment: center; vertical-alignment: center;
} }
// 日历弹层。确定后把选中的日期交回给日期框。
picker := DatePickerPopup { picker := DatePickerPopup {
title: root.title; title: root.title;
date: root.date; date: root.date;
@@ -48,6 +53,7 @@ component DateField inherits Rectangle {
} }
} }
// 盖住整个日期框的点击区域,用来打开上面的日历。
TouchArea { TouchArea {
width: parent.width; width: parent.width;
height: parent.height; height: parent.height;
@@ -57,11 +63,13 @@ component DateField inherits Rectangle {
} }
} }
// 列表中的一天。外框是矩形。
component DayBlock inherits Rectangle { component DayBlock inherits Rectangle {
in property <DayRow> day; in property <DayRow> day;
height: 112px; height: 112px;
background: #f7f7f5; background: #f7f7f5;
// 顶行横向排列:日期、时间、时长靠左,站点靠右。
HorizontalLayout { HorizontalLayout {
x: 24px; x: 24px;
y: 12px; y: 12px;
@@ -70,6 +78,7 @@ component DayBlock inherits Rectangle {
spacing: 8px; spacing: 8px;
alignment: start; alignment: start;
// 日期,例如 11-13。
Text { Text {
text: day.date; text: day.date;
font-size: 15px; font-size: 15px;
@@ -78,6 +87,7 @@ component DayBlock inherits Rectangle {
vertical-alignment: center; vertical-alignment: center;
} }
// 当天最早到最晚的时间。
Text { Text {
text: day.time; text: day.time;
font-size: 13px; font-size: 13px;
@@ -85,6 +95,7 @@ component DayBlock inherits Rectangle {
vertical-alignment: center; vertical-alignment: center;
} }
// 最早和最晚相隔的小时数。
Text { Text {
text: day.hours; text: day.hours;
font-size: 13px; font-size: 13px;
@@ -92,6 +103,7 @@ component DayBlock inherits Rectangle {
vertical-alignment: center; vertical-alignment: center;
} }
// 这一天有补卡时才显示「补」。
if day.mark != "": Text { if day.mark != "": Text {
text: day.mark; text: day.mark;
font-size: 13px; font-size: 13px;
@@ -99,6 +111,7 @@ component DayBlock inherits Rectangle {
vertical-alignment: center; vertical-alignment: center;
} }
// 占满顶行剩余宽度,把站点文字挤到右边;超出时省略。
Rectangle { Rectangle {
horizontal-stretch: 1; horizontal-stretch: 1;
min-width: 24px; min-width: 24px;
@@ -117,6 +130,7 @@ component DayBlock inherits Rectangle {
} }
} }
// 右下角状态:正常、缺卡或时长不足。
status-text := Text { status-text := Text {
x: parent.width - 24px - self.width; x: parent.width - 24px - self.width;
y: parent.height - 16px - self.height; y: parent.height - 16px - self.height;
@@ -126,6 +140,7 @@ component DayBlock inherits Rectangle {
horizontal-alignment: right; horizontal-alignment: right;
} }
// 打卡内容。宽度停在状态左边,避免盖住右下角。
Text { Text {
x: 24px; x: 24px;
y: 42px; y: 42px;
@@ -139,6 +154,7 @@ component DayBlock inherits Rectangle {
vertical-alignment: top; vertical-alignment: top;
} }
// 这一天底部的分隔线。
Rectangle { Rectangle {
x: 0px; x: 0px;
y: parent.height - 1px; y: parent.height - 1px;
@@ -148,6 +164,7 @@ component DayBlock inherits Rectangle {
} }
} }
// 主窗口。
export component MainWindow inherits Window { export component MainWindow inherits Window {
in property <[DayRow]> days; in property <[DayRow]> days;
in-out property <Date> start-date; in-out property <Date> start-date;
@@ -164,6 +181,7 @@ export component MainWindow inherits Window {
background: #f7f7f5; background: #f7f7f5;
default-font-family: "Segoe UI"; default-font-family: "Segoe UI";
// 左上角标题。
Text { Text {
x: 24px; x: 24px;
y: 16px; y: 16px;
@@ -174,6 +192,7 @@ export component MainWindow inherits Window {
horizontal-alignment: left; horizontal-alignment: left;
} }
// 开始日期。选完后通知 Rust 按新范围重新拉取。
DateField { DateField {
x: 76px; x: 76px;
y: 12px; y: 12px;
@@ -183,6 +202,7 @@ export component MainWindow inherits Window {
accepted => { root.range-changed(); } accepted => { root.range-changed(); }
} }
// 两个日期中间的间隔符。
Text { Text {
x: 190px; x: 190px;
y: 16px; y: 16px;
@@ -192,6 +212,7 @@ export component MainWindow inherits Window {
horizontal-alignment: left; horizontal-alignment: left;
} }
// 结束日期。
DateField { DateField {
x: 210px; x: 210px;
y: 12px; y: 12px;
@@ -201,6 +222,7 @@ export component MainWindow inherits Window {
accepted => { root.range-changed(); } accepted => { root.range-changed(); }
} }
// 右上角刷新按钮。加载时文字变成「正在刷新」,并且不能再点。
TouchArea { TouchArea {
x: parent.width - 28px - 80px; x: parent.width - 28px - 80px;
y: 0px; y: 0px;
@@ -218,6 +240,7 @@ export component MainWindow inherits Window {
clicked => { root.refresh(); } clicked => { root.refresh(); }
} }
// 标题区域和列表之间的分隔线。
Rectangle { Rectangle {
x: 0px; x: 0px;
y: 51px; y: 51px;
@@ -226,6 +249,7 @@ export component MainWindow inherits Window {
background: #e6e6e3; background: #e6e6e3;
} }
// 拉取失败时显示的错误文字。
if root.error != "": Text { if root.error != "": Text {
x: 24px; x: 24px;
y: 68px; y: 68px;
@@ -237,6 +261,7 @@ export component MainWindow inherits Window {
horizontal-alignment: left; horizontal-alignment: left;
} }
// 这个日期范围内没有打卡记录。
if !root.loading && root.error == "" && root.days.length == 0: Text { if !root.loading && root.error == "" && root.days.length == 0: Text {
x: 24px; x: 24px;
y: 68px; y: 68px;
@@ -246,6 +271,7 @@ export component MainWindow inherits Window {
horizontal-alignment: left; horizontal-alignment: left;
} }
// 打卡列表。ScrollView 负责滚动,里面的纵向布局把每一天从上往下排。
if root.error == "" && root.days.length > 0: ScrollView { if root.error == "" && root.days.length > 0: ScrollView {
x: 0px; x: 0px;
y: 52px; y: 52px;
@@ -260,6 +286,7 @@ export component MainWindow inherits Window {
} }
} }
// 刷新完成后的顶部提示条。贴住标题栏,点击可关,3 秒后由 Rust 自动关掉。
if root.toast != "": island := Rectangle { if root.toast != "": island := Rectangle {
property <length> capsule-width: min(parent.width - 80px, notice.preferred-width + close-mark.preferred-width + 32px); property <length> capsule-width: min(parent.width - 80px, notice.preferred-width + close-mark.preferred-width + 32px);
@@ -273,6 +300,7 @@ export component MainWindow inherits Window {
border-bottom-right-radius: 15px; border-bottom-right-radius: 15px;
background: #1a1a1a; background: #1a1a1a;
// 提示文字,例如「已刷新」。
notice := Text { notice := Text {
x: 16px; x: 16px;
height: parent.height; height: parent.height;
@@ -283,6 +311,7 @@ export component MainWindow inherits Window {
overflow: elide; overflow: elide;
} }
// 右侧红色关闭标记,距提示条右边缘 8 像素。
close-mark := Text { close-mark := Text {
x: parent.width - 8px - self.width; x: parent.width - 8px - self.width;
height: parent.height; height: parent.height;
@@ -293,6 +322,7 @@ export component MainWindow inherits Window {
vertical-alignment: center; vertical-alignment: center;
} }
// 整条提示都可以点击关闭。
TouchArea { TouchArea {
width: parent.width; width: parent.width;
height: parent.height; height: parent.height;