From 7a19d102bfeb3b132432741b58f39c58b2ae65d1 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 17 Dec 2024 17:53:57 +0100 Subject: [PATCH] Fix Plane3D component ui when it's non-editable (#8509) * Fixes https://github.com/rerun-io/rerun/issues/8488 Shows normal always as a vec now ![image](https://github.com/user-attachments/assets/b23a1437-bc67-4054-abc3-04d3a7fa973f) Editable one is unchanged (we'd need more space for edit boxes, so we rely on multiline ui): ![image](https://github.com/user-attachments/assets/ebf0b8e6-c116-49f4-be99-10731e9c99b8) --- crates/viewer/re_component_ui/src/plane3d.rs | 62 +++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/crates/viewer/re_component_ui/src/plane3d.rs b/crates/viewer/re_component_ui/src/plane3d.rs index 2b3484f60e19..d0432dd7a4a2 100644 --- a/crates/viewer/re_component_ui/src/plane3d.rs +++ b/crates/viewer/re_component_ui/src/plane3d.rs @@ -83,37 +83,41 @@ pub fn edit_or_view_plane3d( let distance = value.distance(); ui.label("n"); - // Show simplified combobox if this is axis aligned. - let mut axis_dir = AxisDirection::from(glam::Vec3::from(value.normal())); - let normal_response = response_with_changes_of_inner( - egui::ComboBox::from_id_salt("plane_normal") - .selected_text(format!("{axis_dir}")) - .height(250.0) - .show_ui(ui, |ui| { - let mut variants = AxisDirection::VARIANTS.iter(); - #[allow(clippy::unwrap_used)] // We know there's more than zero variants. - let variant = variants.next().unwrap(); - - let mut response = - ui.selectable_value(&mut axis_dir, *variant, variant.to_string()); - for variant in variants { - response |= ui.selectable_value(&mut axis_dir, *variant, variant.to_string()); - } - - if let MaybeMutRef::MutRef(value) = value { + + let normal_response = if let Some(value_mut) = value.as_mut() { + // Show simplified combobox if this is axis aligned. + let mut axis_dir = AxisDirection::from(glam::Vec3::from(value_mut.normal())); + response_with_changes_of_inner( + egui::ComboBox::from_id_salt("plane_normal") + .selected_text(format!("{axis_dir}")) + .height(250.0) + .show_ui(ui, |ui| { + let mut variants = AxisDirection::VARIANTS.iter(); + #[allow(clippy::unwrap_used)] // We know there's more than zero variants. + let variant = variants.next().unwrap(); + + let mut response = + ui.selectable_value(&mut axis_dir, *variant, variant.to_string()); + for variant in variants { + response |= + ui.selectable_value(&mut axis_dir, *variant, variant.to_string()); + } if let Ok(new_dir) = glam::Vec3::try_from(axis_dir) { - **value = components::Plane3D::new(new_dir, distance); + *value_mut = components::Plane3D::new(new_dir, distance); } - } - response - }), - ) - .on_hover_text(format!( - "{} {} {}", - re_format::format_f32(value.normal().x()), - re_format::format_f32(value.normal().y()), - re_format::format_f32(value.normal().z()), - )); + response + }), + ) + .on_hover_text(format!( + "{} {} {}", + re_format::format_f32(value.normal().x()), + re_format::format_f32(value.normal().y()), + re_format::format_f32(value.normal().z()), + )) + } else { + let normal = value.normal(); + edit_or_view_vec3d_raw(ui, &mut MaybeMutRef::Ref(&normal)) + }; ui.label("d"); let mut maybe_mut_distance = match value {