diff options
Diffstat (limited to 'src/layout.zig')
| -rw-r--r-- | src/layout.zig | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/layout.zig b/src/layout.zig index 8db05a07..3637f30e 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -713,14 +713,26 @@ pub fn columnBySerial(p: *const Pardes, serial: u32) ?usize { return null; } -pub fn columnMoveTarget(p: *const Pardes, source: usize, x: u16) usize { - if (source >= p.ncol) return source; +/// What releasing column `source`'s grip at `x` does: past a neighbour's +/// middle it takes that column's place; short of it, as in acme, the +/// column's left edge moves to `x - grab`, clamped as setColumnPairWidth +/// clamps it. Still on the grip, or at the leftmost column, nothing moves. +/// The drag preview and the release both ask here, so they cannot disagree. +pub const ColumnDrop = union(enum) { stay, reorder: usize, edge: u16 }; + +pub fn columnDrop(p: *const Pardes, source: usize, x: u16, grab: u16) ColumnDrop { + if (source >= p.ncol) return .stay; var insertion: usize = 0; for (0..p.ncol) |column| { if (column == source) continue; if (x >= p.col_x[column] + p.col_w[column] / 2) insertion += 1; } - return insertion; + if (insertion != source) return .{ .reorder = insertion }; + if (source == 0 or (x >= p.col_x[source] and x < p.col_x[source] + config.GUTTER)) return .stay; + if (p.col_w[source - 1] + p.col_w[source] < 2 * config.MINW) return .stay; + const lo = p.col_x[source - 1] + config.MINW; + const hi = (p.col_x[source] + p.col_w[source]) -| config.MINW; + return .{ .edge = std.math.clamp(x -| grab, lo, @max(lo, hi)) }; } /// Share out the width of columns `left` and `left + 1` so the left one is |
