SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Section details card: every row shows, and the numbers read like the pill (#10708) (#10799)
semmelrinded90707843484
diff --git a/crates/ui-egui/src/ui_kit/details.rs b/crates/ui-egui/src/ui_kit/details.rsindex 250a0c182e..99dab28cf7 100644--- a/crates/ui-egui/src/ui_kit/details.rs+++ b/crates/ui-egui/src/ui_kit/details.rs@@ -45,13 +45,33 @@ pub(crate) fn details_field_owned_escape(ctx: &egui::Context) -> bool {#[derive(Clone, Debug, PartialEq)]pub(crate) enum DetailValue {- Number { value: f64, min: f64, max: f64, suffix: String },- Length { value: f64, units: String },+ Number {+ value: f64,+ min: f64,+ max: f64,+ suffix: String,+ },+ /// Shown to `decimals` places, as the design shows lengths.+ Length {+ value: f64,+ units: String,+ decimals: u8,+ },Angle(f64),- Slider { value: f64, min: f64, max: f64 },- Axis { value: [f64; 3], current: String },+ Slider {+ value: f64,+ min: f64,+ max: f64,+ },+ Axis {+ value: [f64; 3],+ current: String,+ },Check(bool),- Choice { selected: usize, options: Vec<String> },+ Choice {+ selected: usize,+ options: Vec<String>,+ },}pub(crate) struct DetailSetting {@@ -136,7 +156,7 @@ fn setting(ui: &mut Ui, field: &DetailSetting, focus: bool) -> Option<DetailEvenui.style_mut().drag_value_text_style = egui::TextStyle::Monospace;let response = match &mut value {DetailValue::Number { value, min, max, suffix } => Some(super::number_field(ui, value, *min..=*max, 0.01, suffix)),- DetailValue::Length { value, units } => Some(super::length_field(ui, value, units, 6)),+ DetailValue::Length { value, units, decimals } => Some(super::length_field(ui, value, units, *decimals)),DetailValue::Angle(value) => Some(super::angle_field(ui, value)),DetailValue::Slider { value, min, max } => Some(super::slider(ui, value, *min..=*max, Default::default())),DetailValue::Check(value) => Some(super::checkbox(ui, "", value)),@@ -228,6 +248,9 @@ pub(crate) fn details(ui: &mut Ui, id: &str, description: &Details, max_height:ui.ctx().data_mut(|data| data.insert_temp(egui::Id::new(CONTROL_FOCUS), Vec::<egui::Id>::new()));ui.ctx().data_mut(|data| data.insert_temp(egui::Id::new(OWNED_POPUPS), Vec::<egui::Id>::new()));ui.set_width((t.form_card_width + if description.findings.is_empty() { 0.0 } else { t.space_24 * 2.0 }).min(ui.available_width()));+ // A card's area is as tall as it was last frame: allowed `max_height`, a body that grew+ // after the first frame scrolls instead, and its last row was cut off (#10708).+ ui.set_max_height(max_height);super::scope(ui, |ui| {let mut caption_height = 0.0;if let Some(caption) = &description.caption {diff --git a/crates/ui-egui/src/viewport_details.rs b/crates/ui-egui/src/viewport_details.rsindex e37c508f65..748a49eab0 100644--- a/crates/ui-egui/src/viewport_details.rs+++ b/crates/ui-egui/src/viewport_details.rs@@ -16,7 +16,7 @@ fn field(id: &str, label: &str, value: DetailValue) -> DetailSetting {DetailSetting { id: id.into(), label: tr(label), value, enabled: true }}fn length(app: &SolveApp, value: f64) -> DetailValue {- DetailValue::Length { value, units: app.session.doc.units.clone() }+ DetailValue::Length { value, units: app.session.doc.units.clone(), decimals: app.preferences.length_decimals }}fn number(value: f64, min: f64, max: f64, suffix: &str) -> DetailValue {DetailValue::Number { value, min, max, suffix: suffix.into() }@@ -26,7 +26,13 @@ fn axis(value: [f64; 3]) -> DetailValue {let current = if axes.iter().any(|axis| *axis == value || axis.map(|v| -v) == value) {crate::viewport_status::direction(value)} else {- let [x, y, z] = value;+ // Rounded as the card's other numbers are: a tilted normal reads (0.707, 0.707, 0).+ let short = |v: f64| {+ let s = format!("{v:.3}");+ let s = s.trim_end_matches('0').trim_end_matches('.');+ if s == "-0" { "0".to_string() } else { s.to_string() }+ };+ let [x, y, z] = value.map(short);format!("({x}, {y}, {z})")};DetailValue::Axis { value, current }diff --git a/crates/ui-egui/src/viewport_overlays_tests.rs b/crates/ui-egui/src/viewport_overlays_tests.rsindex 7f9583dff4..2d66513e27 100644--- a/crates/ui-egui/src/viewport_overlays_tests.rs+++ b/crates/ui-egui/src/viewport_overlays_tests.rs@@ -67,7 +67,8 @@ fn section_details_live_fields_reconstruct_arbitrary_plane_without_losing_companassert!((original.1 + flipped.1).len() < 1e-9);h.app.session.doc_mut().units = "in".into();let effect = h.app.session.status_items().remove(0);- let params = crate::viewport_details::edit_params(&h.app, &effect, "offset", &V::Length { value: -25.4, units: "in".into() }).unwrap();+ let params =+ crate::viewport_details::edit_params(&h.app, &effect, "offset", &V::Length { value: -25.4, units: "in".into(), decimals: 2 }).unwrap();assert_eq!(params["offset"], "-25.4 mm");assert_eq!(params["hatch"], true);assert_eq!(params["flip"], !current_flip);@@ -121,7 +122,7 @@ fn details_record_scope_preserves_mixed_limits_and_stale_targets_never_move_camecrate::viewport_details::dispatch(&mut h.app, &h.ctx, &owner, DetailEvent::Target(target));assert_eq!(h.app.session.camera, before);let effect = h.app.session.status_items().remove(0);- assert!(crate::viewport_details::edit_params(&h.app, &effect, "gap", &V::Length { value: 1.0, units: "in".into() }).is_none());+ assert!(crate::viewport_details::edit_params(&h.app, &effect, "gap", &V::Length { value: 1.0, units: "in".into(), decimals: 2 }).is_none());assert!(crate::viewport_details::description(&h.app, &effect).findings.iter().all(|row| !row.target));}@@ -2670,3 +2671,29 @@ fn summary_preferences_cancel_restores_layout_independently_of_all_effect_policiassert_eq!(crate::scenario::rect_of("viewport_status:summary").is_some(), saved);}}++#[test]+fn a_section_card_shows_every_row_and_reads_like_its_pill() {+ // #10708: the card was cut off below Hatch (and Flip for a tilted plane), and showed+ // "15.000000 mm" and a normal with 16 digits.+ use crate::ui_kit::DetailValue as V;+ for (plane, rows, normal) in [(json!("XZ"), 3, None), (json!({"origin":[20,15,10],"normal":[1,1,0]}), 3, Some("(0.707, 0.707, 0)"))] {+ let mut h = Harness::new();+ h.app.run("solid.box", json!({"length":40,"width":30,"height":20})).unwrap();+ h.app.run("inspect.section", json!({"plane":plane,"offset":15})).unwrap();+ h.frames(3);+ let effect = h.app.session.status_items().remove(0);+ let owner = crate::viewport_status::identity(&effect);+ h.step(&json!({"click":{"handle":format!("viewport_status:{owner}:setting")}})).unwrap();+ h.frames(4);+ let card = crate::scenario::rect_of("viewport_status:card").expect("the card");+ let fields: Vec<_> = ["offset", "flip", "hatch"].iter().filter_map(|f| crate::scenario::rect_of(&format!("details:field:{f}"))).collect();+ assert_eq!(fields.len(), rows);+ assert!(fields.iter().all(|f| card.contains_rect(*f)), "{plane}: card {card:?}, rows {fields:?}");+ let description = crate::viewport_details::description(&h.app, &effect);+ assert!(description.settings.iter().any(|s| matches!(&s.value, V::Length { decimals: 2, .. })));+ if let Some(normal) = normal {+ assert!(description.settings.iter().any(|s| matches!(&s.value, V::Axis { current, .. } if current == normal)), "{plane}");+ }+ }+}