-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make bool edit_ui generic (there's more bools incoming soon!
- Loading branch information
Showing
5 changed files
with
20 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Target = f32>, | ||
value: &mut impl std::ops::DerefMut<Target = bool>, | ||
) -> 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.