fix: 頁面的數字卡不再把視窗撐出標題列(× 跑到中間);所有對話框都不會被內容撐寬

使用者那一頁(機箱健康報告:四張數字卡、結論、九張表、兩張圖)打開時視窗比標題列寬,× 在中間。原因是數字卡:每張卡的標籤、數字、變化該疊成三行,卻繼承了外面那一排「左到右」的排法而並排,卡片遠比算好的寬,整排超出閱讀欄、撐寬視窗;第一張的字還疊在一起。

- 數字卡(page_kpis):每張直排三行、同一排一樣寬;四張並排每張不到 150 時一排兩張(三張 → 三張,否則一張);字太長以 … 結尾,滑過看全文。
- dialog_body:內容在自己的一塊裡畫,太寬的在視窗邊緣切掉,不再撐寬整個視窗(標題列和 × 不會再錯位);超出時照樣記進 WIDER_DIALOGS,版面檢查看得到。
- 版面檢查的頁面場景加上四張長字數字卡、結論和十欄寬表格;寬表格真的左右捲動時回報那一條(scrolls_sideways),捲到邊被切的字不算錯。換回原本的數字卡程式,檢查報 36 個問題(含「視窗被內容撐寬 281px」)。
- 截圖用的 ANYBOT_SHOT_PAGE_JSON:整頁(標題、kpis、結論)換成檔案裡的。
- LOOK_KEYS 只給測試用,標成 cfg(test)(消掉警告)。

已驗證:cargo test --bin anybot 529 通過(含 text_stays_inside_its_place_on_every_screen 新場景);用使用者那一頁截圖 1180/1500 寬:× 在右上角、數字卡兩排各兩張,往下捲九張表和兩張圖都在閱讀欄內。
未驗證:使用者自己的螢幕尺寸。
This commit is contained in:
王性驊 2026-11-17 00:40:50 +08:00
parent 0b57f33ac7
commit dbc3197f6a
7 changed files with 126 additions and 36 deletions

View File

@ -1572,8 +1572,9 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)
- **細節區塊** ```details 標題:預設收起,只顯示一行灰色「▸ 標題」(沒寫標題就是「細節」),點了展開裡面的 Markdown。讓第一屏只有結論、數字和下一步;證據、長清單、指令收在下面。
- **寫法檢查**:Bot 存頁面時程式先看一遍(Anthropic 的報告寫法:結論先講、句子短、少粗體、數字放卡片或表格、不用裝飾)。段落超過 120 字、一節超過一處粗體、括號裡一串數字、標題編號、分隔線、用「→」帶結論、表格裡放指令、正文很長卻沒有收起的細節——有就退回一次、列出每一處要怎麼改;同一頁第二次照存,不會卡住。
- 頁面是「閱讀排版」:內文排在置中的 720 像素欄位裡,行高 1.55 倍、段落有呼吸空間,不會貼著視窗邊緣;聊天室保持原本的緊湊排版。頁面上的數字表格(2–3 欄、資料不超過 8 列)在寬度夠時會自動左表右圖併排。
- 頁面視窗(和其他對話框)不會被內容撐寬:太寬的表格在閱讀欄裡左右捲動,其他太寬的東西在視窗邊緣切掉,標題列的 × 一直在右上角。(以前一頁四張數字卡把視窗撐出自己的標題列,× 跑到中間。)
- 有 3 個以上標題的頁面,標題下面有一行小字「▸ 目錄 · N 節」(不佔第一屏):點了展開成標題清單,每條可點、點了跳到那一節;展開時上面有小搜尋框可以篩標題(⌘F 直接展開並把光標放進去,Esc 離開)。
- 寫頁面時 Bot 會選一種「種類」(data 數據分析/compare 比較評測/decision 決策備忘/howto 教學步驟/timeline 時間線/prose 長文/notes 筆記),第一屏跟著內容走:data 頁頂部放 2–4 張 KPI 數字卡(附漲跌,漲綠跌紅),compare/decision 頁先給一行「結論」卡;種類顯示在頁面標題和聊天卡片的列中。字段全部可省略——沒有數字就不硬湊卡片。
- 寫頁面時 Bot 會選一種「種類」(data 數據分析/compare 比較評測/decision 決策備忘/howto 教學步驟/timeline 時間線/prose 長文/notes 筆記),第一屏跟著內容走:data 頁頂部放 2–4 張 KPI 數字卡(附漲跌,漲綠跌紅;每張三行疊著:標籤、數字、變化,四張並排太窄時一排兩張,字太長以 … 結尾、滑過看全文),compare/decision 頁先給一行「結論」卡;種類顯示在頁面標題和聊天卡片的列中。字段全部可省略——沒有數字就不硬湊卡片。
- 要定期追蹤時,Bot 會同時設例行任務:每次先 `read_page`、查新消息,有實質進展才更新頁面並告訴你;沒有就說「沒有新消息」,頁面不動。
- 每次更新保留上一版(最多 10 版),打開頁面後下方「版本紀錄」可以看舊版。也可以複製成 Markdown、存成檔案(到「下載」)、刪除。
- 右側面板「資料庫」最上面列出這個 Bot 的頁面。手機也能看:聊天裡的卡片、頁面連結、完整頁面(圖表由 AnyBot 畫好傳過去)。

View File

@ -16,14 +16,14 @@ Bot 把要追蹤、整理、比較的事寫成一頁,之後一直更新同一
- 回覆裡的 [標題](page:ID) 連結,和回覆下面的頁面卡片(一張精簡卡:頁面圖示、標題一次、一行它說什麼——更新過的是「已更新:改了什麼」,否則是現況那句——和一行灰字「種類 · 頁面 · 時間 · 第 N 版」):點一下打開。一個回覆裡每一頁只出一張卡,在最後存那一頁的步驟下面(被寫法檢查退回再存、或存了又更新,都不會重複);沒存成的(別的 Bot 的頁面被擋、被退回那一次)不出卡。手機一樣。
- 右側面板的「資料庫」分頁,最上面的「頁面」:這個 Bot 的頁面,最近改過的在前面。
- 打開的頁面像一份文件(和手機同一套):標題宋體粗體 28,下面一行小字作者、「更新於」、第幾版和「這一版更新了:…」;一行現況(summary)是開頭段落、不加框;結論(verdict)是淡底的「結論」提示框;kpis 是只有細框的數字卡。有 3 個以上的標題時有一行「▸ 目錄 · N 節」,點開才是標題清單和小搜尋框(⌘F 直接展開)。內文宋體 16、行距 1.7,閱讀欄最寬 680。下方左邊「版本紀錄」(看舊版時有「回到最新版」)和「刪除」(按兩次),右邊「複製」(Markdown)、「存成檔案」(存成 .md 到「下載」)、「完成」。
- 打開的頁面像一份文件(和手機同一套):標題宋體粗體 28,下面一行小字作者、「更新於」、第幾版和「這一版更新了:…」;一行現況(summary)是開頭段落、不加框;結論(verdict)是淡底的「結論」提示框;kpis 是只有細框的數字卡(每張三行疊著:標籤、數字、變化;四張並排每張太窄時一排兩張;字太長以 … 結尾,滑過看全文)。頁面視窗不會被內容撐寬:太寬的表格在閱讀欄裡左右捲動,其他太寬的東西在視窗邊緣切掉,標題列的 × 一直在右上角。有 3 個以上的標題時有一行「▸ 目錄 · N 節」,點開才是標題清單和小搜尋框(⌘F 直接展開)。內文宋體 16、行距 1.7,閱讀欄最寬 680。下方左邊「版本紀錄」(看舊版時有「回到最新版」)和「刪除」(按兩次),右邊「複製」(Markdown)、「存成檔案」(存成 .md 到「下載」)、「完成」。
- 手機:首頁上面一排的「頁面」列出所有頁面;聊天裡的頁面卡片;打開的頁面的「⋯」有「複製 Markdown」「其他版本」,一條細線下面才是「刪除頁面」。
- 手機打開的頁面像一份文件:標題宋體粗體大字,下面一行小字作者和「更新於」;一行現況(summary)直接當開頭段落、不加框;kpis 是幾張只有細框的數字卡;結論(verdict)是一塊淡底的「結論」提示框;有 3 個以上的標題時多一行「目錄 · N 節」,點開是標題清單,點一個捲到那裡(沒有搜尋框)。內文宋體 16px、行距寬;表格沒有直線和斑馬紋、數字欄靠右;提示框同一種淡底,只有圖示依種類上色。
## 怎麼操作
- Bot:使用者要你追蹤、整理、比較、研究一件之後還會回來看的事,用 `write_page`(title、content;summary 一行現況;kind;kpis、verdict 只放真的資料;更新時帶 id 和 note),回覆裡用 [標題](page:ID) 連過去。更新前先 `read_page`(id 或 title)看現在的內容。要查的事同事可能已經在追,先 `list_pages`、`read_page` 讀它的,不要重查一遍。要定期追蹤就配一條例行任務([routines](routines.md)):每次讀頁面、查新消息,有實質進展才更新,沒有就說「沒有新消息」。這三個工具屬於「頁面」能力。
- 驗證:請 Bot「幫我追蹤某件事,整理成一頁」,回覆下面要出現頁面卡片,右側面板 資料庫 › 頁面 要列出它;再請它更新,卡片寫「已更新」,打開頁面的「版本紀錄」有上一版;同一個回覆裡就算寫了好幾次(被退回再存),下面也只有一張卡。請另一個 Bot 改這一頁,要被擋下並說是誰的頁面。頁裡的 ```chart:長條要按大小排序(月份圖不排)、單系列數字在條上;手機同頁看同一張圖要是同一套樣式——字跟內文差不多大、折線有 y 軸數字、圖下有數據表(24 筆的折線收成「▸ 數據 · 24 筆」)、一條在 1,700 上下的折線看得出起伏(y 軸不從 0 開始)、深色模式下打開頁面視窗不會超出畫面、只寫 `pie` 當第一行也畫得出來、只有一項的圓餅是整圓。手機打開有 3 個以上標題的頁面,標題下面要有收起來的「目錄 · N 節」一行,點開點一個標題會捲過去;內文是宋體、表格沒有直線。自動測試:`cargo test pages::`、`cargo test appctl::`。
- 驗證:請 Bot「幫我追蹤某件事,整理成一頁」,回覆下面要出現頁面卡片,右側面板 資料庫 › 頁面 要列出它;data 頁有四張數字卡和十欄的寬表格時,打開頁面的 × 要在右上角、數字卡是兩排各兩張;再請它更新,卡片寫「已更新」,打開頁面的「版本紀錄」有上一版;同一個回覆裡就算寫了好幾次(被退回再存),下面也只有一張卡。請另一個 Bot 改這一頁,要被擋下並說是誰的頁面。頁裡的 ```chart:長條要按大小排序(月份圖不排)、單系列數字在條上;手機同頁看同一張圖要是同一套樣式——字跟內文差不多大、折線有 y 軸數字、圖下有數據表(24 筆的折線收成「▸ 數據 · 24 筆」)、一條在 1,700 上下的折線看得出起伏(y 軸不從 0 開始)、深色模式下打開頁面視窗不會超出畫面、只寫 `pie` 當第一行也畫得出來、只有一項的圓餅是整圓。手機打開有 3 個以上標題的頁面,標題下面要有收起來的「目錄 · N 節」一行,點開點一個標題會捲過去;內文是宋體、表格沒有直線。自動測試:`cargo test pages::`、`cargo test appctl::`。
## 陷阱

View File

@ -803,12 +803,18 @@ impl App {
m.tool_calls.push(crate::model::ToolCall { id: "pg1".into(), name: "write_page".into(), args: serde_json::json!({"id": id, "title": "台灣 Tesla FSD 追蹤"}).to_string(), status: crate::model::ToolStatus::Done });
b.messages.push(m);
}
// ANYBOT_SHOT_PAGE_BODY=<file>: the page's Markdown from that file instead.
// ANYBOT_SHOT_PAGE_BODY=<file>: the page's Markdown from that file instead;
// ANYBOT_SHOT_PAGE_JSON=<file>: a whole page (title, kpis, verdict…).
if let Some(body) = std::env::var("ANYBOT_SHOT_PAGE_BODY").ok().and_then(|f| std::fs::read_to_string(f).ok()) {
if let Some(pg) = app.state.pages.iter_mut().find(|x| x.id == id) {
pg.body = body;
}
}
if let Some(page) = std::env::var("ANYBOT_SHOT_PAGE_JSON").ok().and_then(|f| std::fs::read_to_string(f).ok()).and_then(|s| serde_json::from_str::<crate::pages::Page>(&s).ok()) {
if let Some(pg) = app.state.pages.iter_mut().find(|x| x.id == id) {
*pg = crate::pages::Page { id, bot: pg.bot, ..page };
}
}
if v == "page" {
app.page_view = Some((id, None));
}
@ -7130,6 +7136,23 @@ thread_local! {
static WIDER_DIALOGS: std::cell::RefCell<Vec<(String, f32)>> = const { std::cell::RefCell::new(Vec::new()) };
}
thread_local! {
/// Strips drawn this frame whose content scrolls sideways (a wide table): the layout check
/// doesn't count a word cut at their edge.
static SIDEWAYS: std::cell::RefCell<Vec<egui::Rect>> = const { std::cell::RefCell::new(Vec::new()) };
}
/// A strip whose content is wider than it and scrolls sideways (for the layout check).
fn scrolls_sideways(r: egui::Rect) {
SIDEWAYS.with(|v| v.borrow_mut().push(r));
}
/// The strips that scroll sideways since the last call (see SIDEWAYS).
#[cfg(test)]
fn take_sideways() -> Vec<egui::Rect> {
SIDEWAYS.with(|v| std::mem::take(&mut *v.borrow_mut()))
}
/// The dialogs drawn wider than set since the last call (see WIDER_DIALOGS).
#[cfg(test)]
fn take_wider_dialogs() -> Vec<(String, f32)> {
@ -7148,6 +7171,7 @@ fn dialog_body<R>(ui: &mut egui::Ui, id: impl std::hash::Hash + std::fmt::Debug,
// infinite width, so rows that size themselves from `available_width` (settings rows,
// cards) grew past the window and every line they wrapped spilled off-screen.)
let viewport_width = ui.available_width().min(ui.ctx().content_rect().width());
let name = format!("{id:?}");
let mut area = egui::ScrollArea::vertical();
if let Some(y) = forced_dialog_scroll() {
area = area.vertical_scroll_offset(y);
@ -7157,9 +7181,23 @@ fn dialog_body<R>(ui: &mut egui::Ui, id: impl std::hash::Hash + std::fmt::Debug,
.auto_shrink([false, true])
.show(ui, |ui| {
Frame::new().inner_margin(Margin { left: 20, right: 20, top: 16, bottom: 16 }).show(ui, |ui| {
ui.set_width((viewport_width - 40.0).max(200.0));
let w = (viewport_width - 40.0).max(200.0);
ui.set_width(w);
ui.spacing_mut().item_spacing.y = 6.0;
body(ui)
// Content too wide for the dialog is cut off at its edge; it never pushes the
// window wider than its own title bar (a page's number tiles did, and the × then
// sat in the middle). The layout check still hears of it.
let at = ui.cursor().min;
let edge = egui::Rect::from_min_max(egui::pos2(at.x, f32::NEG_INFINITY), egui::pos2(at.x + w, f32::INFINITY));
let mut inner = ui.new_child(egui::UiBuilder::new().max_rect(egui::Rect::from_min_size(at, vec2(w, f32::INFINITY))).layout(*ui.layout()));
inner.set_clip_rect(inner.clip_rect().intersect(edge));
let r = body(&mut inner);
let used = inner.min_rect();
if used.width() > w + 1.0 && !ui.is_sizing_pass() {
WIDER_DIALOGS.with(|v| v.borrow_mut().push((name.clone(), used.width() - w)));
}
ui.advance_cursor_after_rect(egui::Rect::from_min_size(at, vec2(w, used.height())));
r
})
.inner
})

View File

@ -42,15 +42,18 @@ fn words(shapes: &[ClippedShape]) -> Vec<Word> {
/// What is wrong with the text in one drawn frame, in words a person can find on screen.
/// `long_fields`: long words typed into a one-line field scroll inside it (that is how a field
/// works), so they are not counted then.
pub fn problems(shapes: &[ClippedShape], long_fields: bool) -> Vec<String> {
/// works), so they are not counted then. `sideways`: strips whose content scrolls sideways (a
/// wide table) — a word cut at their edge is scrolled out of view, not cut by mistake.
pub fn problems(shapes: &[ClippedShape], long_fields: bool, sideways: &[egui::Rect]) -> Vec<String> {
// (Clipped by the strip across — its clip's sides are the strip's — and inside it down.)
let scrolled = |w: &Word| sideways.iter().any(|r| w.clip.min.x >= r.min.x - 1.0 && w.clip.max.x <= r.max.x + 1.0 && r.y_range().expand(1.0).contains(w.rect.center().y));
let ws: Vec<Word> = words(shapes).into_iter().filter(|w| w.clip.intersects(w.rect) && w.clip.width() > 4.0).collect();
let short = |s: &str| s.chars().take(40).collect::<String>().replace('\n', " ");
let mut out = vec![];
for w in &ws {
let over = (w.rect.max.x - w.clip.max.x).max(w.clip.min.x - w.rect.min.x);
let in_field = w.clip.height() < 40.0 && w.rect.min.x >= w.clip.min.x - 1.0;
if over > 1.5 && !(long_fields && in_field) {
if over > 1.5 && !(long_fields && in_field) && !scrolled(w) {
out.push(format!("被切掉 {over:.0}px:「{}」", short(&w.text)));
}
}
@ -75,6 +78,8 @@ fn draw(app: &mut App, ctx: &egui::Context, size: egui::Vec2) -> Vec<ClippedShap
let mut frame = eframe::Frame::_new_kittest();
let mut shapes = vec![];
for _ in 0..4 {
// (Only the last frame's sideways strips are kept.)
super::take_sideways();
let input = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)), ..Default::default() };
let mut out = ctx.run_ui(input, |ui| app.ui(ui, &mut frame));
out.textures_delta.clear();
@ -217,6 +222,17 @@ fn scenes() -> Vec<(&'static str, Open)> {
a.state.pages = pages;
a.state.next_page_id = next;
if let Some(pg) = a.state.pages.iter_mut().find(|pg| pg.id == id) {
// 數字卡四張(長標籤、長備註)、結論、十欄的寬表格:一份機箱健康報告把頁面
// 視窗撐出自己的標題列(× 跑到中間)。
pg.kind = "data".into();
pg.verdict = "機箱本身健康(CMM Normal、BMC 可連)。問題在 A1 槽 25G 交換模組:近 30 天瞬斷 9 次,每次 1~2 秒自解。".into();
pg.kpis = vec![
crate::pages::Kpi { label: "Switch A1 瞬斷(近 30 天)".into(), value: "9 次".into(), delta: "每次 1~2 秒自解".into() },
crate::pages::Kpi { label: "未確認 Critical".into(), value: "8 筆".into(), delta: "累計 21 筆".into() },
crate::pages::Kpi { label: "槽位可見度".into(), value: "2 / 5".into(), delta: "A1、A7、A8 無健康資料".into() },
crate::pages::Kpi { label: "實際電源模組".into(), value: "6 顆".into(), delta: "B2、B3 槽為空板".into() },
];
pg.body.push_str("\n\n## 刀鋒\n| 槽位 | 序號 | 型號 | 健康 | CPU | 記憶體 | BMC | BIOS | IP | 電源 |\n|---|---|---|---|---|---|---|---|---|---|\n| A8-1 | FruPS202505211418 | SBI-612B-1C2N | **無資料** | Xeon 6737P | 128 GB | 1.5 | 01.11.05.00 | 10.184.17.71 | 關 |\n");
pg.body.push_str("\n\n## 圖表\n```chart\nbar 各季下載量(個)\n北部 | 940\n中部 | 620\n南部 | 780\n東部 | 90\n```\n\n```chart\nline 月度下載(個)\n| 1月 | 2月 | 3月 | 4月\n去年 | 120 | 180 | 150 | 210\n今年 | 200 | 260 | 320 | 390\n```\n\n```chart\npie 裝置\n手機 | 550\n桌面 | 300\n平板 | 150\n```\n\n```stats\n本季下載 | 2,430 | ↑ 18% 較上季\n上季 | 2,060\n```\n");
}
a.state.selected = 1;
@ -282,7 +298,7 @@ fn audit_one(font: &str, worst: bool) -> Vec<String> {
let texts: Vec<String> = words(&shapes).into_iter().filter(|x| x.clip.intersects(x.rect)).map(|x| x.text).collect();
let fresh = texts.iter().filter(|t| !seen.contains(*t)).count();
seen.extend(texts);
for p in problems(&shapes, worst) {
for p in problems(&shapes, worst, &super::take_sideways()) {
report.push(format!("[{data} {font} {w:.0}] {name}: {p}"));
}
for (title, over) in super::take_wider_dialogs() {
@ -335,7 +351,7 @@ fn the_check_sees_cut_and_overlapping_text() {
out.textures_delta.clear();
shapes = out.shapes;
}
let found = problems(&shapes, false);
let found = problems(&shapes, false, &[]);
assert!(found.iter().any(|p| p.starts_with("疊在一起") && p.contains("停止")), "{found:?}");
assert!(found.iter().any(|p| p.starts_with("被切掉") && p.contains("03:00")), "{found:?}");
}

View File

@ -1250,6 +1250,12 @@ impl App {
.response
.rect
});
// A table wider than the column scrolls sideways: a cell cut at its edge is how that
// looks, not text cut by mistake (the layout check is told which strip scrolls).
if grid.content_size.x > grid.inner_rect.width() + 1.0 {
// (Its viewport across, the table down: the scroll area's own rect has no height.)
super::scrolls_sideways(egui::Rect::from_x_y_ranges(grid.inner_rect.x_range(), grid.inner.y_range()));
}
let x = grid.inner.x_range();
// Clipped only sideways, to what of a wide table is scrolled into view. (The scroll
// area's own inner rect is not the table's height: clipping to it hid every line but

View File

@ -22,6 +22,7 @@ const LOCAL_KEYS: &[&str] = &["remote", "theme", "accent", "sidebar_collapsed",
/// brain's, and a brain that doesn't know these (an older one) answered with 紙 and its clay every
/// time, so the 強調色 picked here was orange again. Still sent to the brain when changed here: the
/// phone wears the brain's.
#[cfg(test)]
const LOOK_KEYS: &[&str] = &["shell_tone", "shell_accent", "shell_contrast", "dense", "celebrate"];
/// This computer's own settings (LOCAL_KEYS but `selected`, which names a bot of one side, and

View File

@ -6,6 +6,8 @@
use super::*;
const CARD_W: f32 = 520.0;
/// The narrowest a number tile gets inside before the tiles go two to a row.
const KPI_TILE_MIN: f32 = 150.0;
impl App {
/// The card for page `id` under a reply.
@ -60,6 +62,56 @@ impl App {
}
/// The page, large: everything drawn like the chat, with the version picker and the footer.
/// The page's number tiles: each a stack — what (grey), the number (large), how it moved (green
/// or red) — all of a row the same width, in rows that fit the column: 4 side by side when
/// each gets KPI_TILE_MIN, else 2 a row (3 → 3, else 1). Words too long for a tile end in …
/// and say themselves on hover. (Inside the row's left-to-right layout the three lines sat side
/// by side, the tiles grew past the column and pushed the 頁面 window off its own title bar.)
fn page_kpis(&self, ui: &mut egui::Ui, kpis: &[crate::pages::Kpi]) {
use crate::theme::sp;
let p = self.pal;
let kpis = &kpis[..kpis.len().min(4)];
let gap = sp::S2;
// A tile's inner width when `per` share a row: less its padding (12 a side) and border.
let inner = |per: usize| (ui.available_width() - gap * (per as f32 - 1.0)) / per as f32 - 26.0;
let n = kpis.len();
let per = [n, n.div_ceil(2), 1].into_iter().find(|&k| inner(k) >= KPI_TILE_MIN).unwrap_or(1);
let kw = inner(per).max(40.0);
for (i, row) in kpis.chunks(per).enumerate() {
if i > 0 {
ui.add_space(gap);
}
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = gap;
for k in row {
Frame::new().stroke(Stroke::new(1.0, p.border)).corner_radius(R_M).inner_margin(Margin::symmetric(12, 10)).show(ui, |ui| {
ui.set_width(kw);
ui.vertical(|ui| {
ui.set_max_width(kw);
ui.spacing_mut().item_spacing.y = 2.0;
let line = |ui: &mut egui::Ui, text: RichText, full: &str| {
let r = ui.add(egui::Label::new(text).truncate());
if r.intrinsic_size().is_some_and(|s| s.x > kw + 0.5) {
r.on_hover_text(full);
}
};
line(ui, RichText::new(&k.label).size(FONT_XS).color(p.text3), &k.label);
line(ui, RichText::new(&k.value).size(FONT_H2).strong().family(crate::bold()).color(p.text), &k.value);
if !k.delta.is_empty() {
let c = match crate::pages::stat_trend(&k.delta) {
Some(true) => p.up,
Some(false) => p.danger,
None => p.text3,
};
line(ui, RichText::new(&k.delta).size(FONT_XS).color(c), &k.delta);
}
});
});
}
});
}
}
pub(super) fn page_viewer(&mut self, ctx: &egui::Context) {
let Some((id, rev)) = self.page_view else { return };
let p = self.pal;
@ -132,31 +184,7 @@ impl App {
}
if !old && !shown.kpis.is_empty() {
ui.add_space(sp::S4);
let kpis = shown.kpis.clone();
let n = kpis.len().min(4) as f32;
let gap = sp::S2;
// Each tile's inner width: its share of the row, less its own
// padding (12 a side) and its 1 px border, so the row fits the column.
let kw = ((ui.available_width() - gap * (n - 1.0)) / n - 26.0).max(40.0);
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = gap;
for k in kpis.iter().take(4) {
Frame::new().stroke(Stroke::new(1.0, p.border)).corner_radius(R_M).inner_margin(Margin::symmetric(12, 10)).show(ui, |ui| {
ui.set_width(kw);
ui.spacing_mut().item_spacing.y = 2.0;
ui.add(egui::Label::new(RichText::new(&k.label).size(FONT_XS).color(p.text3)).truncate());
ui.add(egui::Label::new(RichText::new(&k.value).size(FONT_H2).strong().family(crate::bold()).color(p.text)).truncate());
if !k.delta.is_empty() {
let c = match crate::pages::stat_trend(&k.delta) {
Some(true) => p.up,
Some(false) => p.danger,
None => p.text3,
};
ui.label(RichText::new(&k.delta).size(FONT_XS).color(c));
}
});
}
});
self.page_kpis(ui, &shown.kpis);
}
// 目錄: a page with sections lists them on one quiet line — 「目錄 · N 節」 —
// that unfolds into the headings (click one to jump; the box narrows the