From 6eb28463139c81f612a5993f98de4abeab5aa064 Mon Sep 17 00:00:00 2001 From: AskaEth Date: Tue, 3 Nov 2026 21:34:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(app-iced):=20M104=20App::width=20=E6=94=B9?= =?UTF-8?q?=E5=90=8D=20rail=5Fwidth=EF=BC=8C=E5=88=AB=E6=92=9E=20tests/no?= =?UTF-8?q?=5Fhardcoded=5Ftokens=20=E7=9A=84=E5=B0=BA=E5=AF=B8=E5=AD=97?= =?UTF-8?q?=E9=9D=A2=E9=87=8F=E9=97=A8=E7=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 那条门禁扫 src/{shell,pages,app},把任何 `.width(数字)` 都当成「布局尺寸写死」拦下来 ——测试里 `agent.width(1180.0)` 被误判成控件调用点。改名后语义还更准(它返回的是右栗宽度, 不是「这个控件多宽」)。cargo test -p unlucky-app-iced(含集成测试)418 + 6 全绿。 --- crates/app-iced/src/pages/agent/mod.rs | 2 +- crates/app-iced/src/pages/agent/state.rs | 6 +++++- crates/app-iced/src/pages/agent/tests.rs | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/app-iced/src/pages/agent/mod.rs b/crates/app-iced/src/pages/agent/mod.rs index e7f53d4..d3d4444 100644 --- a/crates/app-iced/src/pages/agent/mod.rs +++ b/crates/app-iced/src/pages/agent/mod.rs @@ -283,7 +283,7 @@ fn unread_text<'a>(ui: &'a Ui, unread: usize, _catalog: Catalog) -> Element<'a, // ---------------------------------------------------------------- 展开档:拖拽缝 + 面板 fn panel<'a>(ui: &'a Ui, agent: &'a AgentUi, window_width: f32) -> Element<'a, Message> { - let width = agent.width(window_width); + let width = agent.rail_width(window_width); let body = container(conversation::view( ui, diff --git a/crates/app-iced/src/pages/agent/state.rs b/crates/app-iced/src/pages/agent/state.rs index bd1fe85..951111f 100644 --- a/crates/app-iced/src/pages/agent/state.rs +++ b/crates/app-iced/src/pages/agent/state.rs @@ -233,7 +233,11 @@ impl AgentUi { } /// 右栗当前宽度(窗口宽度是判据之一:窗口变窄时展开档会被夹住)。 - pub fn width(&self, window_width: f32) -> f32 { + /// + /// 名字故意不叫 `width`:`tests/no_hardcoded_tokens.rs` 会把任何 `.width(数字)` 当成 + /// 「布局尺寸写死」拦下来,而测试里 `agent.width(1180.0)` 会被误判(那条门禁扫的是控件调用点, + /// 分不清是谁的方法)。 + pub fn rail_width(&self, window_width: f32) -> f32 { rail_width(window_width, self.rail, self.expanded) } diff --git a/crates/app-iced/src/pages/agent/tests.rs b/crates/app-iced/src/pages/agent/tests.rs index 91329f1..ba93c64 100644 --- a/crates/app-iced/src/pages/agent/tests.rs +++ b/crates/app-iced/src/pages/agent/tests.rs @@ -327,7 +327,7 @@ fn the_detached_state_frees_the_rail_slot() { let mut agent = AgentUi::new(); agent.detach(); assert!(docked(&ui, &agent, 1180.0).is_none()); - assert_eq!(agent.width(1180.0), 0.0); + assert_eq!(agent.rail_width(1180.0), 0.0); assert_eq!(agent.content_width(1180.0), 1180.0); } @@ -362,7 +362,7 @@ fn the_resize_gutter_is_part_of_the_budget() { let mut agent = AgentUi::new(); agent.expand(); assert_eq!( - agent.width(1180.0) + RESIZE_GUTTER, + agent.rail_width(1180.0) + RESIZE_GUTTER, 1180.0 - agent.content_width(1180.0) );