summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.zig54
1 files changed, 26 insertions, 28 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index ba0fa4fa..2c707e85 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -3008,7 +3008,7 @@ const StdinFeed = struct {
{
f.last_cols = ws.col;
f.last_rows = ws.row;
- f.applyResize(in, g, ws.col, ws.row);
+ applyResize(in, g, ws.col, ws.row);
out.n_events += 1;
}
@@ -3202,7 +3202,7 @@ const StdinFeed = struct {
}
},
.winsize => |vw| {
- f.applyResize(in, g, @intCast(vw.cols), @intCast(vw.rows));
+ applyResize(in, g, @intCast(vw.cols), @intCast(vw.rows));
out.n_events += 1;
},
.paste => |text| {
@@ -3216,8 +3216,7 @@ const StdinFeed = struct {
return out;
}
- fn applyResize(f: *StdinFeed, in: *Input, g: ?*Gui, cols: u16, rows: u16) void {
- _ = f;
+ fn applyResize(in: *Input, g: ?*Gui, cols: u16, rows: u16) void {
if (g) |gp| {
_ = c.SDL_SetWindowSize(gp.window, @intCast(cols * gp.cell_w), @intCast(rows * gp.cell_h));
_ = c.SDL_SyncWindow(gp.window);
@@ -3273,7 +3272,7 @@ fn setStdinRaw() !void {
try posix.tcsetattr(0, .NOW, term);
}
-fn dumpGrid(gpa: std.mem.Allocator, surface: *pardes.Surface) !void {
+fn dumpGrid(gpa: std.mem.Allocator, surface: *const pardes.Surface) !void {
if (surface.cols == 0 or surface.rows == 0) return;
const cur_x: u16 = if (surface.cursor) |cu| cu.x else 0;
const cur_y: u16 = if (surface.cursor) |cu| cu.y else 0;
@@ -3288,7 +3287,7 @@ fn dumpGrid(gpa: std.mem.Allocator, surface: *pardes.Surface) !void {
while (y < surface.rows) : (y += 1) {
var x: u16 = 0;
while (x < surface.cols) : (x += 1) {
- const grapheme = surface.at(x, y).grapheme();
+ const grapheme = surface.cells[@as(usize, y) * surface.cols + x].grapheme();
total = try std.math.add(usize, total, if (grapheme.len > 0) grapheme.len else 1);
}
}
@@ -3301,7 +3300,7 @@ fn dumpGrid(gpa: std.mem.Allocator, surface: *pardes.Surface) !void {
while (y < surface.rows) : (y += 1) {
var x: u16 = 0;
while (x < surface.cols) : (x += 1) {
- const grapheme = surface.at(x, y).grapheme();
+ const grapheme = surface.cells[@as(usize, y) * surface.cols + x].grapheme();
if (grapheme.len > 0) {
@memcpy(frame[at..][0..grapheme.len], grapheme);
at += grapheme.len;
@@ -4132,7 +4131,7 @@ const Shell = struct {
feed: StdinFeed = .{},
presented: bool = false,
skipped_presents: u8 = 0,
- surface: ?*pardes.Surface = null,
+ surface: ?*const pardes.Surface = null,
saw_event: bool = false,
dump_err: ?anyerror = null,
retired_shells: [pardes.MAX_PANES]RetiredShell = @splat(.{}),
@@ -4518,8 +4517,8 @@ const Shell = struct {
for (0..pardes.views.max) |i| {
const k: u8 = @intCast(i);
if (k != live and pardes.views.isOpen(s.core, k) and !pardes.views.isAway(s.core, k)) s.openAnotherWindow(k);
- s.windowed |= @as(u8, 1) << @intCast(live);
}
+ s.windowed |= @as(u8, 1) << @intCast(live);
s.core.toView(live);
s.follow();
}
@@ -5135,7 +5134,7 @@ fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void {
s.follow();
const g = s.gui orelse return;
frame_started_ns = monoNs();
- const frame = @constCast(surface);
+ const frame = surface;
s.surface = frame;
g.frame_arrival_ns = monoNs();
const scene_requested = g.post.ready();
@@ -5211,7 +5210,7 @@ fn gridPresent(ctx: ?*anyopaque, surface: *const pardes.Surface) void {
s.presented = s.saw_event;
s.saw_event = false;
if (!s.presented) return;
- dumpGrid(s.gpa, @constCast(surface)) catch |err| {
+ dumpGrid(s.gpa, surface) catch |err| {
s.dump_err = err;
s.presented = false;
};
@@ -5809,7 +5808,7 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
/// The glide's picture: the pane's body rows moved by the offset, and in
/// the gap it opens the rows that left, as `emitScrollRows` draws a
/// touchpad's fraction.
-fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 {
+fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 {
const glide = &g.glide;
for (surface.panelTracks()) |track|
if (track.active() and track.pane == glide.pane) return 0;
@@ -5841,7 +5840,7 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde
while (col < x0 + bw) : (col += 1) {
// No caret among the moving rows: it is drawn from its own
// springs (the quad), never carried by the text's glide.
- emitInstance(g, instances, base + n, col, row, shifted, win_w, win_h, null, cellFontRole(surface.at(col, row)), line, col, row_cursor, false, false, page);
+ emitInstance(g, instances, base + n, col, row, shifted, win_w, win_h, null, cellFontRole(&line[col]), line, col, row_cursor, false, false, page);
n += 1;
}
}
@@ -6238,7 +6237,7 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
if (g.scroll_lag == 0) resetScroll(g);
}
-fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 {
+fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 {
g.scroll_held_px = 0;
if (g.glide.follow.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page, held);
const scroll_pane = g.scroll_pane orelse return 0;
@@ -6266,7 +6265,7 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pard
var col = x0;
while (col < x0 + bw) : (col += 1) {
const sidx: u32 = @as(u32, row) * surface.cols + col;
- emitInstance(g, instances, base + n, col, row, shifted, win_w, win_h, null, cellFontRole(surface.at(col, row)), line, col, row_cursor, false, sidx == cursor_idx and !cursor_bar, page);
+ emitInstance(g, instances, base + n, col, row, shifted, win_w, win_h, null, cellFontRole(&line[col]), line, col, row_cursor, false, sidx == cursor_idx and !cursor_bar, page);
n += 1;
}
}
@@ -6440,13 +6439,13 @@ fn validImageBytes(place: pardes.ImagePlace) ?u32 {
const NativeBounds = struct { w: u32, h: u32 };
-fn nativeBounds(g: *const Gui, place: anytype) ?NativeBounds {
+fn nativeBounds(g: *const Gui, place: SavedImagePlace) ?NativeBounds {
const bound_w = std.math.mul(u32, place.w, g.cell_w) catch return null;
const bound_h = std.math.mul(u32, place.h, g.cell_h) catch return null;
return .{ .w = bound_w, .h = bound_h };
}
-fn nativePlaceGeometry(g: *const Gui, place: anytype) ?pardes.image.NativeGeometry {
+fn nativePlaceGeometry(g: *const Gui, place: SavedImagePlace) ?pardes.image.NativeGeometry {
if (comptime pardes.pdf_enabled) {
if (place.native.geometry) |geometry| return geometry;
const bounds = nativeBounds(g, place) orelse return null;
@@ -6463,7 +6462,7 @@ fn nativePlaceGeometry(g: *const Gui, place: anytype) ?pardes.image.NativeGeomet
return null;
}
-fn nativePlaceDrawable(g: *const Gui, place: anytype) bool {
+fn nativePlaceDrawable(g: *const Gui, place: SavedImagePlace) bool {
if (comptime pardes.pdf_enabled) return nativePlaceGeometry(g, place) != null;
const bounds = nativeBounds(g, place) orelse return false;
return pardes.image.containGeometry(place.iw, place.ih, bounds.w, bounds.h) != null;
@@ -6632,7 +6631,7 @@ fn prepareNativeImages(
g: *Gui,
gpa: std.mem.Allocator,
cmd: *c.SDL_GPUCommandBuffer,
- surface: *pardes.Surface,
+ surface: *const pardes.Surface,
groups: *Groups,
sw: u32,
sh: u32,
@@ -6765,7 +6764,7 @@ fn panelBoxScissor(g: *const Gui, box: pardes.animation.Box, max_w: u32, max_h:
fn drawNativeImagesGpu(
g: *Gui,
rp: ?*c.SDL_GPURenderPass,
- surface: *pardes.Surface,
+ surface: *const pardes.Surface,
batch: Group,
whole: c.SDL_Rect,
) void {
@@ -6796,8 +6795,8 @@ fn drawNativeImagesGpu(
fn renderFrame(
g: *Gui,
gpa: std.mem.Allocator,
- core: ?*const pardes.Pardes,
- surface: *pardes.Surface,
+ core: ?*pardes.Pardes,
+ surface: *const pardes.Surface,
debug_on: bool,
) !bool {
if (surface.pointer_shape != g.pointer_shape) {
@@ -6891,7 +6890,7 @@ fn renderFrame(
g.cursor_quad_alpha = if (quad_mode) chrome.cursor_alpha * blink_alpha else 0;
// The probe's view of this frame's motion (FrameStats.Frame).
if (core) |p| {
- const probe = &@constCast(p).frames;
+ const probe = &p.frames;
// A focused PDF's strip is the core's (pdf_view.draw).
const pdf_focus = if (p.panes[p.active]) |pane| pane.hasPdf() else false;
if (!pdf_focus) probe.scroll = g.glide.follow.offset;
@@ -7661,8 +7660,7 @@ fn scrollColumn(g: *const Gui, chrome: *const pardes.Chrome, col: u16, layout: C
/// acme's button for the grip whose first cell is (col, row), in window
/// pixels: the scroll column wide, its tag row tall, from the rule above to
/// the rule below, so button and scrollbar read as one strip.
-fn gripButton(g: *const Gui, chrome: *const pardes.Chrome, col: u16, row: u16, layout: CellLayout, win_h: f32) [4]f32 {
- _ = win_h;
+fn gripButton(g: *const Gui, chrome: *const pardes.Chrome, col: u16, row: u16, layout: CellLayout) [4]f32 {
const x = scrollColumn(g, chrome, col, layout);
const y0 = @round(@as(f32, @floatFromInt(row)) * layout.h);
return .{ x[0], y0, x[1], @round(@as(f32, @floatFromInt(row + 1)) * layout.h) };
@@ -7766,7 +7764,7 @@ fn emitSurfaceCell(
// A grip is acme's button: its fill is this cell's ground, cut to
// the button (and a dirty one's inset a pixel inside its ring, so
// the ring reads round it), its glyph centered in it.
- const button = if (here.grip and here.grip_top) gripButton(g, chrome, col - @min(here.grip_offset, @as(u16, @intCast(at))), row, body_layout, win_h) else null;
+ const button = if (here.grip and here.grip_top) gripButton(g, chrome, col - @min(here.grip_offset, @as(u16, @intCast(at))), row, body_layout) else null;
if (grip) {
// A grip is one glyph centered across the gutter, not text: it is
// looked up by its codepoint's glyph, never shaped.
@@ -7912,7 +7910,7 @@ test "every pixel of a grip column is band, button or ring, and the button sits
if (!bottom) for (pixels[(h_px - 1) * w_px ..][0..w_px]) |pixel|
try std.testing.expectEqual(rgb(chrome.tag_rule orelse mixRgb(chrome.tag_bg, chrome.page orelse bg_default)), pixel.?);
// The button's edges are the scrollbar's.
- const button = gripButton(&g, chrome, grip.rect.x, grip.rect.y, layout, win_h);
+ const button = gripButton(&g, chrome, grip.rect.x, grip.rect.y, layout);
const column = scrollColumn(&g, chrome, s.region(.rail, 0).?.rect.x, layout);
try std.testing.expectEqual(column[0], button[0]);
try std.testing.expectEqual(column[1], button[2]);
@@ -10498,7 +10496,7 @@ fn gripDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ce
for (regions) |grip| {
if ((grip.kind != .grip and grip.kind != .column_grip) or groupOf(groups, grip.serial) != index) continue;
if (grip.rect.h == 0 or grip.rect.y >= rows) continue;
- const button = gripButton(g, chrome, grip.rect.x, grip.rect.y, layout, win_h);
+ const button = gripButton(g, chrome, grip.rect.x, grip.rect.y, layout);
// Round the button, its first row is the tag's band: nothing of the
// cells under it shows there.
const band = if (grip.active) chrome.tag_focus_bg else chrome.tag_bg;