Bug fix: moving windows slightly when dragging slider

This commit is contained in:
Emil Ernerfeldt 2021-01-27 20:58:49 +01:00
parent 703592ae0c
commit 5b7fc51932
2 changed files with 16 additions and 2 deletions

View file

@ -466,8 +466,17 @@ fn move_and_resize_window(ctx: &Context, window_interaction: &WindowInteraction)
rect.max.y = ctx.round_to_pixel(pointer_pos.y); rect.max.y = ctx.round_to_pixel(pointer_pos.y);
} }
} else { } else {
// movement // Movement.
rect = rect.translate(pointer_pos - ctx.input().pointer.press_origin()?);
// 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) Some(rect)

View file

@ -293,6 +293,11 @@ impl CtxRef {
response.is_pointer_button_down_on = true; 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 if sense.drag
&& (memory.interaction.drag_id.is_none() && (memory.interaction.drag_id.is_none()
|| memory.interaction.drag_is_window) || memory.interaction.drag_is_window)