Skip to content

Commit

Permalink
Fix Plane3D component ui when it's non-editable (#8509)
Browse files Browse the repository at this point in the history
* Fixes #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)
  • Loading branch information
Wumpf authored Dec 17, 2024
1 parent 75c6f14 commit 7a19d10
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions crates/viewer/re_component_ui/src/plane3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7a19d10

Please sign in to comment.