-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce multiline edits and use it to implement 2d bounds editing
- Loading branch information
Showing
14 changed files
with
599 additions
and
211 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
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
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,51 +1,137 @@ | ||
use egui::NumExt as _; | ||
use re_types::blueprint::components::VisualBounds2D; | ||
use re_types::{blueprint::components::VisualBounds2D, datatypes::Range2D}; | ||
use re_viewer_context::ViewerContext; | ||
|
||
pub fn edit_visual_bounds_2d( | ||
_ctx: &ViewerContext<'_>, | ||
pub fn multiline_edit_visual_bounds_2d( | ||
ctx: &ViewerContext<'_>, | ||
ui: &mut egui::Ui, | ||
value: &mut VisualBounds2D, | ||
) -> egui::Response { | ||
let speed_func = |start: f64, end: f64| ((end - start).abs() * 0.01).at_least(0.001); | ||
|
||
ui.vertical(|ui| { | ||
ui.horizontal(|ui| { | ||
let [x_range_start, x_range_end] = &mut value.x_range.0; | ||
let speed = speed_func(*x_range_start, *x_range_end); | ||
|
||
ui.label("x"); | ||
ui.add( | ||
egui::DragValue::new(x_range_start) | ||
.clamp_range(f64::NEG_INFINITY..=*x_range_end) | ||
.max_decimals(2) | ||
.speed(speed), | ||
) | ui.add( | ||
egui::DragValue::new(x_range_end) | ||
.clamp_range(*x_range_start..=f64::INFINITY) | ||
.max_decimals(2) | ||
.speed(speed), | ||
) | ||
}) | ||
.inner | ||
| ui.horizontal(|ui| { | ||
let mut any_edit = false; | ||
|
||
let response_x = re_ui::list_item::ListItem::new(ctx.re_ui) | ||
.interactive(false) | ||
.show_hierarchical( | ||
ui, | ||
re_ui::list_item::PropertyContent::new("x").value_fn(|_, ui, _| { | ||
let [x_range_start, x_range_end] = &mut value.x_range.0; | ||
let speed = speed_func(*x_range_start, *x_range_end); | ||
|
||
let response = ui | ||
.horizontal_centered(|ui| { | ||
let response_min = ui.add( | ||
egui::DragValue::new(x_range_start) | ||
.clamp_range(f64::NEG_INFINITY..=*x_range_end) | ||
.max_decimals(2) | ||
.speed(speed), | ||
); | ||
|
||
ui.label("-"); | ||
|
||
let response_max = ui.add( | ||
egui::DragValue::new(x_range_end) | ||
.clamp_range(*x_range_start..=f64::INFINITY) | ||
.max_decimals(2) | ||
.speed(speed), | ||
); | ||
|
||
response_min | response_max | ||
}) | ||
.inner; | ||
|
||
if response.changed() { | ||
any_edit = true; | ||
} | ||
}), | ||
); | ||
|
||
let response_y = re_ui::list_item::ListItem::new(ctx.re_ui) | ||
.interactive(false) | ||
.show_hierarchical( | ||
ui, | ||
re_ui::list_item::PropertyContent::new("y").value_fn(|_, ui, _| { | ||
let [y_range_start, y_range_end] = &mut value.y_range.0; | ||
let speed = speed_func(*y_range_start, *y_range_end); | ||
|
||
ui.label("y"); | ||
ui.add( | ||
egui::DragValue::new(y_range_start) | ||
.clamp_range(f64::NEG_INFINITY..=*y_range_end) | ||
.max_decimals(2) | ||
.speed(speed), | ||
) | ui.add( | ||
egui::DragValue::new(y_range_end) | ||
.clamp_range(*y_range_start..=f64::INFINITY) | ||
.max_decimals(2) | ||
.speed(speed), | ||
) | ||
}) | ||
.inner | ||
}) | ||
.inner | ||
let response = ui | ||
.horizontal_centered(|ui| { | ||
let response_min = ui.add( | ||
egui::DragValue::new(y_range_start) | ||
.clamp_range(f64::NEG_INFINITY..=*y_range_end) | ||
.max_decimals(2) | ||
.speed(speed), | ||
); | ||
|
||
ui.label("-"); | ||
|
||
let response_max = ui.add( | ||
egui::DragValue::new(y_range_end) | ||
.clamp_range(*y_range_start..=f64::INFINITY) | ||
.max_decimals(2) | ||
.speed(speed), | ||
); | ||
|
||
response_min | response_max | ||
}) | ||
.inner; | ||
|
||
if response.changed() { | ||
any_edit = true; | ||
} | ||
}), | ||
); | ||
|
||
let mut response = response_x | response_y; | ||
if any_edit { | ||
response.mark_changed(); | ||
} | ||
response | ||
} | ||
|
||
pub fn singleline_edit_visual_bounds_2d( | ||
_ctx: &ViewerContext<'_>, | ||
ui: &mut egui::Ui, | ||
value: &mut VisualBounds2D, | ||
) -> egui::Response { | ||
let width = value.x_range.0[1] - value.x_range.0[0]; | ||
let height = value.y_range.0[1] - value.y_range.0[0]; | ||
|
||
let mut width_edit = width; | ||
let mut height_edit = height; | ||
|
||
let speed_func = |v: f64| (v.abs() * 0.01).at_least(0.001); | ||
|
||
let response_width = ui.add( | ||
egui::DragValue::new(&mut width_edit) | ||
.clamp_range(f64::NEG_INFINITY..=f64::INFINITY) | ||
.max_decimals(1) | ||
.speed(speed_func(width)), | ||
); | ||
ui.label("×"); | ||
let response_height = ui.add( | ||
egui::DragValue::new(&mut height_edit) | ||
.clamp_range(f64::NEG_INFINITY..=f64::INFINITY) | ||
.max_decimals(1) | ||
.speed(speed_func(height)), | ||
); | ||
|
||
let d_width = width_edit - width; | ||
let d_height = height_edit - height; | ||
*value = Range2D { | ||
x_range: [ | ||
value.x_range.0[0] - d_width * 0.5, | ||
value.x_range.0[1] + d_width * 0.5, | ||
] | ||
.into(), | ||
y_range: [ | ||
value.y_range.0[0] - d_height * 0.5, | ||
value.y_range.0[1] + d_height * 0.5, | ||
] | ||
.into(), | ||
} | ||
.into(); | ||
|
||
response_height | response_width | ||
} |
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
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
Oops, something went wrong.