diff --git a/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs b/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs new file mode 100644 index 000000000000..12237408907a --- /dev/null +++ b/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs @@ -0,0 +1,22 @@ +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, +) -> egui::Response { + edit_f32_zero_to_inf_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), + ) +} diff --git a/crates/re_edit_ui/src/datatype_editors/float_drag.rs b/crates/re_edit_ui/src/datatype_editors/float_drag.rs new file mode 100644 index 000000000000..12237408907a --- /dev/null +++ b/crates/re_edit_ui/src/datatype_editors/float_drag.rs @@ -0,0 +1,22 @@ +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, +) -> egui::Response { + edit_f32_zero_to_inf_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), + ) +} diff --git a/crates/re_edit_ui/src/datatype_editors/mod.rs b/crates/re_edit_ui/src/datatype_editors/mod.rs new file mode 100644 index 000000000000..d6d74d925e7b --- /dev/null +++ b/crates/re_edit_ui/src/datatype_editors/mod.rs @@ -0,0 +1,5 @@ +mod float_drag; +mod singleline_string; + +pub use float_drag::edit_f32_zero_to_inf; +pub use singleline_string::edit_singleline_string; diff --git a/crates/re_edit_ui/src/singleline_string.rs b/crates/re_edit_ui/src/datatype_editors/singleline_string.rs similarity index 100% rename from crates/re_edit_ui/src/singleline_string.rs rename to crates/re_edit_ui/src/datatype_editors/singleline_string.rs diff --git a/crates/re_edit_ui/src/lib.rs b/crates/re_edit_ui/src/lib.rs index cdabd5176c54..9fbaa6f9945c 100644 --- a/crates/re_edit_ui/src/lib.rs +++ b/crates/re_edit_ui/src/lib.rs @@ -4,15 +4,13 @@ //! This should be called by `re_viewer` on startup. mod corner2d; +mod datatype_editors; mod marker_shape; mod response_utils; -mod singleline_string; mod visible; -use egui::NumExt as _; use re_types::components::{Color, MarkerSize, Name, Radius, StrokeWidth, Text}; use re_viewer_context::ViewerContext; -use singleline_string::edit_singleline_string; // ---- @@ -29,46 +27,6 @@ fn edit_color_ui(_ctx: &ViewerContext<'_>, ui: &mut egui::Ui, value: &mut Color) response } -fn edit_radius_ui( - _ctx: &ViewerContext<'_>, - ui: &mut egui::Ui, - value: &mut Radius, -) -> egui::Response { - let speed = (value.0 * 0.01).at_least(0.001); - - ui.add( - egui::DragValue::new(&mut value.0) - .clamp_range(0.0..=f64::INFINITY) - .speed(speed), - ) -} - -fn edit_stroke_width_ui( - _ctx: &ViewerContext<'_>, - ui: &mut egui::Ui, - value: &mut StrokeWidth, -) -> egui::Response { - let speed = (value.0 * 0.01).at_least(0.001); - ui.add( - egui::DragValue::new(&mut value.0) - .clamp_range(0.0..=f64::INFINITY) - .speed(speed), - ) -} - -fn edit_marker_size_ui( - _ctx: &ViewerContext<'_>, - ui: &mut egui::Ui, - value: &mut MarkerSize, -) -> egui::Response { - let speed = (value.0 * 0.01).at_least(0.001); - ui.add( - egui::DragValue::new(&mut value.0) - .clamp_range(0.0..=f64::INFINITY) - .speed(speed), - ) -} - // ---- /// Registers all editors of this crate in the component UI registry. @@ -79,11 +37,13 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) { registry.add_editor(edit_color_ui); registry.add_editor(corner2d::edit_corner2d); registry.add_editor(marker_shape::edit_marker_shape_ui); - registry.add_editor(edit_marker_size_ui); - registry.add_editor(edit_radius_ui); - registry.add_editor(edit_stroke_width_ui); + registry.add_editor(visible::edit_visible); - registry.add_editor::(edit_singleline_string); - registry.add_editor::(edit_singleline_string); + registry.add_editor::(datatype_editors::edit_singleline_string); + registry.add_editor::(datatype_editors::edit_singleline_string); + + registry.add_editor::(datatype_editors::edit_f32_zero_to_inf); + registry.add_editor::(datatype_editors::edit_f32_zero_to_inf); + registry.add_editor::(datatype_editors::edit_f32_zero_to_inf); }