diff options
Diffstat (limited to 'dev/gui')
| -rw-r--r-- | dev/gui/gui.zig | 123 |
1 files changed, 52 insertions, 71 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index b569e7f2..b353e14b 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -192,27 +192,27 @@ const PreparedImage = struct { texture: *c.SDL_GPUTexture, }; -fn updateCoreResize(core: *pardes.Pardes, cols: u16, rows: u16, cell_w: u32, cell_h: u32, tag_w: u32, tag_h: u32) bool { - core.update(resizeOf(core.view(), cols, rows, cell_w, cell_h, tag_w, tag_h) orelse return false); - return true; +/// The window's size as its view takes it (Event.resize): its whole +/// cells, their pixels, its rows' metrics. Posted to its own view when it +/// changes, compared with what the window last posted or that view is, +/// never with a frame or the live view. +const Size = @FieldType(pardes.Event, "resize"); + +fn windowSize(g: *const Gui) Size { + var pw: c_int = 0; + var ph: c_int = 0; + _ = c.SDL_GetWindowSizeInPixels(g.window, &pw, &ph); + return .{ + .cols = @intCast(@max(1, @divTrunc(@as(u32, @intCast(@max(pw, 1))), g.cell_w))), + .rows = @intCast(@max(1, @divTrunc(@as(u32, @intCast(@max(ph, 1))), g.cell_h))), + .cell_pixels = .{ .w = @intCast(@min(@max(1, g.cell_w), std.math.maxInt(u16))), .h = @intCast(@min(@max(1, g.cell_h), std.math.maxInt(u16))) }, + .row_metrics = .{ .body_w = @intCast(g.cell_w), .body_h = @intCast(g.cell_h), .tagline_w = @intCast(g.tagline_width), .tagline_h = @intCast(g.tagline_height) }, + }; } -/// The resize a window of `cols` by `rows` cells of these sizes is to the -/// live view (a View, or the Facts a frame carries of it), or null when it -/// is that already. -fn resizeOf(v: anytype, cols: u16, rows: u16, cell_w: u32, cell_h: u32, tag_w: u32, tag_h: u32) ?pardes.Event { - const metrics: pardes.RowMetrics = .{ .body_w = @intCast(cell_w), .body_h = @intCast(cell_h), .tagline_w = @intCast(tag_w), .tagline_h = @intCast(tag_h) }; - const same_metrics = std.meta.eql(metrics, v.row_metrics); - const cell_px_w: u16 = @intCast(@min(@max(1, cell_w), std.math.maxInt(u16))); - const cell_px_h: u16 = @intCast(@min(@max(1, cell_h), std.math.maxInt(u16))); - if (cols == v.screen_w and rows == v.screen_h and - cell_px_w == v.cell_pixels.w and cell_px_h == v.cell_pixels.h and same_metrics) return null; - return .{ .resize = .{ - .cols = cols, - .rows = rows, - .cell_pixels = .{ .w = cell_px_w, .h = cell_px_h }, - .row_metrics = metrics, - } }; +/// Whether view `v` is `size` already. +fn sizedTo(v: *const pardes.Pardes.View, size: Size) bool { + return v.screen_w == size.cols and v.screen_h == size.rows and std.meta.eql(v.cell_pixels, size.cell_pixels) and std.meta.eql(v.row_metrics, size.row_metrics.?); } const TouchPoint = struct { @@ -580,7 +580,7 @@ fn syncReplicaFont(g: *Gui, f: *const @FieldType(pardes.config.Settings, "font") if (f.requested_size_hundredths != 0) g.px = @as(f32, @floatFromInt(f.requested_size_hundredths)) / 100; setGuiFontName(g, face.name); - refitFont(g, null); + refitFont(g); return true; } @@ -624,18 +624,6 @@ fn windowGeometry(window: *c.SDL_Window) WindowGeometry { }; } -const GridCells = struct { cols: u16, rows: u16 }; - -fn windowCells(g: *const Gui) GridCells { - var pw: c_int = 0; - var ph: c_int = 0; - _ = c.SDL_GetWindowSizeInPixels(g.window, &pw, &ph); - return .{ - .cols = @intCast(@max(1, @divTrunc(@as(u32, @intCast(@max(pw, 1))), g.cell_w))), - .rows = @intCast(@max(1, @divTrunc(@as(u32, @intCast(@max(ph, 1))), g.cell_h))), - }; -} - const Point = struct { x: f32, y: f32 }; fn windowPointToPixels(geometry: WindowGeometry, x: f32, y: f32) Point { @@ -1019,7 +1007,7 @@ const Own = struct { core.view().frontend.native_images = true; core.view().frontend.native_image_patches = true; observeGuiFont(g, core); - syncTaglineFont(g, core); + _ = fitTaglineFont(g, core.settings.font.tagline_percent); l.inbox.wake_fn = sdlWake; o.shell = .{ .core = core, @@ -1093,7 +1081,7 @@ const Own = struct { o.shell.core = l.core; o.shell.surface = null; observeGuiFont(o.g, l.core); - syncTaglineFont(o.g, l.core); + _ = fitTaglineFont(o.g, l.core.settings.font.tagline_percent); } }; @@ -1118,10 +1106,11 @@ const Client = struct { inbox: std.ArrayListUnmanaged(replica.Said) = .empty, taken: std.ArrayListUnmanaged(replica.Said) = .empty, link_ended: bool = false, - /// The size the window last posted while its view is not that size - /// yet (the session has not taken it, or speculation stopped at it): - /// posted once, not again each pass while it waits. - posted: ?@FieldType(pardes.Event, "resize") = null, + /// The size the window last posted (windowSize): posted again only + /// when the window's own size changes. Never by what a frame shows: a + /// frame is its view as the session had it then, and a rollback's drew + /// an older size (each was posted again, 2026-11-24). + posted: ?Size = null, /// The window, the shell its frames are drawn through, the input it /// routes (its core this join's), and the client's joins. g: *Gui = undefined, @@ -1227,11 +1216,11 @@ const Client = struct { } if (scrollRows(g, &cl.in, gpa)) link.dirty = true; if (fitTaglineFont(g, g.facts.tagline_percent)) link.dirty = true; - const geom = windowCells(g); - if (resizeOf(&g.facts, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height)) |ev| { - if (cl.posted == null or !std.meta.eql(cl.posted.?, ev.resize)) cl.in.post(ev); - cl.posted = ev.resize; - } else cl.posted = null; + const size = windowSize(g); + if (cl.posted == null or !std.meta.eql(cl.posted.?, size)) { + cl.in.post(.{ .resize = size }); + cl.posted = size; + } if (cl.drew) refreshPresentedPointer(g, &cl.in); cl.drew = false; runDemo(g, &cl.in, cl.in.core); @@ -2244,13 +2233,8 @@ const WheelTurn = struct { x: f32 = 0, y: f32 = 0, integer_y: i32 = 0, precise: fn setFontPx(g: *Gui, in: *Input, want: f32) void { if (want == g.px) return; g.px = want; - if (in.client) |r| { - refitFont(g, null); - r.loop.link.dirty = true; - } else { - refitFont(g, in.core); - observeGuiFont(g, in.core); - } + refitFont(g); + if (in.client) |r| r.loop.link.dirty = true else observeGuiFont(g, in.core); } /// A Mac trackpad's gesture, decoded by macos_trackpad.m (Trackpad.zig's @@ -2859,17 +2843,15 @@ fn pollFrame(ctx: ?*anyopaque) void { return; }; // A replica client's view live: the window's own view back before what - // the window does to it (its size, its scroll, its font). + // the window does to it (its scroll, its font). if (core.live != s.gview) { - const geom = windowCells(g); const due = g.scroll_pane != null or g.scroll_notch != 0 or g.glide.moving() or - core.settings.font.tagline_percent != g.tagline_percent or core.settings.font.pending or - (if (core.views[s.gview]) |*own| resizeOf(own, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height) != null else false); + core.settings.font.tagline_percent != g.tagline_percent or core.settings.font.pending; if (due) _ = s.windowView(); } syncWindowOpacity(g, core); frame_probe.?.period_ns = refreshNs(g); - syncTaglineFont(g, core); + _ = fitTaglineFont(g, core.settings.font.tagline_percent); if (core.takeFontRequest()) |path| blk: { const bytes = filesystem.readFile(&pardes.tape.none, s.gpa, path) catch { core.rejectFont(); @@ -2883,11 +2865,22 @@ fn pollFrame(ctx: ?*anyopaque) void { if (core.settings.font.requested_size_hundredths != 0) g.px = @as(f32, @floatFromInt(core.settings.font.requested_size_hundredths)) / 100; setGuiFontName(g, core.settings.font.requested_name.get()); - refitFont(g, core); + refitFont(g); acknowledgeGuiFont(g, core); } - const geom = windowCells(g); - if (updateCoreResize(core, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height)) resetScroll(g); + // The window's size is its own view's, compared with that view and + // posted to it as the window's input (Input.post makes it live): never + // compared with the live view, which a client's input leaves live + // (2026-11-24: sized to this window, that client posted its own size + // again and this window its own, a unit and a rollback each way, on + // and on after a drag ended, the client drawing its view at this + // window's size, cut). A font's new cells come here too. + const size = windowSize(g); + if (core.views[s.gview]) |*own| if (!sizedTo(own, size)) { + var in: Input = .{ .core = core, .shell = s }; + in.post(.{ .resize = size }); + resetScroll(g); + }; stepScroll(g, core, s.gpa); if (s.test_mode) writeTestStatus(g, core, s.presented, core.needs_frame); // A blink edge, or the window's own motion (its glide, its caret, a @@ -4522,7 +4515,7 @@ fn firstCp(s: []const u8) u32 { return std.unicode.utf8Decode(s[0..n]) catch ' '; } -fn refitFont(g: *Gui, core: ?*pardes.Pardes) void { +fn refitFont(g: *Gui) void { var cw: c_int = 10; var chh: c_int = 20; var asc: c_int = 16; @@ -4537,12 +4530,6 @@ fn refitFont(g: *Gui, core: ?*pardes.Pardes) void { g.tagline_height = tagline.height; resetGlyphAtlas(g); - - if (core) |p| { - const geom = windowCells(g); - _ = updateCoreResize(p, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height); - } - resetScroll(g); } @@ -4552,12 +4539,6 @@ fn resetGlyphAtlas(g: *Gui) void { g.words.clear(); } -fn syncTaglineFont(g: *Gui, core: *pardes.Pardes) void { - if (!fitTaglineFont(g, core.settings.font.tagline_percent)) return; - const geom = windowCells(g); - _ = updateCoreResize(core, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height); -} - /// The tagline's face at `percent` of the body's: whether it changed. fn fitTaglineFont(g: *Gui, percent: u8) bool { if (percent == g.tagline_percent) return false; |
