From 320c97485cdce4d47421500ca8acd6e8c9361d5a Mon Sep 17 00:00:00 2001 From: H-Chris233 Date: Fri, 1 May 2026 22:58:23 +0800 Subject: [PATCH] Reuse capsule height for QA anchoring QA positioning had kept its own fixed capsule height constant after the capsule window was resized to match the visible pill. Reusing the shared capsule height source keeps the documented gap intact without widening the change surface. Constraint: Keep the change minimal and avoid a separate geometry model for QA. Rejected: Keep the old QA constant | would drift from the new capsule geometry again. Confidence: high Scope-risk: narrow Directive: If capsule geometry changes again, update QA anchoring from the shared capsule source instead of introducing another fixed constant. Tested: cargo test --manifest-path src-tauri/Cargo.toml --lib -- --nocapture Not-tested: Live QA window placement on each platform. --- openless-all/app/src-tauri/src/lib.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/openless-all/app/src-tauri/src/lib.rs b/openless-all/app/src-tauri/src/lib.rs index a20b1546..12056a11 100644 --- a/openless-all/app/src-tauri/src/lib.rs +++ b/openless-all/app/src-tauri/src/lib.rs @@ -436,8 +436,6 @@ const QA_WINDOW_WIDTH: f64 = 380.0; const QA_WINDOW_HEIGHT: f64 = 440.0; /// 胶囊与 QA 窗口的间距,与设计稿一致。 const QA_WINDOW_GAP_TO_CAPSULE: f64 = 8.0; -/// 胶囊高度(与 `position_capsule_bottom_center` 中一致)。 -const CAPSULE_HEIGHT_FOR_QA: f64 = 96.0; /// 给 macOS Dock 留的下边距(与 capsule 同源)。 const DOCK_BOTTOM_PADDING_FOR_QA: f64 = 80.0; @@ -452,10 +450,11 @@ fn position_qa_window(window: &tauri::WebviewWindow) -> ta let size = monitor.size(); let logical_w = size.width as f64 / scale; let logical_h = size.height as f64 / scale; + let capsule_height = capsule_window_size(false).1; let x = ((logical_w - QA_WINDOW_WIDTH) / 2.0).max(0.0); let y = (logical_h - DOCK_BOTTOM_PADDING_FOR_QA - - CAPSULE_HEIGHT_FOR_QA + - capsule_height - QA_WINDOW_GAP_TO_CAPSULE - QA_WINDOW_HEIGHT) .max(0.0); @@ -598,9 +597,13 @@ fn capsule_window_size(translation_active: bool) -> (f64, f64) { } } +fn capsule_height_for_qa() -> f64 { + capsule_window_size(false).1 +} + #[cfg(test)] mod tests { - use super::capsule_window_size; + use super::{capsule_height_for_qa, capsule_window_size}; #[test] fn capsule_window_size_matches_visible_pill_when_not_translating() { @@ -621,4 +624,13 @@ mod tests { #[cfg(not(target_os = "windows"))] assert_eq!((width, height), (176.0, 110.0)); } + + #[test] + fn qa_anchor_uses_normal_capsule_height_source() { + #[cfg(target_os = "windows")] + assert_eq!(capsule_height_for_qa(), 52.0); + + #[cfg(not(target_os = "windows"))] + assert_eq!(capsule_height_for_qa(), 42.0); + } }