Use shared unit formatters across property and dynamic views

This commit is contained in:
Marcel committed 2026-09-17 08:30:20 +02:00
1 parent ca0ee37d26
commit fca96b57de
10 files changed
+78 -65

No files matched your search

+10 -12
View File
@@ -346,26 +346,24 @@ pub(super) fn dyn_component_value(
) && relative
&& !comma_cartesian;
match f.component {
DynComponent::X if relative => format!("{:.4}", if wh { dx.abs() } else { dx }),
DynComponent::Y if relative => format!("{:.4}", if wh { dy.abs() } else { dy }),
DynComponent::Z if relative => "0.0000".to_string(),
DynComponent::X => format!("{:.4}", p.x),
DynComponent::Y => format!("{:.4}", p.y),
DynComponent::Z => format!("{:.4}", p.z),
DynComponent::X if relative => crate::entities::common::format_length(if wh { dx.abs() } else { dx }),
DynComponent::Y if relative => crate::entities::common::format_length(if wh { dy.abs() } else { dy }),
DynComponent::Z if relative => crate::entities::common::format_length(0.0),
DynComponent::X => crate::entities::common::format_length(p.x),
DynComponent::Y => crate::entities::common::format_length(p.y),
DynComponent::Z => crate::entities::common::format_length(p.z),
// Scaled by the role so a diameter box reads twice the radius.
DynComponent::Distance => {
format!(
"{:.4}",
(dx * dx + dy * dy).sqrt() * f.role.value_scale() as f64
crate::entities::common::format_length(
(dx * dx + dy * dy).sqrt() * f.role.value_scale() as f64,
)
}
// Shared rule: unsigned magnitude of the short angle, so CW (below the
// reference axis) reads positive (e.g. 30°, not -30°/330°). The
// committed value stays signed (see dyn_resolve_point).
DynComponent::Angle => {
format!(
"{:.1}",
crate::command::dyn_display_angle_deg(dy.atan2(dx) as f32)
crate::entities::common::format_angle(
(crate::command::dyn_display_angle_deg(dy.atan2(dx) as f32) as f64).to_radians(),
)
}
// Typed-only scalar — no geometric value to track when empty.
+14 -4
View File
@@ -213,6 +213,12 @@ impl OpenCADStudio {
let i = self.active_tab;
let tab = &self.tabs[i];
// Dynamic input is built before the status bar and properties panel,
// so seed its shared formatter here rather than relying on either of
// those later views to have done it for this drawing/thread.
crate::entities::common::set_unit_context(
crate::entities::common::UnitContext::from_header(&tab.scene.document.header),
);
let thumbnail_capture_clean = self.thumbnail_capture_clean;
let theme_text = self.active_theme.palette().background.base.text;
let viewcube_text_color = [theme_text.r, theme_text.g, theme_text.b, theme_text.a];
@@ -1068,15 +1074,15 @@ bg={bg_ms:.1}ms n={view_count}"
(None, _) if rectangle_values.is_some() => {
let (width, height) = rectangle_values.unwrap();
match f.role {
crate::command::DynRole::Width => format!("{width:.4}"),
crate::command::DynRole::Height => format!("{height:.4}"),
crate::command::DynRole::Width => crate::entities::common::format_length(width),
crate::command::DynRole::Height => crate::entities::common::format_length(height),
_ => String::new(),
}
}
// An angle step with a command-supplied live value
// (ARC span / direction) shows it in degrees.
(None, Some(lv)) if f.component == DynComponent::Angle => {
format!("{lv:.1}")
crate::entities::common::format_angle(lv.to_radians())
}
(None, Some(lv))
if matches!(
@@ -1084,7 +1090,11 @@ bg={bg_ms:.1}ms n={view_count}"
DynComponent::Scalar | DynComponent::Distance
) =>
{
format!("{lv:.4}")
if f.component == DynComponent::Distance {
crate::entities::common::format_length(lv)
} else {
lv.to_string()
}
}
_ => dyn_component_value(
f,