diff --git a/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs b/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs index 12237408907a3..24c16dabb72e0 100644 --- a/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs +++ b/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs @@ -1,22 +1,18 @@ -use std::ops::DerefMut; - -use egui::NumExt as _; - -/// Generic editor for a f32 value from zero to infinity. -pub fn edit_f32_zero_to_inf( +/// Generic editor for a boolean value. +pub fn edit_bool( _ctx: &re_viewer_context::ViewerContext<'_>, ui: &mut egui::Ui, - value: &mut impl DerefMut, + value: &mut impl std::ops::DerefMut, ) -> egui::Response { - edit_f32_zero_to_inf_impl(ui, value) + edit_bool_impl(ui, value) } -/// Non monomorphized implementation of [`edit_f32_zero_to_inf`]. -fn edit_f32_zero_to_inf_impl(ui: &mut egui::Ui, value: &mut f32) -> egui::Response { - let speed = (*value * 0.01).at_least(0.001); - ui.add( - egui::DragValue::new(value) - .clamp_range(0.0..=f32::INFINITY) - .speed(speed), - ) +/// Non monomorphized implementation of [`edit_bool`]. +fn edit_bool_impl(ui: &mut egui::Ui, value: &mut bool) -> egui::Response { + ui.scope(move |ui| { + ui.visuals_mut().widgets.hovered.expansion = 0.0; + ui.visuals_mut().widgets.active.expansion = 0.0; + ui.add(re_ui::toggle_switch(15.0, value)) + }) + .inner } diff --git a/crates/re_edit_ui/src/datatype_editors/float_drag.rs b/crates/re_edit_ui/src/datatype_editors/float_drag.rs index 12237408907a3..a0712b8d4dc24 100644 --- a/crates/re_edit_ui/src/datatype_editors/float_drag.rs +++ b/crates/re_edit_ui/src/datatype_editors/float_drag.rs @@ -1,12 +1,10 @@ -use std::ops::DerefMut; - use egui::NumExt as _; /// Generic editor for a f32 value from zero to infinity. pub fn edit_f32_zero_to_inf( _ctx: &re_viewer_context::ViewerContext<'_>, ui: &mut egui::Ui, - value: &mut impl DerefMut, + value: &mut impl std::ops::DerefMut, ) -> egui::Response { edit_f32_zero_to_inf_impl(ui, value) } diff --git a/crates/re_edit_ui/src/datatype_editors/mod.rs b/crates/re_edit_ui/src/datatype_editors/mod.rs index d6d74d925e7be..2621c61e6fb0c 100644 --- a/crates/re_edit_ui/src/datatype_editors/mod.rs +++ b/crates/re_edit_ui/src/datatype_editors/mod.rs @@ -1,5 +1,7 @@ +mod bool_toggle; mod float_drag; mod singleline_string; +pub use bool_toggle::edit_bool; pub use float_drag::edit_f32_zero_to_inf; pub use singleline_string::edit_singleline_string; diff --git a/crates/re_edit_ui/src/lib.rs b/crates/re_edit_ui/src/lib.rs index 8866660e3e6dc..a21f8732dd16a 100644 --- a/crates/re_edit_ui/src/lib.rs +++ b/crates/re_edit_ui/src/lib.rs @@ -7,9 +7,11 @@ mod corner2d; mod datatype_editors; mod marker_shape; mod response_utils; -mod visible; -use re_types::components::{Color, MarkerSize, Name, Radius, ScalarScattering, StrokeWidth, Text}; +use re_types::{ + blueprint::components::Visible, + components::{Color, MarkerSize, Name, Radius, ScalarScattering, StrokeWidth, Text}, +}; use re_viewer_context::ViewerContext; // ---- @@ -55,7 +57,8 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) { registry.add_editor(corner2d::edit_corner2d); registry.add_editor(marker_shape::edit_marker_shape_ui); registry.add_editor(edit_scatter_ui); - registry.add_editor(visible::edit_visible); + + registry.add_editor::(datatype_editors::edit_bool); registry.add_editor::(datatype_editors::edit_singleline_string); registry.add_editor::(datatype_editors::edit_singleline_string); diff --git a/crates/re_edit_ui/src/visible.rs b/crates/re_edit_ui/src/visible.rs deleted file mode 100644 index 6e2ef2e3d45f5..0000000000000 --- a/crates/re_edit_ui/src/visible.rs +++ /dev/null @@ -1,15 +0,0 @@ -use re_types::blueprint::components::Visible; -use re_viewer_context::ViewerContext; - -pub fn edit_visible( - _ctx: &ViewerContext<'_>, - ui: &mut egui::Ui, - value: &mut Visible, -) -> egui::Response { - ui.scope(|ui| { - ui.visuals_mut().widgets.hovered.expansion = 0.0; - ui.visuals_mut().widgets.active.expansion = 0.0; - ui.add(re_ui::toggle_switch(15.0, &mut value.0)) - }) - .inner -}