diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:55:19 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:02:08 -0300 |
| commit | 1635d80290a48fddd4ae9f1de187e49cbd35f39b (patch) | |
| tree | 1ab0597f5e375310175e6f41128e616b0e8ff91e /src | |
| parent | fc2bc8b80cf524c4a4800b8492b1ddcd6e693ab9 (diff) | |
| download | pardes-1635d80290a48fddd4ae9f1de187e49cbd35f39b.tar.gz pardes-1635d80290a48fddd4ae9f1de187e49cbd35f39b.zip | |
image: contain and its Fit, a wrapper over containGeometry kept for the window built without MuPDF, are gone: gui.zig's two places there (nativePlaceDrawable, the native image instance) ask containGeometry, null exactly when the old size was zero, and the contain test asserts on it
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui/gui.zig | 6 | ||||
| -rw-r--r-- | src/image.zig | 17 |
2 files changed, 6 insertions, 17 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 00491aeb..6a310635 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -6578,8 +6578,7 @@ fn nativePlaceGeometry(g: *const Gui, place: anytype) ?pardes.image.NativeGeomet fn nativePlaceDrawable(g: *const Gui, place: anytype) bool { if (comptime pardes.pdf_enabled) return nativePlaceGeometry(g, place) != null; const bounds = nativeBounds(g, place) orelse return false; - const fit = pardes.image.contain(place.iw, place.ih, bounds.w, bounds.h); - return fit.w != 0 and fit.h != 0; + return pardes.image.containGeometry(place.iw, place.ih, bounds.w, bounds.h) != null; } fn uploadNativeTexture( @@ -6717,8 +6716,7 @@ fn emitPreparedImage( }; } else { const bounds = nativeBounds(g, place) orelse return false; - const fit = pardes.image.contain(place.iw, place.ih, bounds.w, bounds.h); - if (fit.w == 0 or fit.h == 0) return false; + const fit = (pardes.image.containGeometry(place.iw, place.ih, bounds.w, bounds.h) orelse return false).dst; instance.* = .{ .x0 = (@as(f32, @floatFromInt(body_x)) / win_w) * 2.0 - 1.0, .y0 = 1.0 - (@as(f32, @floatFromInt(body_y)) / win_h) * 2.0, diff --git a/src/image.zig b/src/image.zig index 357d9e94..e59696f8 100644 --- a/src/image.zig +++ b/src/image.zig @@ -634,20 +634,11 @@ pub fn containGeometry(iw: usize, ih: usize, max_w: u32, max_h: u32) ?NativeGeom return .{ .src = .{ .w = src_w, .h = src_h }, .dst = dst }; } -/// Compatibility helper for callers which need only the old contain size. -pub const Fit = struct { w: u32, h: u32 }; - -pub fn contain(iw: usize, ih: usize, max_w: u32, max_h: u32) Fit { - const geometry = containGeometry(iw, ih, max_w, max_h) orelse - return .{ .w = 0, .h = 0 }; - return .{ .w = geometry.dst.w, .h = geometry.dst.h }; -} - test "native image contain keeps aspect, bounds, top-left, and small-image size" { - try std.testing.expectEqual(Fit{ .w = 40, .h = 20 }, contain(400, 200, 40, 40)); - try std.testing.expectEqual(Fit{ .w = 20, .h = 40 }, contain(200, 400, 40, 40)); - try std.testing.expectEqual(Fit{ .w = 17, .h = 9 }, contain(17, 9, 40, 40)); - try std.testing.expectEqual(Fit{ .w = 0, .h = 0 }, contain(17, 9, 0, 40)); + try std.testing.expectEqual(PixelRect{ .w = 40, .h = 20 }, containGeometry(400, 200, 40, 40).?.dst); + try std.testing.expectEqual(PixelRect{ .w = 20, .h = 40 }, containGeometry(200, 400, 40, 40).?.dst); + try std.testing.expectEqual(PixelRect{ .w = 17, .h = 9 }, containGeometry(17, 9, 40, 40).?.dst); + try std.testing.expect(containGeometry(17, 9, 0, 40) == null); const odd = containGeometry(403, 211, 101, 47).?; try std.testing.expectEqual(PixelRect{ .w = 89, .h = 47 }, odd.dst); |
