1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
//! All pane and minimap geometry is in font-sized canvas units.
const std = @import("std");
const Rect = @import("sketch").Rect;
const Geometry = @This();
pub const toolbar_count = 17;
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((toolbar_count + 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, ®s, &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);
}
pub fn scaled(r: Rect, scale: f32) Rect {
return .{ .x = r.x * scale, .y = r.y * scale, .w = r.w * scale, .h = r.h * scale };
}
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);
}
}
}
|