Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Plane3D component ui when it's non-editable #8509

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading