From cde1d8d1edb0c8001a28a2a674c46b5a581439db Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Wed, 4 Jul 2018 21:40:16 +0200 Subject: [PATCH] Fix incorrect cell side in selection Previously the cell side of a selection with the mouse outside of the grid has been calculated by setting the `Side` to `Right` whenever the `X` of the mouse is bigger or equal to `window_width - padding_x`. However since the grid doesn't perfectly fit the window in most cases, there was an additional few pixels where the `Side` would be `Left`, resulting in the selection jumping around. To fix this the additional padding due to not perfectly fitting window size has been included in the calculation. The `X` position is now checked to be bigger or equal to `width - padding_x - extra_padding_x`. An important note is that this will need changing when the grid is centered inside the window, so extra padding is split up evenly. Once that change is merged the calculation required will be `width - padding_x - extra_padding_x / 2.`. This fixes #1412. --- src/input.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/input.rs b/src/input.rs index 90384198..2d647114 100644 --- a/src/input.rs +++ b/src/input.rs @@ -304,9 +304,11 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { let cell_x = x.saturating_sub(size_info.padding_x as usize) % size_info.cell_width as usize; let half_cell_width = (size_info.cell_width / 2.0) as usize; + let additional_padding = (size_info.width - size_info.padding_x * 2.) % size_info.cell_width; + let end_of_grid = size_info.width - size_info.padding_x - additional_padding; let cell_side = if cell_x > half_cell_width // Edge case when mouse leaves the window - || x as f32 >= size_info.width - size_info.padding_x + || x as f32 >= end_of_grid { Side::Right } else {