From 5b7fc51932900792e60a2c88233e16eb07f85db4 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 27 Jan 2021 20:58:49 +0100 Subject: [PATCH] Bug fix: moving windows slightly when dragging slider --- egui/src/containers/window.rs | 13 +++++++++++-- egui/src/context.rs | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index e87afbca..fb7ffa78 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -466,8 +466,17 @@ fn move_and_resize_window(ctx: &Context, window_interaction: &WindowInteraction) rect.max.y = ctx.round_to_pixel(pointer_pos.y); } } else { - // movement - rect = rect.translate(pointer_pos - ctx.input().pointer.press_origin()?); + // Movement. + + // We do window interaction first (to avoid frame delay), + // but we want anything interactive in the window (e.g. slider) to steal + // the drag from us. It is therefor important not to move the window the first frame, + // but instead let other widgets to the steal. HACK. + if !ctx.input().pointer.any_pressed() { + let press_origin = ctx.input().pointer.press_origin()?; + let delta = pointer_pos - press_origin; + rect = rect.translate(delta); + } } Some(rect) diff --git a/egui/src/context.rs b/egui/src/context.rs index ab236dfb..a7301f67 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -293,6 +293,11 @@ impl CtxRef { response.is_pointer_button_down_on = true; } + // HACK: windows have low priority on dragging. + // This is so that if you drag a slider in a window, + // the slider will steal the drag away from the window. + // This is needed because we do window interaction first (to prevent frame delay), + // and then do content layout. if sense.drag && (memory.interaction.drag_id.is_none() || memory.interaction.drag_is_window)