diff options
Diffstat (limited to 'src/layout.zig')
| -rw-r--r-- | src/layout.zig | 354 |
1 files changed, 166 insertions, 188 deletions
diff --git a/src/layout.zig b/src/layout.zig index bcee3fba..aec8587c 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -81,7 +81,7 @@ pub const window_labels = "asfgqwertyuiopzxvbnm"; /// The letter window mode shows on pane `id`. pub fn windowLabel(p: *const Pardes, id: usize) ?u8 { var n: usize = 0; - for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]]) |pane| { + for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n]) |pane| { if (n == window_labels.len) return null; if (pane == id) return window_labels[n]; n += 1; @@ -140,17 +140,17 @@ pub fn windowKey(p: *Pardes, key: pardes.Key) void { /// Column `c`'s serial, handed out the first time it is asked for. pub fn columnSerial(p: *Pardes, c: usize) u32 { - if (p.col_serial[c] == 0) { - p.col_serial[c] = p.next_column_serial; + if (p.cols[c].serial == 0) { + p.cols[c].serial = p.next_column_serial; p.next_column_serial +%= 1; if (p.next_column_serial == 0) p.next_column_serial = 1; } - return p.col_serial[c]; + return p.cols[c].serial; } pub fn columnBySerial(p: *const Pardes, serial: u32) ?usize { if (serial == 0) return null; - for (0..p.ncol) |column| if (p.col_serial[column] == serial) return column; + for (0..p.ncol) |column| if (p.cols[column].serial == serial) return column; return null; } @@ -190,36 +190,27 @@ pub fn setColumnPairWidth(p: *Pardes, left: usize, left_width: u64) void { // Too narrow for both to keep MINW: any split would squeeze one away. if (combined < 2 * @as(u64, config.MINW)) return; const width = std.math.clamp(left_width, config.MINW, @max(@as(u64, config.MINW), combined -| config.MINW)); - const pair = p.col_weight[left] + p.col_weight[left + 1]; + const pair = p.cols[left].weight + p.cols[left + 1].weight; if (pair <= 1 or combined == 0) return; const numerator = @as(u128, pair) * width + combined / 2; const share = std.math.clamp(@as(u64, @intCast(numerator / combined)), 1, pair - 1); - p.col_weight[left] = share; - p.col_weight[left + 1] = pair - share; + p.cols[left].weight = share; + p.cols[left + 1].weight = pair - share; } pub fn reorderColumn(p: *Pardes, from: usize, to: usize) void { if (from >= p.ncol or to >= p.ncol or from == to) return; - const ids = p.col_panes[from]; - const count = p.col_n[from]; - const weight = p.col_weight[from]; + const moved = p.cols[from]; const tag = p.col_tags[from]; - const serial = p.col_serial[from]; var at = from; while (at != to) { const next = if (at < to) at + 1 else at - 1; - p.col_panes[at] = p.col_panes[next]; - p.col_n[at] = p.col_n[next]; - p.col_weight[at] = p.col_weight[next]; + p.cols[at] = p.cols[next]; p.col_tags[at] = p.col_tags[next]; - p.col_serial[at] = p.col_serial[next]; at = next; } - p.col_panes[to] = ids; - p.col_n[to] = count; - p.col_weight[to] = weight; + p.cols[to] = moved; p.col_tags[to] = tag; - p.col_serial[to] = serial; if (p.header_column) |column| { if (column == from) p.header_column = to else if (from < to and column > from and column <= to) { p.header_column = column - 1; @@ -264,9 +255,9 @@ pub fn movePlacement(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) ?MovePlaceme const span_end = if (ownerOf(p, id) == null) groupEnd(p, src.col, src.idx) else src.idx + 1; const own_root = groupRoot(p, id); const tc = targetColumn(p, cur_x); - if (tc == src.col and p.col_n[src.col] == span_end - src.idx) return null; + if (tc == src.col and p.cols[src.col].n == span_end - src.idx) return null; var span_h: u16 = 0; - for (p.col_panes[src.col][src.idx..span_end]) |k| span_h +|= p.rects[k].h; + for (p.cols[src.col].panes[src.idx..span_end]) |k| span_h +|= p.rects[k].h; if (tc == src.col) { const top = p.rects[id].y; // Dropped on itself it stays, unless dragged down from its top with @@ -278,28 +269,28 @@ pub fn movePlacement(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) ?MovePlaceme // Every pane's rows as laid out; only the placed panes' are read. var heights: [MAX_PANES]u16 = undefined; for (&heights, p.rects) |*h, r| h.* = r.h; - if (p.col_n[src.col] > span_end - src.idx) { - const sib = if (src.idx > 0) p.col_panes[src.col][src.idx - 1] else p.col_panes[src.col][span_end]; + if (p.cols[src.col].n > span_end - src.idx) { + const sib = if (src.idx > 0) p.cols[src.col].panes[src.idx - 1] else p.cols[src.col].panes[span_end]; heights[sib] +|= span_h; } var y: u16 = p.topBarHeight() + columnBarHeight(p); - if (p.col_n[tc] == 0) return .{ .preview_col = tc, .above_id = null, .row = y, .above_y = y, .above_h = 0 }; + if (p.cols[tc].n == 0) return .{ .preview_col = tc, .above_id = null, .row = y, .above_y = y, .above_h = 0 }; var last: ?MovePlacement = null; var k: usize = 0; - while (k < p.col_n[tc]) { + while (k < p.cols[tc].n) { if (tc == src.col and k >= src.idx and k < span_end) { k += 1; continue; } // Its own group's panes are places of their own: that is how an // attachment's grip resizes it against its owner. - const unit_end = if (groupRoot(p, p.col_panes[tc][k]) == own_root) k + 1 else groupEnd(p, tc, k); + const unit_end = if (groupRoot(p, p.cols[tc].panes[k]) == own_root) k + 1 else groupEnd(p, tc, k); var h: u16 = 0; for (k..unit_end) |j| { if (tc == src.col and j >= src.idx and j < span_end) continue; - h +|= heights[p.col_panes[tc][j]]; + h +|= heights[p.cols[tc].panes[j]]; } - const above = p.col_panes[tc][unit_end - 1]; + const above = p.cols[tc].panes[unit_end - 1]; k = unit_end; const row = splitRowFor(y, h, cur_y, if (tc == src.col) BOX_H else null) orelse { y +|= h; @@ -329,15 +320,15 @@ pub fn movePane(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) void { const span_end = if (owner == null) groupEnd(p, src.col, src.idx) else src.idx + 1; const count = span_end - src.idx; var moved: [MAX_PANES]usize = undefined; - @memcpy(moved[0..count], p.col_panes[src.col][src.idx..span_end]); - const source_multi = p.col_n[src.col] > count; + @memcpy(moved[0..count], p.cols[src.col].panes[src.idx..span_end]); + const source_multi = p.cols[src.col].n > count; var heights: [MAX_PANES]u16 = undefined; for (&heights, p.rects) |*h, r| h.* = r.h; var span_h: u16 = 0; for (moved[0..count]) |m| span_h +|= heights[m]; for (moved[0..count]) |m| removePane(p, m); if (source_multi) { - const sib = if (src.idx > 0) p.col_panes[src.col][src.idx - 1] else p.col_panes[src.col][src.idx]; + const sib = if (src.idx > 0) p.cols[src.col].panes[src.idx - 1] else p.cols[src.col].panes[src.idx]; heights[sib] +|= span_h; } const above = placement.above_id orelse { @@ -378,8 +369,8 @@ pub fn movePane(p: *Pardes, id: usize, cur_x: u16, cur_y: u16) void { pub fn setColumnWeights(p: *Pardes, col: usize, heights: *const [MAX_PANES]u16) void { if (col >= p.ncol) return; - for (0..p.col_n[col]) |k| { - const pid = p.col_panes[col][k]; + for (0..p.cols[col].n) |k| { + const pid = p.cols[col].panes[k]; if (p.panes[pid]) |pane| if (!pane.collapsed) { pane.vweight = @floatFromInt(@max(1, heights[pid])); }; @@ -392,9 +383,9 @@ pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void { const at = findPane(p, id) orelse return; compute(p); var heights: [MAX_PANES]u16 = @splat(0); - for (p.col_panes[at.col][0..p.col_n[at.col]]) |other| heights[other] = p.rects[other].h; + for (p.cols[at.col].panes[0..p.cols[at.col].n]) |other| heights[other] = p.rects[other].h; var missing = wanted -| heights[id]; - for (p.col_panes[at.col][0..p.col_n[at.col]]) |other| { + for (p.cols[at.col].panes[0..p.cols[at.col].n]) |other| { if (other == id or p.panes[other].?.collapsed) continue; const body_rows: u16 = if (other == context) 6 else 3; const minimum = @max(minRows(p, other), p.panes[other].?.tag_rows + body_rows); @@ -409,17 +400,17 @@ pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void { } pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void { - if (k + 1 >= p.col_n[cc]) return; - const a = p.panes[p.col_panes[cc][k]] orelse return; - const b = p.panes[p.col_panes[cc][k + 1]] orelse return; - const ra = p.rects[p.col_panes[cc][k]]; - const rb = p.rects[p.col_panes[cc][k + 1]]; + if (k + 1 >= p.cols[cc].n) return; + const a = p.panes[p.cols[cc].panes[k]] orelse return; + const b = p.panes[p.cols[cc].panes[k + 1]] orelse return; + const ra = p.rects[p.cols[cc].panes[k]]; + const rb = p.rects[p.cols[cc].panes[k + 1]]; const combined: f32 = @floatFromInt(ra.h + rb.h); var nt: f32 = @floatFromInt(if (p.settings.tag_bottom) cur_y -| ra.y else (cur_y + 1) -| ra.y); // A terminal keeps its tag and two body rows (floorRows); a text pane // gives up all but its tag, as acme's do. - const lo: f32 = @floatFromInt(@max(BOX_H, floorRows(p, p.col_panes[cc][k]))); - const hi = combined - @as(f32, @floatFromInt(@max(BOX_H, floorRows(p, p.col_panes[cc][k + 1])))); + const lo: f32 = @floatFromInt(@max(BOX_H, floorRows(p, p.cols[cc].panes[k]))); + const hi = combined - @as(f32, @floatFromInt(@max(BOX_H, floorRows(p, p.cols[cc].panes[k + 1])))); nt = std.math.clamp(nt, @min(lo, @max(@as(f32, BOX_H), hi)), @max(@as(f32, BOX_H), hi)); if (combined <= 0) return; // Dragging a folded tag open is an explicit resize, so switch this pair @@ -439,18 +430,18 @@ pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void { pub fn findPane(p: *const Pardes, id: usize) ?struct { col: usize, idx: usize } { for (0..p.ncol) |c| { - for (0..p.col_n[c]) |k| { - if (p.col_panes[c][k] == id) return .{ .col = c, .idx = k }; + for (0..p.cols[c].n) |k| { + if (p.cols[c].panes[k] == id) return .{ .col = c, .idx = k }; } } return null; } pub fn insert(p: *Pardes, c: usize, idx: usize, id: usize) void { - var k = p.col_n[c]; - while (k > idx) : (k -= 1) p.col_panes[c][k] = p.col_panes[c][k - 1]; - p.col_panes[c][idx] = id; - p.col_n[c] += 1; + var k = p.cols[c].n; + while (k > idx) : (k -= 1) p.cols[c].panes[k] = p.cols[c].panes[k - 1]; + p.cols[c].panes[idx] = id; + p.cols[c].n += 1; } /// Take a pane out of its column. The column stays, empty if this was its @@ -460,8 +451,8 @@ pub fn removePane(p: *Pardes, id: usize) void { const f = findPane(p, id) orelse return; const c = f.col; var k = f.idx; - while (k + 1 < p.col_n[c]) : (k += 1) p.col_panes[c][k] = p.col_panes[c][k + 1]; - p.col_n[c] -= 1; + while (k + 1 < p.cols[c].n) : (k += 1) p.cols[c].panes[k] = p.cols[c].panes[k + 1]; + p.cols[c].n -= 1; } /// Close column `c` once its panes are gone, its width to the one left of @@ -474,26 +465,23 @@ pub fn dropColumn(p: *Pardes, c: usize) void { /// dropColumn with no `delcol`, for a column never announced. pub fn dropColumnUnannounced(p: *Pardes, c: usize) void { - std.debug.assert(p.col_n[c] == 0); + std.debug.assert(p.cols[c].n == 0); tagline.exitHeader(p); // The finder's width was its share, no weight: nobody gets one, so the // others are as wide as before it came. A column whose weight would go // to the finder gives it to the column on the finder's other side. const finder = p.finder.column(p); const heir: ?usize = if (p.ncol <= 1 or finder == c) null else if (c > 0 and finder != c - 1) c - 1 else if (c + 1 < p.ncol and finder != c + 1) c + 1 else if (c > 1) c - 2 else if (c + 2 < p.ncol) c + 2 else null; - if (heir) |h| p.col_weight[h] +|= p.col_weight[c]; + if (heir) |h| p.cols[h].weight +|= p.cols[c].weight; p.col_tags[c].deinit(p.gpa); var j = c; while (j + 1 < p.ncol) : (j += 1) { - p.col_panes[j] = p.col_panes[j + 1]; - p.col_n[j] = p.col_n[j + 1]; - p.col_weight[j] = p.col_weight[j + 1]; + p.cols[j] = p.cols[j + 1]; p.col_tags[j] = p.col_tags[j + 1]; - p.col_serial[j] = p.col_serial[j + 1]; } p.ncol -= 1; p.col_tags[p.ncol] = .{ .what = .column, .gpa = p.gpa }; - p.col_serial[p.ncol] = 0; + p.cols[p.ncol].serial = 0; } /// `newcol <serial>` or `delcol <serial>` in the log: the column's serial, @@ -517,28 +505,22 @@ pub fn joinCol(p: *Pardes, c: usize) void { pub fn joinFits(p: *Pardes, c: usize) bool { if (c + 1 >= p.ncol) return true; const dst = c + 1; - const n = p.col_n[c]; - const had = p.col_n[dst]; - const weights = .{ p.col_weight[c], p.col_weight[dst] }; - const panes_c = p.col_panes[c]; + const kept = .{ p.cols[c], p.cols[dst] }; joinPanes(p, c, dst); const fits = minimaFit(p); - p.col_n[dst] = had; - p.col_n[c] = n; - p.col_panes[c] = panes_c; - p.col_weight[c] = weights[0]; - p.col_weight[dst] = weights[1]; + p.cols[c] = kept[0]; + p.cols[dst] = kept[1]; compute(p); return fits; } fn joinPanes(p: *Pardes, c: usize, dst: usize) void { - for (0..p.col_n[c]) |k| p.col_panes[dst][p.col_n[dst] + k] = p.col_panes[c][k]; - p.col_n[dst] += p.col_n[c]; - p.col_n[c] = 0; + for (0..p.cols[c].n) |k| p.cols[dst].panes[p.cols[dst].n + k] = p.cols[c].panes[k]; + p.cols[dst].n += p.cols[c].n; + p.cols[c].n = 0; // The width goes right, where the panes went. - p.col_weight[dst] +|= p.col_weight[c]; - p.col_weight[c] = 0; + p.cols[dst].weight +|= p.cols[c].weight; + p.cols[c].weight = 0; } /// Put new pane `id` in column `c` as acme's makenewwindow does @@ -550,7 +532,7 @@ fn joinPanes(p: *Pardes, c: usize, dst: usize) void { /// that is in the column and not much smaller. pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void { compute(p); - const n = p.col_n[c]; + const n = p.cols[c].n; if (n == 0) { insert(p, c, 0, id); p.panes[id].?.vweight = 1; @@ -558,7 +540,7 @@ pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void { } var big: ?usize = null; var empty: ?usize = null; - for (p.col_panes[c][0..n]) |k| { + for (p.cols[c].panes[0..n]) |k| { const pane = p.panes[k] orelse continue; // An attachment is its owner's: never halved for another pane. if (pane.collapsed or ownerOf(p, k) != null) continue; @@ -574,7 +556,7 @@ pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void { const y: u16 = y: { const o = origin orelse { var last = v0; - for (p.col_panes[c][0..n]) |k| if (!p.panes[k].?.collapsed and ownerOf(p, k) == null) { + for (p.cols[c].panes[0..n]) |k| if (!p.panes[k].?.collapsed and ownerOf(p, k) == null) { last = k; }; break :y bodyFrom(p, last) + bodyRows(p, last) / 2; @@ -610,9 +592,9 @@ pub fn minimaFit(p: *Pardes) bool { compute(p); const avail = p.screen_h -| (p.topBarHeight() + columnBarHeight(p)); for (0..p.ncol) |c| { - if (p.col_n[c] < 2) continue; + if (p.cols[c].n < 2) continue; var need: u32 = 0; - for (p.col_panes[c][0..p.col_n[c]]) |k| { + for (p.cols[c].panes[0..p.cols[c].n]) |k| { const pane = p.panes[k] orelse continue; need += if (pane.collapsed) BOX_H else minRows(p, k); } @@ -625,8 +607,8 @@ pub fn minimaFit(p: *Pardes) bool { /// alone in its column always does). pub fn columnAtMinimums(p: *Pardes, c: usize) bool { compute(p); - if (p.col_n[c] < 2) return true; - for (p.col_panes[c][0..p.col_n[c]]) |k| { + if (p.cols[c].n < 2) return true; + for (p.cols[c].panes[0..p.cols[c].n]) |k| { const pane = p.panes[k] orelse continue; if (!pane.collapsed and p.rects[k].h < minRows(p, k)) return false; } @@ -638,12 +620,12 @@ pub fn columnAtMinimums(p: *Pardes, c: usize) bool { /// column has not the rows for all of them (or holds a folded pane). pub fn shareColumn(p: *Pardes, c: usize) bool { compute(p); - const n = p.col_n[c]; + const n = p.cols[c].n; if (n == 0) return false; const avail = p.screen_h -| (p.topBarHeight() + columnBarHeight(p)); var mins: [MAX_PANES]u16 = undefined; var need: u32 = 0; - for (p.col_panes[c][0..n], 0..) |k, i| { + for (p.cols[c].panes[0..n], 0..) |k, i| { const pane = p.panes[k] orelse return false; if (pane.collapsed) return false; p.rects[k].w = p.col_w[c]; @@ -662,7 +644,7 @@ pub fn shareColumn(p: *Pardes, c: usize) bool { }; hs[low] += 1; } - for (p.col_panes[c][0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(hs[i]); + for (p.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(hs[i]); compute(p); return true; } @@ -672,7 +654,7 @@ pub fn shareColumn(p: *Pardes, c: usize) bool { pub fn minima(p: *Pardes) [MAX_PANES]u16 { compute(p); var mins: [MAX_PANES]u16 = @splat(0); - for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]]) |k| { + for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n]) |k| { mins[k] = minRows(p, k); }; return mins; @@ -687,12 +669,12 @@ pub fn minima(p: *Pardes) [MAX_PANES]u16 { pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: ?*const [MAX_PANES]u16) void { compute(p); for (0..p.ncol) |c| { - const n = p.col_n[c]; + const n = p.cols[c].n; if (n < 2) continue; var hs: [MAX_PANES]u16 = undefined; var mins: [MAX_PANES]u16 = undefined; var short = false; - for (p.col_panes[c][0..n], 0..) |k, i| { + for (p.cols[c].panes[0..n], 0..) |k, i| { const pane = p.panes[k] orelse return; if (pane.collapsed) break; hs[i] = p.rects[k].h; @@ -700,7 +682,7 @@ pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: if (hs[i] < mins[i] and before[k].h >= if (before_min) |bm| bm[k] else mins[i]) short = true; } else { if (!short) continue; - for (p.col_panes[c][0..n], 0..) |k, i| { + for (p.cols[c].panes[0..n], 0..) |k, i| { if (hs[i] >= mins[i] or before[k].h < if (before_min) |bm| bm[k] else mins[i]) continue; while (hs[i] < mins[i]) { var giver: ?usize = null; @@ -714,7 +696,7 @@ pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: hs[i] += 1; } } - for (p.col_panes[c][0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i])); + for (p.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i])); } } compute(p); @@ -731,8 +713,8 @@ pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_m restoreMinimaFrom(p, before, before_min); for (0..p.ncol) |k| { compute(p); - if (p.col_n[k] < 2) continue; - const squeezed = for (p.col_panes[k][0..p.col_n[k]]) |id| { + if (p.cols[k].n < 2) continue; + const squeezed = for (p.cols[k].panes[0..p.cols[k].n]) |id| { const pane = p.panes[id] orelse continue; if (!pane.collapsed and p.rects[id].h < minRows(p, id) and before[id].h >= before_min[id]) break true; } else false; @@ -750,13 +732,13 @@ pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_m /// False, changing nothing, when the column has not the rows. pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool { compute(p); - const n = p.col_n[c]; + const n = p.cols[c].n; p.rects[id].w = p.col_w[c]; var need = minRows(p, id); var hs: [MAX_PANES]u16 = undefined; var mins: [MAX_PANES]u16 = undefined; var spare: u32 = 0; - for (p.col_panes[c][0..n], 0..) |k, i| { + for (p.cols[c].panes[0..n], 0..) |k, i| { const pane = p.panes[k] orelse return false; if (pane.collapsed) return false; hs[i] = p.rects[k].h; @@ -771,7 +753,7 @@ pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool { }; hs[giver] -= 1; } - for (p.col_panes[c][0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i])); + for (p.cols[c].panes[0..n], 0..) |k, i| p.panes[k].?.vweight = @floatFromInt(@max(1, hs[i])); insert(p, c, n, id); p.panes[id].?.vweight = @floatFromInt(minRows(p, id)); compute(p); @@ -785,8 +767,8 @@ pub fn takeRoom(p: *Pardes, c: usize, id: usize) bool { pub fn placedRoomy(p: *Pardes, id: usize, before: *const [MAX_PANES]Rect) bool { compute(p); const f = findPane(p, id) orelse return true; - if (p.col_n[f.col] == 1) return true; - for (p.col_panes[f.col][0..p.col_n[f.col]]) |k| { + if (p.cols[f.col].n == 1) return true; + for (p.cols[f.col].panes[0..p.cols[f.col].n]) |k| { const pane = p.panes[k] orelse continue; if (pane.collapsed) continue; if (k != id and p.rects[k].h >= before[k].h) continue; @@ -801,7 +783,7 @@ pub fn placedRoomy(p: *Pardes, id: usize, before: *const [MAX_PANES]Rect) bool { pub fn splitTallest(p: *Pardes, c: usize, id: usize) bool { compute(p); var tall: ?usize = null; - for (p.col_panes[c][0..p.col_n[c]]) |k| { + for (p.cols[c].panes[0..p.cols[c].n]) |k| { if (k == id or p.panes[k].?.collapsed or ownerOf(p, k) != null) continue; if (tall == null or p.rects[k].h > p.rects[tall.?].h) tall = k; } @@ -811,7 +793,7 @@ pub fn splitTallest(p: *Pardes, c: usize, id: usize) bool { p.rects[id].w = p.col_w[c]; if (h < minRows(p, v) + minRows(p, id)) return false; snapColWeights(p, c); - insert(p, c, p.col_n[c], id); + insert(p, c, p.cols[c].n, id); const given = std.math.clamp(h / 2, minRows(p, id), h - minRows(p, v)); p.panes[v].?.vweight = @floatFromInt(h - given); p.panes[id].?.vweight = @floatFromInt(given); @@ -824,10 +806,10 @@ pub fn splitTallest(p: *Pardes, c: usize, id: usize) bool { /// `y` in a group: the new pane goes under all of it, its rows from the /// group's owner, so nothing lands between a pane and its results. fn splitAt(p: *Pardes, c: usize, id: usize, y: u16) void { - const n = p.col_n[c]; + const n = p.cols[c].n; var k: usize = 0; - while (k + 1 < n and y >= p.rects[p.col_panes[c][k]].y + p.rects[p.col_panes[c][k]].h) k += 1; - const v = groupRoot(p, p.col_panes[c][k]); + while (k + 1 < n and y >= p.rects[p.cols[c].panes[k]].y + p.rects[p.cols[c].panes[k]].h) k += 1; + const v = groupRoot(p, p.cols[c].panes[k]); const r = p.rects[v]; snapColWeights(p, c); insert(p, c, groupEnd(p, c, k), id); @@ -880,9 +862,9 @@ pub fn canSplitCol(p: *Pardes, col: usize) bool { compute(p); if (p.col_w[col] < config.MINW * 2) return false; - const weight = p.col_weight[col]; + const weight = p.cols[col].weight; if (weight >= 2 and weight % 2 == 0) return true; - for (0..p.ncol) |column| if (p.col_weight[column] > std.math.maxInt(u64) / 2) + for (0..p.ncol) |column| if (p.cols[column].weight > std.math.maxInt(u64) / 2) return false; return weight > 0; } @@ -893,10 +875,8 @@ pub fn canSplitCol(p: *Pardes, col: usize) bool { /// its first one, empty; null when it has columns. pub fn firstColumn(p: *Pardes) ?usize { if (p.ncol != 0) return null; - p.col_weight[0] = 2; + p.cols[0] = .{ .weight = 2 }; p.col_tags[0] = .{ .what = .column, .gpa = p.gpa }; - p.col_serial[0] = 0; - p.col_n[0] = 0; p.ncol = 1; noteColumn(p, "newcol", columnSerial(p, 0)); return 0; @@ -912,27 +892,22 @@ pub fn insertColumn(p: *Pardes, col: usize, before: bool) ?usize { /// yet be taken back (Newcol's trial), which then leaves no trace. pub fn insertColumnUnannounced(p: *Pardes, col: usize, before: bool) ?usize { if (!canSplitCol(p, col)) return null; - var old_weight = p.col_weight[col]; + var old_weight = p.cols[col].weight; if (old_weight < 2 or old_weight % 2 != 0) { old_weight *= 2; - for (0..p.ncol) |column| p.col_weight[column] *= 2; + for (0..p.ncol) |column| p.cols[column].weight *= 2; } const source_weight = old_weight / 2; - p.col_weight[col] = source_weight; + p.cols[col].weight = source_weight; const c = col + @intFromBool(!before); tagline.exitHeader(p); var j = p.ncol; while (j > c) : (j -= 1) { - p.col_panes[j] = p.col_panes[j - 1]; - p.col_n[j] = p.col_n[j - 1]; - p.col_weight[j] = p.col_weight[j - 1]; + p.cols[j] = p.cols[j - 1]; p.col_tags[j] = p.col_tags[j - 1]; - p.col_serial[j] = p.col_serial[j - 1]; } - p.col_weight[c] = old_weight - source_weight; + p.cols[c] = .{ .weight = old_weight - source_weight }; p.col_tags[c] = .{ .what = .column, .gpa = p.gpa }; - p.col_serial[c] = 0; - p.col_n[c] = 0; p.ncol += 1; return c; } @@ -945,7 +920,7 @@ pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool { const source = findPane(p, source_id) orelse return false; if (!canSplitCol(p, source.col)) return false; if (id == source_id) { - if (p.col_n[source.col] <= 1) return false; + if (p.cols[source.col].n <= 1) return false; _ = absorbVWeight(p, id, null); removePane(p, id); } else if (findPane(p, id) != null) return false; @@ -955,8 +930,8 @@ pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool { } pub fn snapColWeights(p: *Pardes, c: usize) void { - for (0..p.col_n[c]) |k| { - const pid = p.col_panes[c][k]; + for (0..p.cols[c].n) |k| { + const pid = p.cols[c].panes[k]; if (p.panes[pid]) |pp| if (!pp.collapsed) { pp.vweight = @floatFromInt(@max(1, p.rects[pid].h)); }; @@ -970,15 +945,15 @@ pub fn snapColWeights(p: *Pardes, c: usize) void { /// (the pane below for the top one); the pane that got them is returned. pub fn absorbVWeight(p: *Pardes, id: usize, to: ?usize) ?usize { const f = findPane(p, id) orelse return null; - if (p.col_n[f.col] <= 1) return null; + if (p.cols[f.col].n <= 1) return null; // A refused pane held no weight: the rows the others' rounding lent it // go back to them as they were, nobody's weight snapped. if (p.panes[id]) |pane| if (!pane.collapsed and pane.vweight == 0) return null; snapColWeights(p, f.col); - var sib = to orelse if (f.idx > 0) p.col_panes[f.col][f.idx - 1] else p.col_panes[f.col][f.idx + 1]; + var sib = to orelse if (f.idx > 0) p.cols[f.col].panes[f.idx - 1] else p.cols[f.col].panes[f.idx + 1]; var k = f.idx; while (to == null and k > 0) : (k -= 1) { - sib = p.col_panes[f.col][k - 1]; + sib = p.cols[f.col].panes[k - 1]; // nor to a pane attached to another: rows go to owners if (p.panes[sib]) |pp| if (if (pp.file) |ff| panes.Output.fileTraits(ff.output).doc else true) if (ownerOf(p, sib) == null) break; } @@ -1055,9 +1030,9 @@ fn descends(p: *const Pardes, id: usize, root: usize) bool { /// One past the last pane of the group that pane `idx` of column `c` is /// in: `idx + 1` for a pane with nothing attached. pub fn groupEnd(p: *const Pardes, c: usize, idx: usize) usize { - const root = groupRoot(p, p.col_panes[c][idx]); + const root = groupRoot(p, p.cols[c].panes[idx]); var k = idx + 1; - while (k < p.col_n[c] and descends(p, p.col_panes[c][k], root) and p.col_panes[c][k] != root) k += 1; + while (k < p.cols[c].n and descends(p, p.cols[c].panes[k], root) and p.cols[c].panes[k] != root) k += 1; return k; } @@ -1068,10 +1043,10 @@ pub fn groupEnd(p: *const Pardes, c: usize, idx: usize) usize { /// it stands. Nothing moves. Top to bottom, so a nested attachment is /// judged after the one it hangs from. pub fn keepGroups(p: *Pardes) void { - for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]], 0..) |id, k| { + for (0..p.ncol) |c| for (p.cols[c].panes[0..p.cols[c].n], 0..) |id, k| { const pane = p.panes[id] orelse continue; if (pane.attached_to == null) continue; - const kept = if (ownerOf(p, id)) |owner| k > 0 and descends(p, p.col_panes[c][k - 1], owner) else false; + const kept = if (ownerOf(p, id)) |owner| k > 0 and descends(p, p.cols[c].panes[k - 1], owner) else false; if (kept) continue; pane.attached_to = null; }; @@ -1144,12 +1119,12 @@ pub fn giveBack(p: *Pardes, id: usize, gainer: usize, below: bool, rows: u16) bo /// ponytail: unfolding opens every attachment, one folded alone before /// included; remembering which were is a bit a pane. fn collapseGroup(p: *Pardes, c: usize, start: usize, end: usize) void { - const root = p.panes[p.col_panes[c][start]].?; + const root = p.panes[p.cols[c].panes[start]].?; const folding = !root.collapsed; snapColWeights(p, c); const neighbor = expandedNeighbor(p, c, start, .above) orelse expandedNeighbor(p, c, end - 1, .below); var spare: u16 = if (neighbor) |other| p.rects[other].h -| BOX_H else 0; - for (p.col_panes[c][start..end]) |k| { + for (p.cols[c].panes[start..end]) |k| { const pane = p.panes[k] orelse continue; if (folding) { if (pane.collapsed) continue; @@ -1217,9 +1192,9 @@ pub fn toggleCollapse(p: *Pardes, id: usize) void { /// would spread over the whole column instead. pub fn expandedNeighbor(p: *const Pardes, col: usize, index: usize, side: enum { above, below }) ?usize { var k = index; - while (if (side == .above) k > 0 else k + 1 < p.col_n[col]) { + while (if (side == .above) k > 0 else k + 1 < p.cols[col].n) { k = if (side == .above) k - 1 else k + 1; - const id = p.col_panes[col][k]; + const id = p.cols[col].panes[k]; if (p.panes[id]) |pane| if (!pane.collapsed) return id; } return null; @@ -1230,7 +1205,7 @@ fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usiz const available = p.screen_h -| y; var expanded_left: usize = 0; var weight: f32 = 0; - for (p.col_panes[c][0..p.col_n[c]]) |id| if (p.panes[id]) |pane| { + for (p.cols[c].panes[0..p.cols[c].n]) |id| if (p.panes[id]) |pane| { if (!pane.collapsed) { expanded_left += 1; weight += pane.vweight; @@ -1239,7 +1214,7 @@ fn computeCollapsedColumn(p: *Pardes, c: usize, x: u16, width: u16, folded: usiz const expanded_height = available -| @as(u16, @intCast(folded)); var budget = expanded_height; var folded_left = folded; - for (p.col_panes[c][0..p.col_n[c]]) |id| { + for (p.cols[c].panes[0..p.cols[c].n]) |id| { const pane = p.panes[id] orelse continue; const room = p.screen_h -| y; const height: u16 = if (pane.collapsed) blk: { @@ -1272,7 +1247,7 @@ pub fn compute(p: *Pardes) void { var wsum: u128 = 0; var last_plain: usize = p.ncol; for (0..p.ncol) |c| if (finder != c) { - wsum += p.col_weight[c]; + wsum += p.cols[c].weight; last_plain = c; }; if (wsum == 0) wsum = 1; @@ -1286,7 +1261,7 @@ pub fn compute(p: *Pardes) void { offset = finder_w; break :end x + finder_w; } else end: { - prefix += p.col_weight[c]; + prefix += p.cols[c].weight; break :end if (c == last_plain) offset + rest else offset + columnBoundary(rest, prefix, wsum); }; const cw = end -| x; @@ -1294,7 +1269,7 @@ pub fn compute(p: *Pardes) void { p.col_w[c] = cw; var folded: usize = 0; - for (p.col_panes[c][0..p.col_n[c]]) |id| if (p.panes[id]) |pane| { + for (p.cols[c].panes[0..p.cols[c].n]) |id| if (p.panes[id]) |pane| { if (pane.collapsed) folded += 1; }; if (folded > 0) { @@ -1303,8 +1278,8 @@ pub fn compute(p: *Pardes) void { } var vsum: f32 = 0; - for (0..p.col_n[c]) |k| { - if (p.panes[p.col_panes[c][k]]) |pane| vsum += pane.vweight; + for (0..p.cols[c].n) |k| { + if (p.panes[p.cols[c].panes[k]]) |pane| vsum += pane.vweight; } if (vsum <= 0) vsum = 1; @@ -1312,9 +1287,9 @@ pub fn compute(p: *Pardes) void { const top = y; const avail_h = p.screen_h -| y; var hs: [MAX_PANES]u16 = undefined; - const n = p.col_n[c]; + const n = p.cols[c].n; for (0..n) |k| { - const id = p.col_panes[c][k]; + const id = p.cols[c].panes[k]; const pane = p.panes[id] orelse { hs[k] = 0; continue; @@ -1328,7 +1303,7 @@ pub fn compute(p: *Pardes) void { keepTerminalFloors(p, c, hs[0..n]); y = top; for (0..n) |k| { - const id = p.col_panes[c][k]; + const id = p.cols[c].panes[k]; if (p.panes[id] == null) continue; p.rects[id] = .{ .x = x, .y = y, .w = cw, .h = hs[k] }; y +|= hs[k]; @@ -1350,13 +1325,13 @@ fn floorRows(p: *Pardes, id: usize) u16 { // ponytail: a row per step, O(panes x rows); a column holds few of both. fn keepTerminalFloors(p: *Pardes, c: usize, hs: []u16) void { for (hs, 0..) |*h, k| { - const floor = floorRows(p, p.col_panes[c][k]); + const floor = floorRows(p, p.cols[c].panes[k]); while (h.* < floor) { var giver: ?usize = null; var spare: u16 = 0; for (hs, 0..) |other, j| { if (j == k) continue; - const extra = other -| floorRows(p, p.col_panes[c][j]); + const extra = other -| floorRows(p, p.cols[c].panes[j]); if (extra > spare) { spare = extra; giver = j; @@ -1475,7 +1450,7 @@ test "collapse expansion is limited to space available in one neighbor" { // Text panes: a terminal would keep its tag and two rows (floorRows). for (1..4) |id| { p.newScratchBelow(0); - try std.testing.expectEqual(id, p.col_panes[0][id]); + try std.testing.expectEqual(id, p.cols[0].panes[id]); } compute(p); toggleCollapse(p, 2); @@ -1523,7 +1498,7 @@ test "collapse survives tiny resizes and TagBottom" { p.screen_h = @intCast(height); compute(p); var used: u16 = 0; - for (p.col_panes[0][0..p.col_n[0]]) |id| { + for (p.cols[0].panes[0..p.cols[0].n]) |id| { const rect = p.rects[id]; try std.testing.expect(rect.h <= p.screen_h -| rect.y); used += rect.h; @@ -1577,31 +1552,31 @@ test "column reorder moves only crossed state and preserves weights" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 173, .rows = 20 }); defer p.deinit(); p.ncol = 4; - p.col_n = @splat(0); for (0..4) |c| { - p.col_weight[c] = c * 13 + 7; - p.col_serial[c] = @intCast(c + 10); - p.col_panes[c][0] = c; + p.cols[c].n = 0; + p.cols[c].weight = c * 13 + 7; + p.cols[c].serial = @intCast(c + 10); + p.cols[c].panes[0] = c; p.col_tags[c].cur_col = @intCast(c + 20); } compute(p); - const original_weights = p.col_weight; + const original_weights = weightsOf(p); const outer_x = p.col_x[0]; const outer_w = p.col_w[0]; p.header_focus = true; p.header_column = 1; p.header_scroll = 9; reorderColumn(p, 1, 3); - try std.testing.expectEqual(original_weights[1], p.col_weight[3]); - try std.testing.expectEqual(original_weights[2], p.col_weight[1]); - try std.testing.expectEqual(@as(u32, 11), p.col_serial[3]); + try std.testing.expectEqual(original_weights[1], p.cols[3].weight); + try std.testing.expectEqual(original_weights[2], p.cols[1].weight); + try std.testing.expectEqual(@as(u32, 11), p.cols[3].serial); try std.testing.expectEqual(@as(?usize, 3), p.header_column); try std.testing.expectEqual(@as(i32, 21), tagline.focusedHeader(p).?.cur_col); try std.testing.expectEqual(@as(usize, 9), p.header_scroll); try std.testing.expectEqual(outer_x, p.col_x[0]); try std.testing.expectEqual(outer_w, p.col_w[0]); reorderColumn(p, 3, 1); - try std.testing.expectEqualSlices(u64, original_weights[0..4], p.col_weight[0..4]); + try std.testing.expectEqualSlices(u64, original_weights[0..4], weightsOf(p)[0..4]); try std.testing.expectEqual(@as(i32, 21), p.col_tags[1].cur_col); } @@ -1619,9 +1594,9 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, _ = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma\nalpha two\ndelta\nepsilon\nzeta\n"); p.newScratchBelow(0); p.newScratchBelow(0); - const other_col = p.col_panes[0][2]; + const other_col = p.cols[0].panes[2]; try std.testing.expect(splitColumn(p, other_col, other_col, false)); - const below = p.col_panes[0][1]; + const below = p.cols[0].panes[1]; p.active = 0; compute(p); const before = p.rects; @@ -1631,7 +1606,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, const s = try testAttachment(p); try std.testing.expect(attachFrom(p, 0, s, 9, 0)); try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, s)); - try std.testing.expectEqual(s, p.col_panes[0][1]); + try std.testing.expectEqual(s, p.cols[0].panes[1]); for (unrelated) |k| try std.testing.expectEqualDeep(before[k], p.rects[k]); try std.testing.expectEqual(before[0].h, p.rects[0].h + p.rects[s].h); try std.testing.expectEqual(before[0].y, p.rects[0].y); @@ -1639,7 +1614,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, // A second level (a preview under a query pane): out of the first's rows. const pv = try testAttachment(p); try std.testing.expect(attachFrom(p, s, pv, 4, s)); - try std.testing.expectEqual(pv, p.col_panes[0][2]); + try std.testing.expectEqual(pv, p.cols[0].panes[2]); try std.testing.expectEqual(@as(usize, 0), groupRoot(p, pv)); try std.testing.expectEqual(@as(usize, 3), groupEnd(p, 0, 0)); for (unrelated) |k| try std.testing.expectEqualDeep(before[k], p.rects[k]); @@ -1658,8 +1633,8 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, exec.runBuiltin(p, .New, 0, "", null); exec.runBuiltin(p, .New, s, "", null); var at = findPane(p, 0).?; - try std.testing.expectEqual(s, p.col_panes[at.col][at.idx + 1]); - try std.testing.expectEqual(pv, p.col_panes[at.col][at.idx + 2]); + try std.testing.expectEqual(s, p.cols[at.col].panes[at.idx + 1]); + try std.testing.expectEqual(pv, p.cols[at.col].panes[at.idx + 2]); // The seam between owner and attachment is the user's: the pair alone. compute(p); @@ -1667,7 +1642,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, applyRowSplit(p, at.col, at.idx, p.rects[s].y - 3); compute(p); try std.testing.expectEqual(pre_drag[0].h + pre_drag[s].h, p.rects[0].h + p.rects[s].h); - for (p.col_panes[at.col][0..p.col_n[at.col]]) |k| if (k != 0 and k != s) try std.testing.expectEqualDeep(pre_drag[k], p.rects[k]); + for (p.cols[at.col].panes[0..p.cols[at.col].n]) |k| if (k != 0 and k != s) try std.testing.expectEqualDeep(pre_drag[k], p.rects[k]); // Collapse folds the group and unfolds it. compute(p); @@ -1682,8 +1657,8 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, movePane(p, 0, p.col_x[1] + 4, p.rects[other_col].y + p.rects[other_col].h / 2); at = findPane(p, 0).?; try std.testing.expectEqual(@as(usize, 1), at.col); - try std.testing.expectEqual(s, p.col_panes[1][at.idx + 1]); - try std.testing.expectEqual(pv, p.col_panes[1][at.idx + 2]); + try std.testing.expectEqual(s, p.cols[1].panes[at.idx + 1]); + try std.testing.expectEqual(pv, p.cols[1].panes[at.idx + 2]); try std.testing.expectEqual(@as(?usize, 0), ownerOf(p, s)); // Del of the preview gives its rows to its owner, the query pane. @@ -1699,7 +1674,7 @@ test "an attachment takes its rows from its owner alone, keeps them, and moves, try std.testing.expect(p.panes[s] == null); compute(p); try std.testing.expectEqual(pair[0].h + pair[s].h, p.rects[0].h); - for (p.col_panes[1][0..p.col_n[1]]) |k| if (k != 0) try std.testing.expectEqualDeep(pair[k], p.rects[k]); + for (p.cols[1].panes[0..p.cols[1].n]) |k| if (k != 0) try std.testing.expectEqualDeep(pair[k], p.rects[k]); // Del of the owner closes what is attached to it. const again = try testAttachment(p); @@ -1824,9 +1799,9 @@ pub fn removeColumn(p: *Pardes, col: usize) !void { const beside = if (had_focus) besideColumn(p, col, if (p.header_focus) null else p.rects[p.active]) else null; var ids: [MAX_PANES]usize = undefined; var parents: [MAX_PANES]*Pane = undefined; - const count = p.col_n[col]; + const count = p.cols[col].n; for (0..count) |i| { - ids[i] = p.col_panes[col][i]; + ids[i] = p.cols[col].panes[i]; parents[i] = p.panes[ids[i]].?; } try panes.detachCwds(p, parents[0..count]); @@ -1851,7 +1826,7 @@ pub fn besideColumn(p: *const Pardes, col: usize, r: ?Rect) ?usize { const next = if (col > 0) col - 1 else col + 1; const mid = if (r) |at| at.y + at.h / 2 else p.screen_h / 2; var pick: ?usize = null; - for (p.col_panes[next][0..p.col_n[next]]) |k| { + for (p.cols[next].panes[0..p.cols[next].n]) |k| { if (p.panes[k] == null) continue; pick = k; if (p.rects[k].y +| p.rects[k].h > mid) break; @@ -1901,7 +1876,7 @@ pub fn reprojectTagHit(p: *const Pardes, tag_hit: TagHit) ?TagHit { const pane = p.panes[tag_hit.id] orelse return null; if (pane.serial != tag_hit.serial) return null; } - if (tag_hit.kind == .column and (tag_hit.id >= p.ncol or p.col_serial[tag_hit.id] != tag_hit.serial)) return null; + if (tag_hit.kind == .column and (tag_hit.id >= p.ncol or p.cols[tag_hit.id].serial != tag_hit.serial)) return null; return Layer.tagAgain(tag_hit); } @@ -1943,7 +1918,7 @@ test "a new column takes width only from the column that created it" { const coarse = try Pardes.init(std.testing.allocator, .{ .cols = 22, .rows = 10 }); defer coarse.deinit(); - coarse.col_weight[0] = 3; + coarse.cols[0].weight = 3; _ = try coarse.newShell(1, ""); try std.testing.expect(splitColumn(coarse, 0, 1, false)); coarse.sync(); @@ -1956,18 +1931,14 @@ test "a new column takes width only from the column that created it" { try std.testing.expect(splitColumn(extreme, 0, 1, false)); _ = try extreme.newShell(2, ""); insert(extreme, 0, 1, 2); - extreme.col_weight[0] = std.math.maxInt(u64) / 2 + 2; // odd and cannot double - extreme.col_weight[1] = 1; + extreme.cols[0].weight = std.math.maxInt(u64) / 2 + 2; // odd and cannot double + extreme.cols[1].weight = 1; compute(extreme); - const panes_before = extreme.col_panes; - const counts_before = extreme.col_n; - const weights_before = extreme.col_weight; + const cols_before = extreme.cols; const source_vweight = extreme.panes[0].?.vweight; const sibling_vweight = extreme.panes[2].?.vweight; try std.testing.expect(!splitColumn(extreme, 0, 0, false)); - try std.testing.expectEqual(panes_before, extreme.col_panes); - try std.testing.expectEqual(counts_before, extreme.col_n); - try std.testing.expectEqual(weights_before, extreme.col_weight); + try std.testing.expectEqual(cols_before, extreme.cols); try std.testing.expectEqual(source_vweight, extreme.panes[0].?.vweight); try std.testing.expectEqual(sibling_vweight, extreme.panes[2].?.vweight); } @@ -1981,8 +1952,8 @@ test "Newcol refuses an unsplittable restored weight before spawning" { try std.testing.expect(splitColumn(p, id - 1, id, false)); } const restored_cap = std.math.maxInt(u64) / 6; - for (0..4) |column| p.col_weight[column] = restored_cap; - p.col_weight[3] -= 1; + for (0..4) |column| p.cols[column].weight = restored_cap; + p.cols[3].weight -= 1; for ([_]usize{ 3, 2, 1 }) |id| { const pane = p.panes[id].?; try panes.deinitPane(p, pane); @@ -1992,8 +1963,8 @@ test "Newcol refuses an unsplittable restored weight before spawning" { } while (p.nextEffect()) |_| {} - try std.testing.expect(p.col_weight[0] > std.math.maxInt(u64) / 2); - try std.testing.expect(p.col_weight[0] % 2 == 1); + try std.testing.expect(p.cols[0].weight > std.math.maxInt(u64) / 2); + try std.testing.expect(p.cols[0].weight % 2 == 1); try std.testing.expect(!canSplitCol(p, findPane(p, 0).?.col)); const panes_before = p.panes; const serial_before = p.next_serial; @@ -2012,10 +1983,10 @@ test "repeated non-dyadic column splits preserve every unrelated boundary" { p.sync(); const handle = p.col_x[0] + p.col_w[0] - 1; - const untouched = p.col_weight; + const untouched = weightsOf(p); p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } }); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = TOPBAR_H + 1 } }); - try std.testing.expectEqual(untouched, p.col_weight); + try std.testing.expectEqual(untouched, weightsOf(p)); p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } }); p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 417, .row = TOPBAR_H + 1 } }); @@ -2043,22 +2014,22 @@ test "dragging a column's only pane to another leaves that column in place, empt newScratchIn(p, 0, activeColumn(p).?); const moved = p.active; p.sync(); - const weights = p.col_weight; - const tag_serial = p.col_serial[1]; + const weights = weightsOf(p); + const tag_serial = p.cols[1].serial; movePane(p, moved, p.col_x[0] + 4, p.rects[0].y + p.rects[0].h / 2); p.sync(); // acme's coldragwin: colclose then coladd (cols.c:516-517); the column // left behind keeps its place, width and tag. try std.testing.expectEqual(@as(usize, 2), p.ncol); - try std.testing.expectEqual(@as(usize, 0), p.col_n[1]); - try std.testing.expectEqual(tag_serial, p.col_serial[1]); - try std.testing.expectEqualDeep(weights, p.col_weight); - try std.testing.expectEqual(@as(usize, 2), p.col_n[0]); + try std.testing.expectEqual(@as(usize, 0), p.cols[1].n); + try std.testing.expectEqual(tag_serial, p.cols[1].serial); + try std.testing.expectEqualDeep(weights, weightsOf(p)); + try std.testing.expectEqual(@as(usize, 2), p.cols[0].n); // ...and a pane dragged into the empty column takes it whole. movePane(p, moved, p.col_x[1] + 4, p.screen_h / 2); p.sync(); - try std.testing.expectEqualSlices(usize, &.{moved}, p.col_panes[1][0..p.col_n[1]]); - try std.testing.expectEqual(@as(usize, 1), p.col_n[0]); + try std.testing.expectEqualSlices(usize, &.{moved}, p.cols[1].panes[0..p.cols[1].n]); + try std.testing.expectEqual(@as(usize, 1), p.cols[0].n); } test "tiny screens keep pane space before adding a column tag" { @@ -2068,3 +2039,10 @@ test "tiny screens keep pane space before adding a column tag" { try std.testing.expectEqual(TOPBAR_H, p.rects[0].y); _ = try p.render(p.scratch.allocator()); } + +/// Each column's weight, as a test compares them. +fn weightsOf(p: *const Pardes) [MAX_COLS]u64 { + var out: [MAX_COLS]u64 = undefined; + for (&out, p.cols) |*w, c| w.* = c.weight; + return out; +} |
