From d1fef57bf4e792fcbca0a24b432738a4f9e33ba1 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Thu, 30 Jul 2026 11:02:53 +0300 Subject: [PATCH] fix(ui): preserve active scale label Closes #578 --- src/ui/statusbar/mod.rs | 44 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/ui/statusbar/mod.rs b/src/ui/statusbar/mod.rs index a7be7daa8..1074800de 100644 --- a/src/ui/statusbar/mod.rs +++ b/src/ui/statusbar/mod.rs @@ -172,11 +172,22 @@ impl StatusBar { // Scale pill: opens the scale picker popup. // Model space: always interactive, shows annotation scale. // Paper space: interactive only when a viewport is active/selected. - let scale_label = if current_layout == "Model" { - format_scale(Some(1.0 / annotation_scale as f64)) - } else { - format_scale(viewport_scale) - }; + // Keep its text identical to the active drawing-defined scale. Rebuilding + // the label from the numeric factor turns an architectural + // `1/2" = 1'-0"` scale into `1:24`, mixing formats in the same control. + let scale_label = active_scale_label( + scale_is_model, + annotation_scale, + viewport_scale, + &scale_list, + ) + .unwrap_or_else(|| { + if scale_is_model { + format_scale(Some(1.0 / annotation_scale as f64)) + } else { + format_scale(viewport_scale) + } + }); let scale_element: Element<'_, Message> = if scale_pill_enabled { status_menu::menu_bar( menu_tip( @@ -982,3 +993,26 @@ fn format_scale(scale: Option) -> String { .trim_end_matches('.') .to_string() } + +fn active_scale_label( + is_model: bool, + annotation_scale: f32, + viewport_scale: Option, + scales: &[(String, f32, f64)], +) -> Option { + scales + .iter() + .find(|(_, anno_scale, vp_scale)| { + if is_model { + (annotation_scale - *anno_scale).abs() + < 0.001 * annotation_scale.max(0.001) + } else { + viewport_scale + .map(|current| { + (current - *vp_scale).abs() < 0.001 * vp_scale.max(0.001) + }) + .unwrap_or(false) + } + }) + .map(|(label, _, _)| label.clone()) +}