summaryrefslogtreecommitdiff
path: root/gui/src/Geometry.zig
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src/Geometry.zig')
-rw-r--r--gui/src/Geometry.zig57
1 files changed, 57 insertions, 0 deletions
diff --git a/gui/src/Geometry.zig b/gui/src/Geometry.zig
new file mode 100644
index 0000000..3ebdf4e
--- /dev/null
+++ b/gui/src/Geometry.zig
@@ -0,0 +1,57 @@
+//! All pane and minimap geometry is in font-sized canvas units.
+const std = @import("std");
+const Rect = @import("sketch").Rect;
+const Geometry = @This();
+w: f32,
+h: f32,
+content: f32,
+top: f32,
+columns: usize,
+panes: [3]Rect,
+registers: Rect,
+
+pub fn init(w: f32, h: f32, scroll: f32) Geometry {
+ const margin: f32 = 24;
+ const gap: f32 = 16;
+ const room = @max(240, w - 2 * margin);
+ const columns: usize = @intFromFloat(@max(1, @floor((w - 48) / 42)));
+ const top: f32 = 78 + @as(f32, @floatFromInt((16 + columns - 1) / columns)) * 34;
+ const tall = @max(320, (h - top - 64) * 0.64);
+ const bottom = @max(240, h - top - tall - gap - 48);
+ var code: Rect = .{ .x = margin, .y = top, .w = room, .h = tall };
+ var regs: Rect = .{ .x = margin, .y = top + tall + gap, .w = room, .h = 320 };
+ if (w >= 1500) {
+ regs = .{ .x = margin + room * 0.72 + gap, .y = top, .w = room * 0.28 - gap, .h = tall };
+ code.w = room * 0.72;
+ }
+ const y = @max(code.y + code.h, regs.y + regs.h) + gap;
+ var stack: Rect = .{ .x = margin, .y = y, .w = room, .h = bottom };
+ var mem: Rect = .{ .x = margin, .y = y + bottom + gap, .w = room, .h = bottom };
+ if (w >= 1500) {
+ stack.w = (room - gap) / 2;
+ mem = .{ .x = margin + stack.w + gap, .y = y, .w = stack.w, .h = bottom };
+ }
+ const content = mem.y + mem.h + 48;
+ for ([_]*Rect{ &code, &regs, &stack, &mem }) |r| r.y -= std.math.clamp(scroll, 0, @max(0, content - h));
+ return .{ .w = w, .h = h, .content = content, .top = top, .columns = columns, .panes = .{ code, stack, mem }, .registers = regs };
+}
+pub fn visible(r: Rect) f32 {
+ return @max(1, @floor((r.h - 40) / 24));
+}
+pub fn mini(r: Rect) Rect {
+ return .{ .x = r.w - 52, .y = 32, .w = 46, .h = r.h - 40 };
+}
+pub fn seam(r: Rect) f32 {
+ return @min(536, r.w * 0.34);
+}
+
+test "wide panes sit beside each other; narrow panes stack without overlap at every font scale" {
+ for ([_][2]f32{ .{ 2240, 1260 }, .{ 1440, 900 }, .{ 800, 700 } }) |size| {
+ for ([_]f32{ 0.6, 1, 2 }) |scale| {
+ const g = init(size[0] / scale, size[1] / scale, 0);
+ for (g.panes) |p| try std.testing.expect(p.w > 0 and p.h > 0 and p.x + p.w <= g.w);
+ try std.testing.expect(g.registers.x >= g.panes[0].x + g.panes[0].w or g.registers.y >= g.panes[0].y + g.panes[0].h);
+ try std.testing.expect(g.panes[2].x >= g.panes[1].x + g.panes[1].w or g.panes[2].y >= g.panes[1].y + g.panes[1].h);
+ }
+ }
+}