const std = @import("std"); const c = @cImport({ @cInclude("stb_rect_pack.h"); }); const STBRectPack = @This(); ctx: c.stbrp_context, pub fn init(self: *STBRectPack, width: u32, height: u32, nodes: []Node) void { c.stbrp_init_target(&self.ctx, @intCast(width), @intCast(height), nodes.ptr, @intCast(nodes.len)); } pub fn setupAllowOutOfMem(self: *STBRectPack, enabled: bool) void { c.stbrp_setup_heuristic(&self.ctx, if (enabled) 1 else 0); } pub fn setupHeuristic(self: *STBRectPack, heuristic: Heuristic) void { c.stbrp_setup_heuristic(&self.ctx, heuristic); } pub fn packRects(self: *STBRectPack, rects: []Rect) bool { return c.stbrp_pack_rects(&self.ctx, rects.ptr, @intCast(rects.len)) == 1; } pub const Heuristic = enum(i32) { Skyline_BL_sortHeight = c.STBRP_HEURISTIC_Skyline_BL_sortHeight, Skyline_BF_sortHeight = c.STBRP_HEURISTIC_Skyline_BF_sortHeight, _, pub const default = Heuristic.Skyline_BL_sortHeight; }; pub const Node = c.stbrp_node; pub const Rect = c.stbrp_rect;