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

Don't hover things in 2D/3D views if we are dragging something #1643

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions crates/re_ui/src/egui_helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// Is anything in egui being dragged?
pub fn is_anything_being_dragged(egui_ctx: &egui::Context) -> bool {
// As soon as a button is down, egui considers it a drag.
// That is, even a click is considered a drag until it is over.
// So we need some special treatment here.
// TODO(emilk): make it easier to distinguish between clicks and drags in egui.

// copied from egui
/// If the pointer is down for longer than this, it won't become a click (but it is still a drag)
const MAX_CLICK_DURATION: f64 = 0.6;
egui_ctx.input(|i| {
if let Some(press_start_time) = i.pointer.press_start_time() {
let held_time = i.time - press_start_time;
held_time > MAX_CLICK_DURATION || i.pointer.is_moving()
} else {
false
}
})
}
1 change: 1 addition & 0 deletions crates/re_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod command;
mod command_palette;
mod design_tokens;
pub mod egui_helpers;
pub mod icons;
mod static_image_cache;
pub mod toasts;
Expand Down
4 changes: 3 additions & 1 deletion crates/re_viewer/src/ui/view_spatial/ui_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,11 @@ fn view_2d_scrollable(
highlights,
);

let should_do_hovering = !re_ui::egui_helpers::is_anything_being_dragged(parent_ui.ctx());

// Check if we're hovering any hover primitive.
let mut depth_at_pointer = None;
if let Some(pointer_pos_ui) = response.hover_pos() {
if let (true, Some(pointer_pos_ui)) = (should_do_hovering, response.hover_pos()) {
let pointer_pos_space = space_from_ui.transform_pos(pointer_pos_ui);
let hover_radius = space_from_ui.scale().y * 5.0; // TODO(emilk): from egui?
let picking_result = scene.picking(
Expand Down
4 changes: 3 additions & 1 deletion crates/re_viewer/src/ui/view_spatial/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,11 @@ pub fn view_3d(
highlights,
);

let should_do_hovering = !re_ui::egui_helpers::is_anything_being_dragged(ui.ctx());

// TODO(andreas): We're very close making the hover reaction of ui2d and ui3d the same. Finish the job!
// Check if we're hovering any hover primitive.
if let Some(pointer_pos) = response.hover_pos() {
if let (true, Some(pointer_pos)) = (should_do_hovering, response.hover_pos()) {
let picking_result =
scene.picking(glam::vec2(pointer_pos.x, pointer_pos.y), &rect, &eye, 5.0);

Expand Down