feat: 增加 egui 打卡列表窗口,便于和 Slint 比较

This commit is contained in:
2026-11-19 16:19:20 +08:00
parent 6c7bc68cd6
commit 65a35ed19b
4 changed files with 609 additions and 6 deletions
Generated
+354 -5
View File
@@ -18,6 +18,15 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618"
[[package]]
name = "accesskit"
version = "0.25.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e883d1d28c5fd5568c79ed2d2bd48d9f2fd3945c8974ed0f53690ceddb051be"
dependencies = [
"uuid",
]
[[package]]
name = "adler2"
version = "2.0.1"
@@ -145,9 +154,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aeb9553e62312c8756a5979254fc6d7da8bbeb5986a1e17037fab932f7037917"
dependencies = [
"clipboard-win",
"image",
"log",
"objc2 0.6.5",
"objc2-app-kit 0.3.2",
"objc2-core-foundation",
"objc2-core-graphics",
"objc2-foundation 0.3.2",
"parking_lot",
"percent-encoding",
@@ -657,6 +669,15 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "color"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ec7c5eb7a16992b1904d76c517d170ab353b0e0b3d5a0c81a8a0cd1037893cf"
dependencies = [
"bytemuck",
]
[[package]]
name = "color_quant"
version = "1.1.0"
@@ -1026,12 +1047,137 @@ version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edf234dd1594d6dd434a8fb8cada51ddbbc593e40e4a01556a0b31c62da2775b"
[[package]]
name = "ecolor"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31bcbef0d4263a63eb32c4834e5d711613035ce1333468e107d928923e21e6e2"
dependencies = [
"bytemuck",
"emath",
]
[[package]]
name = "eframe"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c5642501a65ca657d05f00c643a5c14ff2346cb3818032bfe23d58e1f8e5f84"
dependencies = [
"ahash",
"bytemuck",
"document-features",
"egui",
"egui-winit",
"egui_glow",
"egui_system_font_provider",
"glow 0.17.0",
"glutin",
"glutin-winit",
"image",
"js-sys",
"log",
"objc2 0.6.5",
"objc2-app-kit 0.3.2",
"objc2-foundation 0.3.2",
"parking_lot",
"percent-encoding",
"profiling",
"raw-window-handle",
"send_wrapper",
"static_assertions",
"wasm-bindgen",
"web-sys",
"web-time",
"windows-sys 0.61.2",
"winit",
]
[[package]]
name = "egui"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec9144f49b7a28b5f395d3147e325b4fe3e77ba686eac11d1bdf0a7da3f375f"
dependencies = [
"accesskit",
"ahash",
"bitflags 2.13.2",
"emath",
"epaint",
"itertools",
"log",
"nohash-hasher",
"profiling",
"smallvec",
"unicode-segmentation",
"web-sys",
]
[[package]]
name = "egui-winit"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4e449f4c4a2a60c7ccb4ba7fa4078417bfe1f9ddc03b5e05ce75748e33a70de"
dependencies = [
"arboard",
"block2 0.6.2",
"bytemuck",
"egui",
"log",
"objc2 0.6.5",
"objc2-app-kit 0.3.2",
"objc2-foundation 0.3.2",
"objc2-ui-kit 0.3.2",
"profiling",
"raw-window-handle",
"smithay-clipboard",
"web-time",
"windows-sys 0.61.2",
"winit",
]
[[package]]
name = "egui_glow"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9275ca5cc35a6b7c94e0e8cedf22542f66cb0cf45ed8ab2657c78ff49fec7268"
dependencies = [
"bytemuck",
"egui",
"glow 0.17.0",
"log",
"profiling",
]
[[package]]
name = "egui_system_font_provider"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f2a2fdfe3c05dd9f691d2b1388b2312d6dce1af502f217c22136d22d9bd76f6"
dependencies = [
"epaint",
"fontique 0.11.1",
"log",
"poll-promise",
"skrifa",
"sys-locale",
"unicode-script",
]
[[package]]
name = "either"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
[[package]]
name = "emath"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e73ce90f54750be8672c02be0743fe47530e6f251e066f0ee2869b59eb297af5"
dependencies = [
"bytemuck",
]
[[package]]
name = "endi"
version = "1.1.1"
@@ -1059,6 +1205,38 @@ dependencies = [
"syn 2.0.119",
]
[[package]]
name = "epaint"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97bac86ae3dde93fc3951e790951caea739ff39a6c89d909cdaf1d9278dbb1bd"
dependencies = [
"ahash",
"bytemuck",
"ecolor",
"emath",
"epaint_default_fonts",
"font-types",
"harfrust",
"log",
"nohash-hasher",
"parking_lot",
"profiling",
"self_cell",
"skrifa",
"smallvec",
"unicode-general-category",
"unicode-properties",
"unicode-segmentation",
"vello_cpu",
]
[[package]]
name = "epaint_default_fonts"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfc1cc505827f4c23eedc297975a0fd038268d41293f389dd8ff3b574aefab19"
[[package]]
name = "equivalent"
version = "1.0.3"
@@ -1116,6 +1294,12 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223"
[[package]]
name = "fax"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caf1079563223d5d59d83c85886a56e586cfd5c1a26292e971a0fa266531ac5a"
[[package]]
name = "fdeflate"
version = "0.3.7"
@@ -1125,6 +1309,12 @@ dependencies = [
"simd-adler32",
]
[[package]]
name = "fearless_simd"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97b65636e5b9ef369943878ac74335ba1c55c1cb6adbf1e2c293c624248d693"
[[package]]
name = "field-offset"
version = "0.3.6"
@@ -1205,6 +1395,28 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "fontique"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6688bc1294fe7117d788937b6c53480169b29c566954af490830d4c09da9516a"
dependencies = [
"hashbrown 0.17.1",
"linebender_resource_handle",
"memmap2",
"objc2 0.6.5",
"objc2-core-foundation",
"objc2-core-text",
"objc2-foundation 0.3.2",
"parlance",
"read-fonts",
"roxmltree",
"smallvec",
"windows",
"windows-core",
"yeslogic-fontconfig-sys",
]
[[package]]
name = "fontique"
version = "0.12.0"
@@ -1454,12 +1666,41 @@ dependencies = [
"xml-rs",
]
[[package]]
name = "glifo"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282a26c1e23de04bdab3e34a21b6f877a479b96737792516b9b8b8f69b6661be"
dependencies = [
"bytemuck",
"foldhash",
"hashbrown 0.17.1",
"log",
"peniko",
"png",
"skrifa",
"smallvec",
"vello_common",
]
[[package]]
name = "glob"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
[[package]]
name = "glow"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29038e1c483364cc6bb3cf78feee1816002e127c331a1eec55a4d202b9e1adb5"
dependencies = [
"js-sys",
"slotmap",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "glow"
version = "0.18.0"
@@ -1552,6 +1793,15 @@ dependencies = [
"windows",
]
[[package]]
name = "guillotiere"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b17e70c989c36bad147b27a58d148c0741c51448aa5653436547323e524d0ab"
dependencies = [
"euclid",
]
[[package]]
name = "half"
version = "2.7.1"
@@ -1822,7 +2072,7 @@ checksum = "d0d03eef528cd0aec45f3cc9d557f4dbe952433f8e29a46576e7e9c36264eeff"
dependencies = [
"derive_more",
"euclid",
"fontique",
"fontique 0.12.0",
"htmlparser",
"icu_decimal",
"icu_locale_core",
@@ -1945,7 +2195,7 @@ dependencies = [
"cfg_aliases",
"clru",
"const-field-offset",
"glow",
"glow 0.18.0",
"glutin",
"i-slint-common",
"i-slint-core",
@@ -2219,6 +2469,7 @@ dependencies = [
"moxcms",
"num-traits",
"png",
"tiff",
"zune-core",
"zune-jpeg",
]
@@ -2708,6 +2959,12 @@ dependencies = [
"libc",
]
[[package]]
name = "nohash-hasher"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
[[package]]
name = "nom"
version = "7.1.3"
@@ -2833,6 +3090,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c"
dependencies = [
"bitflags 2.13.2",
"block2 0.6.2",
"objc2 0.6.5",
"objc2-core-foundation",
"objc2-core-graphics",
@@ -3206,7 +3464,7 @@ version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61bd0c0c1737f0b3d3726dc06b225083af213b61913e4fbae1670613a106c6ce"
dependencies = [
"fontique",
"fontique 0.12.0",
"hashbrown 0.17.1",
"linebender_resource_handle",
"parlance",
@@ -3236,7 +3494,7 @@ version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b74c0d373e462e504ad4436710a39f099e18e848e1ee711f70cd2dcd5a69b290"
dependencies = [
"fontique",
"fontique 0.12.0",
"harfrust",
"hashbrown 0.17.1",
"icu_locale_core",
@@ -3259,6 +3517,19 @@ dependencies = [
"base64ct",
]
[[package]]
name = "peniko"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "839c8299360d2e998bdb106dc0a6cd71dcc5f4df51df1b620361bf50e283cca6"
dependencies = [
"bytemuck",
"color",
"kurbo",
"linebender_resource_handle",
"smallvec",
]
[[package]]
name = "percent-encoding"
version = "2.3.2"
@@ -3366,6 +3637,16 @@ dependencies = [
"miniz_oxide 0.8.9",
]
[[package]]
name = "poll-promise"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f6a58fecbf9da8965bcdb20ce4fd29788d1acee68ddbb64f0ba1b81bccdb7df"
dependencies = [
"document-features",
"static_assertions",
]
[[package]]
name = "polling"
version = "3.11.0"
@@ -3497,6 +3778,7 @@ dependencies = [
"aes-gcm",
"base64 0.22.1",
"chrono",
"eframe",
"rand 0.8.8",
"reqwest",
"rsa",
@@ -4050,12 +4332,24 @@ dependencies = [
"tiny-skia 0.11.4",
]
[[package]]
name = "self_cell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ab42ca02749e120097e328d91d415325bdf43b1c72c4c8badf37375fe40a813"
[[package]]
name = "semver"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
[[package]]
name = "send_wrapper"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73"
[[package]]
name = "serde"
version = "1.0.229"
@@ -4276,7 +4570,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c891a6914ae994bca6972cca44d1371901a051ab2bd6178985d2489a1cd3af7"
dependencies = [
"derive_more",
"fontique",
"fontique 0.12.0",
"i-slint-compiler",
"spin_on",
"toml_edit",
@@ -4690,6 +4984,20 @@ dependencies = [
"syn 3.0.10",
]
[[package]]
name = "tiff"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63feaf3343d35b6ca4d50483f94843803b0f51634937cc2ec519fc32232bc52"
dependencies = [
"fax",
"flate2",
"half",
"quick-error",
"weezl",
"zune-jpeg",
]
[[package]]
name = "tiny-skia"
version = "0.11.4"
@@ -4975,6 +5283,12 @@ version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5"
[[package]]
name = "unicode-general-category"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b993bddc193ae5bd0d623b49ec06ac3e9312875fdae725a975c51db1cc1677f"
[[package]]
name = "unicode-ident"
version = "1.0.27"
@@ -4987,6 +5301,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
[[package]]
name = "unicode-properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "993ad287eb20e8ba755312801cfe1413e0f25d604075863acaddca10b04c1833"
[[package]]
name = "unicode-script"
version = "0.5.9"
@@ -5105,6 +5425,35 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "vello_common"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbb2141a2bca6e6d598e471fd4d1d7eed8e020aad6a28187edda07f091a325dd"
dependencies = [
"bytemuck",
"fearless_simd",
"guillotiere",
"log",
"peniko",
"png",
"smallvec",
"thiserror 2.0.21",
]
[[package]]
name = "vello_cpu"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace506ca414548966fcf3c283be94eb1cad8254de488791ee698bf438b0890a9"
dependencies = [
"bytemuck",
"glifo",
"hashbrown 0.17.1",
"png",
"vello_common",
]
[[package]]
name = "version_check"
version = "0.9.5"
+9
View File
@@ -17,6 +17,15 @@ serde_json = { version = "1", features = ["preserve_order"] }
sha2 = "0.10"
thiserror = "2"
slint = { version = "1", default-features = false, features = ["std", "compat-1-18", "backend-winit", "renderer-software"] }
eframe = { version = "0.37", optional = true, default-features = false, features = ["default_fonts", "glow", "system_fonts", "clipboard"] }
[features]
egui = ["dep:eframe"]
[[bin]]
name = "punchlog-egui"
path = "src/bin/punchlog-egui.rs"
required-features = ["egui"]
[build-dependencies]
slint-build = "1"
+2 -1
View File
@@ -5,10 +5,11 @@
```powershell
cargo run
cargo run --bin punchlog-ui
cargo run --bin punchlog-egui --features egui
cargo run --bin extract-device -- --write
```
`punchlog-ui` 打开最近一周的列表窗口。
`punchlog-ui` 是 Slint 窗口,`punchlog-egui` 是同一份最近一周数据的 egui 窗口。
第二条需要手机打开 USB 调试并具有 root,用来把当前 iCenter 的版本和设备身份写回 `.env`。
+244
View File
@@ -0,0 +1,244 @@
//! egui 版最近一周打卡列表。数据和 `punchlog-ui` 相同,用来并排比较。
use eframe::egui;
const BG: egui::Color32 = egui::Color32::from_rgb(0xf7, 0xf7, 0xf5);
const INK: egui::Color32 = egui::Color32::from_rgb(0x1a, 0x1a, 0x1a);
const MUTED: egui::Color32 = egui::Color32::from_rgb(0x6a, 0x6a, 0x6a);
const FAINT: egui::Color32 = egui::Color32::from_rgb(0x8a, 0x8a, 0x8a);
const LINE: egui::Color32 = egui::Color32::from_rgb(0xe6, 0xe6, 0xe3);
struct Row {
date: String,
mark: String,
time: String,
hours: String,
status: String,
site: String,
memo: String,
problem: bool,
}
struct View {
range: String,
error: String,
rows: Vec<Row>,
}
struct PunchApp {
view: View,
}
fn main() -> eframe::Result {
let view = load_view();
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([880.0, 720.0])
.with_title("打卡"),
renderer: eframe::Renderer::Glow,
system_font_fallback: true,
persist_window: false,
centered: true,
..Default::default()
};
eframe::run_native(
"punchlog",
options,
Box::new(move |cc| {
install_look(&cc.egui_ctx);
Ok(Box::new(PunchApp { view }))
}),
)
}
impl eframe::App for PunchApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
ui.painter().rect_filled(ui.max_rect(), 0.0, BG);
let refresh = header(ui, &self.view.range);
if refresh {
self.view = load_view();
}
hairline(ui);
if !self.view.error.is_empty() {
message(ui, &self.view.error, INK);
return;
}
if self.view.rows.is_empty() {
message(ui, "这一周没有打卡记录。", FAINT);
return;
}
egui::ScrollArea::vertical()
.auto_shrink([false, false])
.show(ui, |ui| {
for row in &self.view.rows {
day(ui, row);
hairline(ui);
}
});
}
fn clear_color(&self, _visuals: &egui::Visuals) -> [f32; 4] {
BG.to_normalized_gamma_f32()
}
}
fn header(ui: &mut egui::Ui, range: &str) -> bool {
ui.allocate_ui_with_layout(
egui::vec2(ui.available_width(), 52.0),
egui::Layout::left_to_right(egui::Align::Center),
|ui| {
ui.set_width(ui.available_width());
ui.spacing_mut().item_spacing.x = 0.0;
ui.add_space(24.0);
ui.label(egui::RichText::new("打卡").size(16.0).strong().color(INK));
ui.add_space(16.0);
ui.label(egui::RichText::new(range).size(13.0).color(FAINT));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.add_space(24.0);
let (rect, response) =
ui.allocate_exact_size(egui::vec2(48.0, 32.0), egui::Sense::click());
ui.painter().text(
rect.right_center(),
egui::Align2::RIGHT_CENTER,
"刷新",
egui::FontId::proportional(13.0),
INK,
);
if response.hovered() {
ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand);
}
response.clicked()
})
.inner
},
)
.inner
}
fn day(ui: &mut egui::Ui, row: &Row) {
let width = ui.available_width();
ui.add_space(14.0);
ui.horizontal(|ui| {
ui.set_min_width(width);
ui.spacing_mut().item_spacing.x = 0.0;
ui.add_space(24.0);
ui.label(egui::RichText::new(&row.date).size(15.0).strong().color(INK));
ui.add_space(16.0);
ui.label(egui::RichText::new(&row.time).size(13.0).color(MUTED));
ui.add_space(16.0);
ui.label(egui::RichText::new(&row.hours).size(13.0).color(MUTED));
if !row.mark.is_empty() {
ui.add_space(12.0);
ui.label(egui::RichText::new(&row.mark).size(13.0).color(MUTED));
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.add_space(24.0);
let color = if row.problem { INK } else { MUTED };
ui.label(egui::RichText::new(&row.status).size(13.0).color(color));
});
});
ui.add_space(8.0);
ui.horizontal(|ui| {
ui.add_space(24.0);
ui.vertical(|ui| {
ui.set_width((width - 48.0).max(0.0));
ui.spacing_mut().item_spacing.y = 4.0;
if !row.site.is_empty() {
ui.add(
egui::Label::new(egui::RichText::new(&row.site).size(12.0).color(FAINT))
.wrap_mode(egui::TextWrapMode::Truncate),
);
}
if !row.memo.is_empty() {
ui.label(egui::RichText::new(&row.memo).size(14.0).color(INK));
}
});
});
ui.add_space(14.0);
}
fn message(ui: &mut egui::Ui, text: &str, color: egui::Color32) {
ui.add_space(16.0);
ui.horizontal(|ui| {
ui.add_space(24.0);
ui.add(egui::Label::new(egui::RichText::new(text).size(14.0).color(color)).wrap());
});
}
fn hairline(ui: &mut egui::Ui) {
let rect = ui.available_rect_before_wrap();
let y = ui.cursor().top();
ui.painter()
.hline(rect.x_range(), y, egui::Stroke::new(1.0, LINE));
ui.add_space(1.0);
}
fn install_look(ctx: &egui::Context) {
install_font(ctx);
let mut style = (*ctx.global_style()).clone();
style.visuals.panel_fill = BG;
style.visuals.window_fill = BG;
style.visuals.extreme_bg_color = BG;
style.visuals.faint_bg_color = BG;
style.visuals.code_bg_color = BG;
style.visuals.override_text_color = Some(INK);
style.visuals.window_shadow = egui::Shadow::NONE;
style.visuals.popup_shadow = egui::Shadow::NONE;
style.visuals.selection.bg_fill = egui::Color32::from_rgb(0xe7, 0xe7, 0xe2);
style.visuals.selection.stroke.color = egui::Color32::from_rgb(0xc8, 0xc8, 0xc2);
style.spacing.item_spacing = egui::vec2(0.0, 4.0);
style.spacing.scroll = egui::style::ScrollStyle::floating();
ctx.set_global_style(style);
}
fn install_font(ctx: &egui::Context) {
let Ok(bytes) = std::fs::read(r"C:\Windows\Fonts\msyh.ttc") else {
return;
};
let mut fonts = egui::FontDefinitions::default();
let blob: std::sync::Arc<dyn AsRef<[u8]> + Send + Sync> = std::sync::Arc::new(bytes);
fonts.font_data.insert(
"yahei".to_owned(),
std::sync::Arc::new(egui::FontData::from_blob(blob, 0)),
);
for family in [egui::FontFamily::Proportional, egui::FontFamily::Monospace] {
if let Some(list) = fonts.families.get_mut(&family) {
list.insert(0, "yahei".to_owned());
}
}
ctx.set_fonts(fonts);
}
fn load_view() -> View {
match load_report() {
Ok(report) => View {
range: format!("{} — {}", report.start, report.end),
error: String::new(),
rows: report.days.iter().map(to_row).collect(),
},
Err(err) => View {
range: String::new(),
error: err.to_string(),
rows: Vec::new(),
},
}
}
fn load_report() -> punchlog::Result<punchlog::WeekReport> {
let mut config = punchlog::AppConfig::load()?;
punchlog::load_last_week(&mut config)
}
fn to_row(day: &punchlog::DaySummary) -> Row {
let (site, memo) = day.content();
Row {
date: day.day.format("%m-%d").to_string(),
mark: if day.has_supplement { "补" } else { "" }.to_owned(),
time: format!("{} – {}", day.first.format("%H:%M"), day.last.format("%H:%M")),
hours: format!("{:.1}h", day.hours),
status: day.status.label().to_owned(),
site,
memo: memo.replace(" / ", "\n"),
problem: day.status.is_problem(),
}
}