saveImage
Internal use only!
Always runs a single frame. If -Dgenerate-images is passed to zig build docs,
capture the physical pixels in rect, and write those as a png file.
If rect is null, capture the whole OS window.
Generates and saves images for documentation. The test name is required to
end with .png and are format strings evaluated at comptime.
Parameters
- self:*Self
- *Self
- frame:dvui.App.frameFunction
- dvui.App.frameFunction
- rect:?dvui.Rect.Physical
- ?dvui.Rect.Physical
- filename:[]const u8
- []const u8
Source
Implementation
pub fn saveImage(self: *Self, frame: dvui.App.frameFunction, rect: ?dvui.Rect.Physical, filename: []const u8) !void {
if (self.image_dir == null) {
// This means that the rest of the test is still performed and used as a normal dvui test.
_ = try step(frame);
return;
}
var dir = try std.Io.Dir.cwd().createDirPathOpen(dvui.io, self.image_dir.?, .{});
defer dir.close(dvui.io);
if (std.Io.Dir.path.dirname(filename)) |sub| try dir.createDirPath(dvui.io, sub);
const file = try dir.createFile(dvui.io, filename, .{});
defer file.close(dvui.io);
var buf: [512]u8 = undefined;
var writer = file.writer(dvui.io, &buf);
try capturePng(frame, rect, &writer.interface);
try writer.end();
}