From 4a4ef03c4629a5becefeafe878c787b57e215e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Thu, 19 Nov 2026 15:38:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=8C=E9=9D=A2=E7=89=88=E9=9D=A2=EF=BC=9A?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E8=88=87=E5=8D=A1=E7=89=87=E7=9A=84=E5=91=BC?= =?UTF-8?q?=E5=90=B8=EF=BC=88=E5=A4=A9=E5=9C=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用離屏版面審計量出使用者說的「破版」實為節奏太擠:訊息堆則與則之間 只有 9px,卡片裡問題→選項、區塊→按鈕都挤在 6px。統一節奏—— - 訊息堆:則與則 14px(緊湊 11px),日期分隔上下 12px。 - 審批卡:程式碼框內 10px,按鈕前 10px,「之後都直接操作」前 8px。 - 問題卡:題目→選項 10px,選項間 6px,欄位→按鈕 12px。 - 計畫卡:卡前 8px,摘要→步驟 8px,確認/注意 8px。 - Header:右側按鈕貼頂 12px;Bot 名字文字與聊天內文左緣對齊(同格線)。 新增離屏診斷探针(report_breathing_room / report_design / report_who_*, #[ignore] 手動跑):量每屏文字到窗邊距離、左緣起點分布、<3px 擠對。 已驗證: cargo test 721 全綠(含 layout_audit::text_stays 全螢幕全寬度); report_design 重跑:聊天、審批卡、問題卡、計畫卡、Bot 設定、例行任務、 頁面「擠」全部歸零(剩餘為設定遮罩下聊天層的跨層相鄰,非破版)。 未驗證: 真機視窗外觀(使用者自觀)。 --- src/app.rs | 19 ++--- src/app/chat_ui.rs | 4 +- src/app/layout_audit.rs | 152 +++++++++++++++++++++++++++++++++++++++- src/app/plan_ui.rs | 10 +-- 4 files changed, 169 insertions(+), 16 deletions(-) diff --git a/src/app.rs b/src/app.rs index bff865f..7b17d91 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3910,6 +3910,9 @@ impl App { ui.add_space(pad); ui.vertical(|ui| { ui.set_width(col_w); + // 訊息堆的呼吸:一则和下一则之间留足空白(天眼下的节奏:块与块 + // 之间 14px,紧组内部才用 6~8)。 + ui.spacing_mut().item_spacing.y = if self.state.dense { 11.0 } else { 14.0 }; ui.add_space(18.0); if bot.messages.is_empty() { self.empty_state(ui, &bot); @@ -3975,7 +3978,7 @@ impl App { let color = self.bot_color(bot); let (bar, _) = ui.allocate_exact_size(vec2(ui.available_width(), 58.0), egui::Sense::hover()); // Right: request / working, 分享, ⋯ — laid out from the right edge. - let mut right = ui.new_child(egui::UiBuilder::new().max_rect(bar.shrink2(vec2(12.0, 10.0))).layout(Layout::right_to_left(Align::Center))); + let mut right = ui.new_child(egui::UiBuilder::new().max_rect(bar.shrink2(vec2(12.0, 12.0))).layout(Layout::right_to_left(Align::Center))); right.spacing_mut().item_spacing.x = 8.0; let more = pill_icon(&mut right, crate::icons::Icon::More, p).on_hover_text(t("更多")); egui::Popup::menu(&more).show(|ui| self.bot_menu_items(ui, bot.id)); @@ -4004,7 +4007,7 @@ impl App { let font = egui::FontId::new(FONT_H3, crate::bold()); let name = sidebar_ui::shorten_width(ui, &bot.name, (bar.width() - right_w - 48.0).max(60.0), FONT_H3); let galley = ui.painter().layout_no_wrap(name, font, p.text); - let rect = egui::Rect::from_min_size(egui::pos2(bar.left() + 14.0, bar.center().y - 18.0), vec2(galley.size().x + 20.0, 36.0)); + let rect = egui::Rect::from_min_size(egui::pos2(bar.left() + 20.0, bar.center().y - 18.0), vec2(galley.size().x + 20.0, 36.0)); let r = ui.interact(rect, egui::Id::unique(("name-pill", bot.id)), egui::Sense::click()); if r.hovered() { ui.painter().rect_filled(rect, R_M, p.hover); @@ -4103,7 +4106,7 @@ impl App { None if !head.is_empty() => ui.label(RichText::new(head).size(FONT_XS).color(p.text3)), None => ui.label(""), }; - Frame::new().fill(p.elevated).corner_radius(R_M).inner_margin(Margin::symmetric(12, 8)).show(ui, |ui| { + Frame::new().fill(p.elevated).corner_radius(R_M).inner_margin(Margin::symmetric(12, 10)).show(ui, |ui| { ui.set_width(ui.available_width()); ui.add(egui::Label::new(RichText::new(detail).monospace().size(FONT_SM).color(p.text)).wrap()); }); @@ -4111,7 +4114,7 @@ impl App { if !machine.is_empty() && !matches!(kind, ApprovalKind::Action | ApprovalKind::EnableThisComputer) { ui.label(RichText::new(format!("在:{machine}")).size(FONT_XS).color(p.text3)); } - ui.add_space(6.0); + ui.add_space(10.0); // (Wrapped: in a narrow window the long 「一律允許…」 goes to the next line instead of // running out of the card.) ui.horizontal_wrapped(|ui| { @@ -4150,7 +4153,7 @@ impl App { }); // One click to work like the reference assistant: allow this and stop asking from now on. if !self.direct_on() && self.managed.direct.allows() && self.managed.local.allows() { - ui.add_space(4.0); + ui.add_space(8.0); // (A way out of asking, offered quietly: grey, not a second call to action.) let b = crate::icons::label(ui, crate::icons::Icon::Zap, &t("之後都直接操作,不再一個個問"), FONT_SM, p.text2).interact(egui::Sense::click()).on_hover_cursor(egui::CursorIcon::PointingHand); if b.on_hover_text(t("打開「直接操作」:Bot 可以直接使用這台電腦和瀏覽器,不再一個個問你。危險指令、密碼檔和你的「一律詢問」規則仍會擋下來。可在設定 → 權限關掉。")).clicked() { @@ -4317,7 +4320,7 @@ impl App { if q.multiple { ui.label(RichText::new(t("可以選好幾個")).size(FONT_SM).color(p.text2)); } - ui.add_space(6.0); + ui.add_space(10.0); let typed_id = egui::Id::unique(("ask-typed", bot.id, &call_id, step)); let own = !form.typed[step].trim().is_empty(); for (i, o) in q.options.iter().enumerate() { @@ -4347,7 +4350,7 @@ impl App { act = Some(Act::Next); } } - ui.add_space(4.0); + ui.add_space(6.0); } // The field: the answer itself when there are no choices, 「自己回答」 beside them. let hint = if q.options.is_empty() { t("輸入回答") } else { t("自己回答") }; @@ -4370,7 +4373,7 @@ impl App { if field.lost_focus() && ready && ui.input(|i| i.key_pressed(Key::Enter)) { act = Some(Act::Next); } - ui.add_space(8.0); + ui.add_space(12.0); ui.horizontal(|ui| { ui.spacing_mut().button_padding = vec2(14.0, 7.0); let go = if last { t("送出") } else { t("下一題") }; diff --git a/src/app/chat_ui.rs b/src/app/chat_ui.rs index bf83ed9..c149549 100644 --- a/src/app/chat_ui.rs +++ b/src/app/chat_ui.rs @@ -492,9 +492,9 @@ impl App { d(a) != d(b) }; if prev.map(|pa| m.at - pa > 30 * 60_000 || new_day(pa, m.at)).unwrap_or(true) { - ui.add_space(10.0); + ui.add_space(12.0); ui.vertical_centered(|ui| ui.label(RichText::new(date_label(m.at)).size(FONT_XS).color(p.text3))); - ui.add_space(10.0); + ui.add_space(12.0); } } // New messages fade and rise in (240 ms). diff --git a/src/app/layout_audit.rs b/src/app/layout_audit.rs index 623c142..50baf25 100644 --- a/src/app/layout_audit.rs +++ b/src/app/layout_audit.rs @@ -18,6 +18,7 @@ struct Word { clip: egui::Rect, rect: egui::Rect, text: String, + size: f32, } fn words(shapes: &[ClippedShape]) -> Vec { @@ -26,7 +27,7 @@ fn words(shapes: &[ClippedShape]) -> Vec { Shape::Text(t) => { let text = t.galley.text().trim().to_string(); if !text.is_empty() { - out.push(Word { clip, rect: t.visual_bounding_rect(), text }); + out.push(Word { clip, rect: t.visual_bounding_rect(), text, size: t.galley.job.sections.first().map(|s| s.format.font_id.size).unwrap_or(13.0) }); } } Shape::Vec(v) => v.iter().for_each(|x| walk(clip, x, out)), @@ -536,3 +537,152 @@ fn esc_puts_a_connectors_name_back() { step(&mut app, &ctx, size, vec![]); assert_eq!(app.state.mcp_servers[0].name, "notion"); } + +/// 天地審計(手動跑:`cargo test layout_audit::report -- --ignored --nocapture`): +/// 每一屏在 1000×800 畫一次,量「看得見的最近內容」離窗邊多遠——頂、底、左、右。 +/// 頂/底 < 8px 或左右 < 6px 視為貼邊(破版候補:滾動列表頂部貼邊是常見原因)。 +#[test] +#[ignore] +fn report_breathing_room() { + let (w, h) = (1000.0f32, 800.0f32); + let mut lines = vec![]; + for (name, open) in scenes() { + let ctx = egui::Context::default(); + crate::load_fonts(&ctx); + let mut app = App::new(&ctx, Some(std::env::temp_dir().join("anybot-breathing.png"))); + app.popup_hidden.extend(app.state.bots.iter().map(|b| b.id)); + open(&mut app); + let shapes = draw(&mut app, &ctx, vec2(w, h)); + let ws = words(&shapes); + let ws: Vec<&Word> = ws.iter().filter(|x| x.clip.intersects(x.rect) && x.clip.width() > 4.0 && x.rect.min.y < h).collect(); + // 分欄量:側欄(左)、主欄(右);主欄再分上半(內容)與下半(輸入區 y > h-120)。 + for (zone, sel, x0, x1) in [ + ("側欄", 0..=2, 0.0f32, 400.0f32), + ("主欄上", 0..=2, 400.0f32, w), + ("輸入區", 0..=2, 400.0f32, w), + ] { + let top_lim = if zone == "輸入區" { h - 140.0 } else { 0.0 }; + let bot_lim = if zone == "輸入區" { h } else { h - 140.0 }; + let pick: Vec<&&Word> = ws.iter().filter(|x| x.rect.center().x >= x0 && x.rect.center().x < x1 && x.rect.center().y >= top_lim && x.rect.center().y < bot_lim).collect(); + if pick.is_empty() { + continue; + } + let top = pick.iter().map(|x| x.rect.min.y).fold(f32::MAX, f32::min); + let bottom = pick.iter().map(|x| x.rect.max.y).fold(f32::MIN, f32::max); + let left = pick.iter().map(|x| x.rect.min.x).fold(f32::MAX, f32::min); + let right = pick.iter().map(|x| x.rect.max.x).fold(f32::MIN, f32::max); + let flag = |v: f32, lim: f32| if v < lim { "⚠️" } else { " " }; + lines.push(format!( + "{}{}{}{} {name} [{zone}]:頂 {top:.0} 底 {:.0} 左 {left:.0} 右 {:.0}", + flag(top, 8.0), flag(h - bottom, 8.0), flag(left, 6.0), flag(w - right, 6.0), + h - bottom, w - right + )); + } + let _ = 0..2; + } + for l in &lines { + println!("{l}"); + } +} + +/// 設計審計(手動跑:`cargo test layout_audit::report_design -- --ignored --nocapture`): +/// 每一屏(1000×800)量四件事,都是肉眼會覺得「破版、擠、亂」的來源: +/// 1. 左緣起點:主欄文字從哪些 x 開始(2px 一桶)——起點越多種,版面越像随机。 +/// 2. 擠:主欄裡上下相鄰、x 重疊、垂直縫 <3px 的文字對(沒呼吸)。 +/// 3. 字級:用了幾種字級(含大小寫同字号不計)——层次該收斂。 +/// 4. 貼邊:小框(卡、按鈕)裡文字離框左緣 <2px 的。 +#[test] +#[ignore] +fn report_design() { + let (w, h) = (1000.0f32, 800.0f32); + for (name, open) in scenes() { + let ctx = egui::Context::default(); + crate::load_fonts(&ctx); + let mut app = App::new(&ctx, Some(std::env::temp_dir().join("anybot-design.png"))); + app.popup_hidden.extend(app.state.bots.iter().map(|b| b.id)); + open(&mut app); + let shapes = draw(&mut app, &ctx, vec2(w, h)); + let all = words(&shapes); + let ws: Vec<&Word> = all.iter().filter(|x| x.clip.intersects(x.rect) && x.clip.width() > 4.0 && x.rect.min.y < h && x.rect.max.y > 0.0).collect(); + // 1. 左緣起點(主欄)。 + let mut starts: std::collections::BTreeMap = Default::default(); + for x in &ws { + if x.rect.center().x >= 400.0 { + *starts.entry((x.rect.min.x / 2.0).round() as i32 * 2).or_default() += 1; + } + } + let mut starts: Vec<(i32, usize)> = starts.into_iter().collect(); + starts.sort_by_key(|(x, n)| (std::cmp::Reverse(*n), *x)); + // 2. 擠。 + let mut cramped = 0; + let mut samples = vec![]; + let main: Vec<&&Word> = ws.iter().filter(|x| x.rect.center().x >= 400.0).collect(); + for a in &main { + for b in &main { + if std::ptr::eq(*a, *b) { + continue; + } + let gap = b.rect.min.y - a.rect.max.y; + if (0.0..3.0).contains(&gap) + && a.rect.min.x < b.rect.max.x && b.rect.min.x < a.rect.max.x + && !samples.iter().any(|s: &(String, String)| s.0 == a.text) + { + cramped += 1; + if samples.len() < 3 { + samples.push((a.text.chars().take(14).collect(), b.text.chars().take(14).collect())); + } + } + } + } + // 3. 字級。 + let sizes: std::collections::BTreeSet = ws.iter().map(|x| (x.size * 2.0).round() as i32).collect(); + // 4. 貼邊(小框)。 + let edge: Vec = ws.iter().filter(|x| x.clip.width() < 940.0 && x.clip.width() > 40.0 && x.rect.min.x - x.clip.min.x < 2.0 && x.clip.min.x > 100.0).map(|x| x.text.chars().take(14).collect()).collect(); + println!("── {name}\n 左緣起點 {} 種:{:?}\n 擠:<3px 對 {cramped} {:?}", starts.len(), &starts[..starts.len().min(6)], samples); + println!(" 字級 {} 種:{:?} 貼邊小框文字 {}:{:?}", sizes.len(), sizes.iter().map(|s| *s as f32 / 2.0).collect::>(), edge.len(), &edge[..edge.len().min(3)]); + } +} + +/// 誰貼著窗底(手動):印出底部 12px 內、左半边的文字。 +#[test] +#[ignore] +fn report_who_touches_the_floor() { + let (w, h) = (1000.0f32, 800.0f32); + for (name, open) in scenes() { + let ctx = egui::Context::default(); + crate::load_fonts(&ctx); + let mut app = App::new(&ctx, Some(std::env::temp_dir().join("anybot-floor.png"))); + app.popup_hidden.extend(app.state.bots.iter().map(|b| b.id)); + open(&mut app); + let shapes = draw(&mut app, &ctx, vec2(w, h)); + let hits: Vec = words(&shapes).iter().filter(|x| x.clip.intersects(x.rect) && x.rect.max.y > h - 12.0 && x.rect.center().x < 500.0).map(|x| format!("「{}」y底 {:.0} x {:.0}", x.text.chars().take(18).collect::(), x.rect.max.y, x.rect.min.x)).collect(); + if !hits.is_empty() { + println!("{name}: {}", hits.join("、")); + } + } +} + +/// 左緣起點是谁(手動):主欄每個左緣 x(2px 桶)的前三個字。 +#[test] +#[ignore] +fn report_who_starts_where() { + let (w, h) = (1000.0f32, 800.0f32); + for (name, open) in scenes() { + let ctx = egui::Context::default(); + crate::load_fonts(&ctx); + let mut app = App::new(&ctx, Some(std::env::temp_dir().join("anybot-starts.png"))); + app.popup_hidden.extend(app.state.bots.iter().map(|b| b.id)); + open(&mut app); + let shapes = draw(&mut app, &ctx, vec2(w, h)); + let mut by: std::collections::BTreeMap> = Default::default(); + for x in words(&shapes).iter().filter(|x| x.clip.intersects(x.rect) && x.rect.center().x >= 400.0 && x.rect.min.y < h) { + by.entry((x.rect.min.x / 2.0).round() as i32 * 2).or_default().push(x.text.chars().take(10).collect()); + } + if by.len() > 5 { + println!("── {name}"); + for (x, t) in &by { + println!(" x={x}: {}", t[..t.len().min(3)].join("、")); + } + } + } +} diff --git a/src/app/plan_ui.rs b/src/app/plan_ui.rs index 0e066f5..4a89003 100644 --- a/src/app/plan_ui.rs +++ b/src/app/plan_ui.rs @@ -147,7 +147,7 @@ impl App { Outcome::NotNow | Outcome::Refused => t("沒有採用"), }; let whole = matches!(how, Outcome::Waiting | Outcome::Approved); - ui.add_space(6.0); + ui.add_space(8.0); Frame::new() .fill(p.elevated) .stroke(Stroke::new(1.0, if how == Outcome::Waiting { p.accent } else { p.border })) @@ -164,12 +164,12 @@ impl App { ui.label(RichText::new(label).size(FONT_XS).color(if how == Outcome::Waiting { p.accent } else { p.text3 })); }); }); - ui.add_space(4.0); + ui.add_space(6.0); ui.add(egui::Label::new(RichText::new(&draft.summary).size(FONT_SM).color(if whole { p.text } else { p.text2 })).wrap()); if !whole { return; } - ui.add_space(6.0); + ui.add_space(8.0); // The steps: as the bot keeps them while it follows the plan, else as handed in. let rows: Vec<(String, String, Option)> = match following { Some(pl) => pl.steps.iter().map(|s| (s.title.clone(), draft.steps.iter().find(|d| d.title == s.title).map(|d| d.detail.clone()).unwrap_or_default(), Some(s.status))).collect(), @@ -201,12 +201,12 @@ impl App { } for (head, body) in [("怎麼確認做對了:", &draft.check), ("注意:", &draft.notes)] { if !body.is_empty() { - ui.add_space(6.0); + ui.add_space(8.0); ui.add(egui::Label::new(RichText::new(format!("{}{body}", t(head))).size(FONT_XS).color(p.text2)).wrap()); } } if how == Outcome::Waiting { - ui.add_space(6.0); + ui.add_space(8.0); ui.label(RichText::new(t("在下面的卡片選「開始照計畫做」,或寫下要改哪裡")).size(FONT_XS).color(p.text3)); } });