diff options
Diffstat (limited to 'dev/gui')
| -rw-r--r-- | dev/gui/gui.zig | 295 |
1 files changed, 157 insertions, 138 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 0f1fe0e6..bc831a69 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 { @@ -372,6 +372,22 @@ fn emitTouchClick(g: *const Gui, in: *Input, point: TouchNormPoint, button: pard const Queue = host_io.Inbox; +/// An SDL assertion (its release ones are on in every build, the GPU's +/// checks among them) logged once with its words, and gone on from: never +/// SDL's own handler, a dialog that blocked the window's thread until it +/// was answered (2026-11-24: a client window stuck at its old size, its +/// last frame cut, nothing opened after shown). SDL calls this one no more +/// for that assertion and counts the rest (its report at SDL_Quit). Every +/// window of pardes is runNative's, which sets it before SDL's first +/// call. A test build fails at one. +fn sdlAssertion(data: [*c]const c.SDL_AssertData, _: ?*anyopaque) callconv(.c) c.SDL_AssertState { + const d = data.*; + const words = .{ d.condition, d.filename, d.linenum, d.function }; + if (builtin.is_test) std.debug.panic("SDL assertion: {s} at {s}:{d} ({s})", words); + log.err("SDL assertion: {s} at {s}:{d} ({s}); ignored, from now on", words); + return c.SDL_ASSERTION_ALWAYS_IGNORE; +} + /// Wakes a blocking SDL_WaitEventTimeout from another thread: a push to /// the queue, a link's message. fn sdlWake(_: ?*anyopaque) void { @@ -580,7 +596,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 +640,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 { @@ -774,6 +778,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di log.err("SDL_SetMemoryFunctions: {s}", .{c.SDL_GetError()}); return error.SdlInit; } + c.SDL_SetAssertionHandler(sdlAssertion, null); _ = c.SDL_SetHint("SDL_JOYSTICK_HIDAPI", "1"); // SDL_HINT_JOYSTICK_HIDAPI _ = c.SDL_SetHint("SDL_JOYSTICK_HIDAPI_STEAMDECK", "1"); // ..._STEAMDECK if (comptime builtin.os.tag == .macos) _ = c.SDL_SetHint(c.SDL_HINT_MAC_SCROLL_MOMENTUM, "1"); @@ -1019,7 +1024,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 +1098,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 +1123,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, @@ -1159,9 +1165,11 @@ const Client = struct { cl.pending.append(cl.gpa, e) catch {}; } - /// What the window's input made, applied at once and sent; what the - /// window reads beside its frame (Gui.facts) as its view is now. + /// What the window's input made, its last motion with it (Input.moved), + /// applied at once and sent; what the window reads beside its frame + /// (Gui.facts) as its view is now. fn feed(cl: *Client, l: *ClientLoop) void { + cl.in.flush(); const r = l.link.r; for (cl.pending.items) |ev| { const predicted = r.echo.stats.predicted; @@ -1225,11 +1233,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); @@ -1287,8 +1295,9 @@ const Client = struct { return ms; } - /// SDL's wait: each event dispatched and fed; then what the reader - /// took, the window's own pictures' draws done. + /// SDL's wait: each event dispatched and fed (a run of motions one + /// input, Input.moved); then what the reader took, the window's own + /// pictures' draws done. pub fn wait(cl: *Client, l: *ClientLoop, ms: u32) void { const g = cl.g; const link = &l.link; @@ -1301,11 +1310,14 @@ const Client = struct { while (got) : (got = c.SDL_PollEvent(&sev)) { if (sev.type == c.SDL_EVENT_USER) continue; dispatch(g, &cl.in, &sev); - cl.feed(l); + // Fed as it comes, the next event's hits read in the frame it + // predicts; a motion goes with the next input, or the pass's. + if (cl.in.moved == null) cl.feed(l); if (cl.in.redraw) link.dirty = true; cl.in.redraw = false; if (link.quit) break; } + cl.feed(l); cl.takeSaid(l); // Its draws done (api.draw: this window's own pictures). if (cl.shell.takeDraws()) link.dirty = true; @@ -1530,6 +1542,9 @@ const StdinFeed = struct { // window pixels, built as SDL would and run through dispatch, // so a driver exercises the real pointer path (pixel to cell, // tag and body hits). SGR mouse carries only cells. + // mouse;pointer;<SDL button, 0 for none>;<x>;<y>: a motion as + // `motion` builds it, pushed onto SDL's queue as a mouse's + // comes, for the window's wait to take with the rest. // finger;<kind>;<id>;<x>;<y>;<pressure> // close: the window's close button // One the read cut short, or what may yet begin one, waits for @@ -1558,7 +1573,7 @@ const StdinFeed = struct { // counts them: shift 4, meta (alt) 8, ctrl 16. const held = std.fmt.parseInt(u8, parts.next() orelse "0", 10) catch 0; var sev = std.mem.zeroes(c.SDL_Event); - const k = std.meta.stringToEnum(enum { wheel, focus, motion, down, up }, kind) orelse .up; + const k = std.meta.stringToEnum(enum { wheel, focus, motion, pointer, down, up }, kind) orelse .up; switch (k) { .wheel => { // ESC]777;mouse;wheel;<y, SDL's sign: up positive>;<x>;<y>BEL: @@ -1572,7 +1587,7 @@ const StdinFeed = struct { }, // ESC]777;mouse;focus;<1 gained, 0 lost>;0;0BEL .focus => sev.type = if (button != 0) c.SDL_EVENT_WINDOW_FOCUS_GAINED else c.SDL_EVENT_WINDOW_FOCUS_LOST, - .motion => { + .motion, .pointer => { sev.type = c.SDL_EVENT_MOUSE_MOTION; sev.motion.x = x; sev.motion.y = y; @@ -1586,6 +1601,11 @@ const StdinFeed = struct { sev.button.y = y; }, } + if (k == .pointer) { + sev.motion.windowID = c.SDL_GetWindowID(gp.window); + _ = c.SDL_PushEvent(&sev); + continue; + } const before = c.SDL_GetModState(); var mods: c.SDL_Keymod = 0; if (held & 4 != 0) mods |= c.SDL_KMOD_LSHIFT; @@ -1756,8 +1776,27 @@ const Input = struct { /// Something the window draws of its own changed (a display's scale, a /// touchpad's fraction): the runner draws again. redraw: bool = false, + /// The pointer's last motion `dispatch` took, not posted yet: a run of + /// motions is one input, its last, posted before whatever input comes + /// next or at the pass's end (`flush`). The core reads only a motion's + /// cell and held button; posted each, every one was a step of the + /// session, and with clients a unit to each and a frame of each (1652 + /// motions in 0.35 s were 1655 frames of the session, 2026-11-24). + moved: ?pardes.Mouse = null, fn post(in: *Input, ev: pardes.Event) void { + in.flush(); + in.send(ev); + } + + /// The pass's last motion (`moved`) posted. + fn flush(in: *Input) void { + const m = in.moved orelse return; + in.moved = null; + in.send(.{ .mouse = m }); + } + + fn send(in: *Input, ev: pardes.Event) void { // A replica client's: fed after the event (Client.feed). if (in.client) |cl| return cl.post(ev); const g = if (in.shell) |s| s.gui else null; @@ -1908,7 +1947,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { else physical_held; const mc = pointAt(g, m.x, m.y); - in.post(.{ .mouse = pointerMouse(held orelse .none, if (held != null) .drag else .motion, mc, pointerMods()) }); + in.moved = pointerMouse(held orelse .none, if (held != null) .drag else .motion, mc, pointerMods()); }, c.SDL_EVENT_MOUSE_WHEEL => { const w = sev.wheel; @@ -2210,13 +2249,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 @@ -2422,14 +2456,14 @@ const Shell = struct { /// of their own with no window here; the session loop's /// (runtime/session.zig), a client's none. peers: *replica.Peers, - /// This wait took only a replica's post (its input, its join): the pump - /// after it reads no new time, so it moves nothing the replicas' - /// speculations stand on (tui.zig's `mail_only`). + /// This wait took nothing but a replica's post, if one (its input, its + /// join): the pump after one reads no new time (Peers.heldNow). mail_only: bool = false, waited: bool = false, /// With replica clients, a wait takes one person's input (tui.zig - /// `split`): the next is held for the next wait. - took_input: bool = false, + /// `split`), the type of its first event here: the next is held for + /// the next wait. + took: ?u32 = null, held: ?c.SDL_Event = null, fn host(s: *Shell) pardes.Host { @@ -2462,6 +2496,17 @@ const Shell = struct { return true; } + /// The window's events from `sev` on, SDL's queue after it, made inputs + /// (`dispatch`: a run of motions one, Input.moved) until the queue is + /// empty or one is held for the next wait (`split`). + fn takeEvents(s: *Shell, g: *Gui, in: *Input, sev: *c.SDL_Event) void { + while (!s.split(sev)) { + _ = s.windowView(); + dispatch(g, in, sev); + if (!c.SDL_PollEvent(sev)) break; + } + } + /// With replica clients, a wait takes one person's input and its pump /// makes one unit of it (tui.zig `split`): whether `sev`, a second, is /// held for the next wait. Any event but a wake is no replica's post. @@ -2473,11 +2518,13 @@ const Shell = struct { c.SDL_EVENT_KEY_DOWN, c.SDL_EVENT_TEXT_INPUT, c.SDL_EVENT_MOUSE_BUTTON_DOWN, c.SDL_EVENT_MOUSE_BUTTON_UP, c.SDL_EVENT_MOUSE_MOTION, c.SDL_EVENT_MOUSE_WHEEL, c.SDL_EVENT_WINDOW_FOCUS_GAINED, c.SDL_EVENT_WINDOW_FOCUS_LOST, c.SDL_EVENT_WINDOW_MOUSE_LEAVE, c.SDL_EVENT_FINGER_DOWN, c.SDL_EVENT_FINGER_MOTION, c.SDL_EVENT_FINGER_UP => {}, else => return false, }; - if (s.took_input) { + if (s.took) |took| { + // A run of motions is one input, its last (Input.moved). + if (took == c.SDL_EVENT_MOUSE_MOTION and sev.type == took) return false; s.held = sev.*; return true; } - s.took_input = true; + s.took = sev.type; return false; } @@ -2649,7 +2696,7 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { const core = s.core; var in: Input = .{ .core = core, .shell = s }; s.mail_only = true; - s.took_input = false; + s.took = null; defer s.waited = true; if (s.gui) |g| { if (s.surface != null) startGamepads(g); @@ -2730,35 +2777,9 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { virtual.* = @max(virtual.*, core.nextWake() orelse virtual.*); } } - if (got) { - // A run of queued motions is one move to its last position (the - // handler reads only absolute x/y and held buttons): acting on - // each would repeat hover and selection work the next undoes. - var motion: ?c.SDL_Event = null; - while (true) { - if (s.split(&sev)) break; - if (sev.type == c.SDL_EVENT_MOUSE_MOTION and (motion == null or motion.?.motion.windowID == sev.motion.windowID)) { - motion = sev; - } else { - if (motion) |*m| { - _ = s.windowView(); - dispatch(g, &in, m); - } - motion = null; - if (sev.type == c.SDL_EVENT_MOUSE_MOTION) { - motion = sev; - } else { - _ = s.windowView(); - dispatch(g, &in, &sev); - } - } - if (!c.SDL_PollEvent(&sev)) break; - } - if (motion) |*m| { - _ = s.windowView(); - dispatch(g, &in, m); - } - } + // A run of queued motions is one move to its last position + // (Input.moved), whoever's input it is. + if (got) s.takeEvents(g, &in, &sev); runDemo(g, &in, core); // Paced: what came before the tick is in; wait out the rest of it, // unless an input came: its frame is drawn at once (the paced loop @@ -2780,17 +2801,7 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { pardes.turn.rest(); const more = c.SDL_PollEvent(&sev); pardes.turn.wake(); - if (more) { - if (!s.split(&sev)) { - _ = s.windowView(); - dispatch(g, &in, &sev); - while (c.SDL_PollEvent(&sev)) { - if (s.split(&sev)) break; - _ = s.windowView(); - dispatch(g, &in, &sev); - } - } - } else { + if (more) s.takeEvents(g, &in, &sev) else { // The events asked for every 100 µs, the core busy between. const until = c.SDL_GetTicksNS() + 100 * std.time.ns_per_us; while (c.SDL_GetTicksNS() < @min(until, tick)) std.atomic.spinLoopHint(); @@ -2807,6 +2818,8 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { return; } } + // The pass's last motion, before what the ptys said (`split`). + in.flush(); s.drainQueue(); if (s.gui) |g| pollGamepad(g, &in); if (in.redraw) core.needs_frame = true; @@ -2845,17 +2858,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(); @@ -2869,11 +2880,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 @@ -3143,7 +3165,7 @@ fn guiNow(ctx: ?*anyopaque) u64 { const s = shellOf(ctx); if (s.waited) { s.waited = false; - if (s.mail_only and s.peers.count() > 0 and s.core.clock.started) return s.core.clock.now_ns; + if (s.peers.heldNow(s.core, s.mail_only)) |held| return held; } return s.test_clock orelse s.paced_ns orelse c.SDL_GetTicksNS(); } @@ -3728,17 +3750,17 @@ fn holdContext(g: *Gui, surface: *const pardes.Surface, id: usize, held: u16, bh return .{ .rows = rows, .lift = @as(f32, @floatFromInt(rows)) * (row_px - layout.h) }; } -fn scrollScissor(g: *const Gui, layout: CellLayout, sw: u32, sh: u32) c.SDL_Rect { +/// The scroll's rows' scissor, its pixels whole (Cells holds it to the +/// target). +fn scrollScissor(g: *const Gui, layout: CellLayout) c.SDL_Rect { const r = g.scroll_rect; const px = layout.x_off + @as(f32, @floatFromInt(r.x + config.GUTTER)) * layout.w; const py = layout.y_off + @as(f32, @floatFromInt(g.scroll_body_y)) * layout.h + g.scroll_held_px; const pw = @as(f32, @floatFromInt(r.w - config.GUTTER)) * layout.w; const ph = @max(0, @as(f32, @floatFromInt(g.scroll_body_h)) * layout.h - g.scroll_held_px); - const x0 = std.math.clamp(@as(i32, @intFromFloat(@floor(px))), 0, @as(i32, @intCast(sw))); - const y0 = std.math.clamp(@as(i32, @intFromFloat(@floor(py))), 0, @as(i32, @intCast(sh))); - const x1 = std.math.clamp(@as(i32, @intFromFloat(@ceil(px + pw))), x0, @as(i32, @intCast(sw))); - const y1 = std.math.clamp(@as(i32, @intFromFloat(@ceil(py + ph))), y0, @as(i32, @intCast(sh))); - return .{ .x = x0, .y = y0, .w = x1 - x0, .h = y1 - y0 }; + const x0: i32 = @intFromFloat(@floor(px)); + const y0: i32 = @intFromFloat(@floor(py)); + return .{ .x = x0, .y = y0, .w = @as(i32, @intFromFloat(@ceil(px + pw))) - x0, .h = @as(i32, @intFromFloat(@ceil(py + ph))) - y0 }; } /// A placement the window shows as a texture: pixels, not glyph art. @@ -3880,6 +3902,8 @@ fn prepareNativeImages( return true; } +/// A picture's scissor, its placement's cells (Cells holds it to the +/// target: a frame may be larger than the window it is drawn into). fn imageScissor(g: *const Gui, place: pardes.Placement) c.SDL_Rect { return .{ .x = @intCast(@as(u32, place.dst.x) * g.cell_w), @@ -4085,7 +4109,7 @@ fn renderFrame( building = false; if (frame_probe) |probe| probe.zone(.gui_build, probe_build); // Drawn only over a scroll's shifted rows (scrollScissor asks a scroll). - const scroll_clip = if (shifted != 0) scrollScissor(g, layout, sw, sh) else std.mem.zeroes(c.SDL_Rect); + const scroll_clip = if (shifted != 0) scrollScissor(g, layout) else std.mem.zeroes(c.SDL_Rect); g.cells.record(cmd, target, sw, sh, clear, background_opacity, groups.items[0..groups.len], groups.ink, cell_total, shifted, scroll_clip, overlay_count); command_consumed = true; @@ -4514,7 +4538,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; @@ -4529,12 +4553,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); } @@ -4544,12 +4562,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; @@ -7021,6 +7033,13 @@ test "a held key moves the view at the stream's own rate, never a bounce a line, for (70..90) |k| try std.testing.expectEqual(held.carets[70], held.carets[k]); } +test "a picture's scissor is its placement's cells, cut at its pane's edges" { + const g = testGui(10, 20, 6, 12); + var place: pardes.Placement = undefined; + place.dst = .{ .x = 2, .y = 3, .w = 4, .h = 5 }; + try std.testing.expectEqual(c.SDL_Rect{ .x = 20, .y = 60, .w = 40, .h = 100 }, imageScissor(&g, place)); +} + test "a scroll's shifted rows start under the context rows, and its scissor below their band" { var surface: pardes.Surface = .{}; var g = testGui(10, 20, 6, 12); @@ -7032,7 +7051,7 @@ test "a scroll's shifted rows start under the context rows, and its scissor belo const grid = holdContext(&g, &surface, 0, 3, 19, layout); try std.testing.expectEqual(@as(u16, 3), grid.rows); try std.testing.expectEqual(@as(f32, 0), grid.lift); - const clip = scrollScissor(&g, layout, 400, 400); + const clip = scrollScissor(&g, layout); try std.testing.expectEqual(@as(c_int, 20 + 3 * 20), clip.y); try std.testing.expectEqual(@as(c_int, 16 * 20), clip.h); // In a body layer they are tagline-high: the rows under them move up @@ -7041,11 +7060,11 @@ test "a scroll's shifted rows start under the context rows, and its scissor belo surface.body_layers[0].context_rows = 3; const layered = holdContext(&g, &surface, 0, 3, 19, layout); try std.testing.expectEqual(@as(f32, 3 * (12 - 20)), layered.lift); - try std.testing.expectEqual(@as(c_int, 20 + 3 * 12), scrollScissor(&g, layout, 400, 400).y); + try std.testing.expectEqual(@as(c_int, 20 + 3 * 12), scrollScissor(&g, layout).y); // None held: the whole body moves. surface.body_layers[0].rows = 0; try std.testing.expectEqual(@as(u16, 0), holdContext(&g, &surface, 0, 0, 19, layout).rows); - try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout, 400, 400).y); + try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout).y); } test "concealed terminal text emits no ink on its ground" { |
