1
0
chip8-zig/src/horizontal-layout.zig

39 lines
908 B
Zig

const Self = @This();
const rl = @import("raylib");
bounds: rl.Rectangle,
gap: f32,
used_width: f32,
pub fn init(gap: f32, bounds: rl.Rectangle) Self {
return Self{
.bounds = bounds,
.gap = gap,
.used_width = 0
};
}
pub fn column_sized(self: *Self, width: f32, height: f32) rl.Rectangle {
const rect = rl.Rectangle{
.x = self.bounds.x + self.used_width,
.y = self.bounds.y,
.width = width,
.height = height,
};
self.used_width += width + self.gap;
return rect;
}
pub fn column(self: *Self, width: f32) rl.Rectangle {
return self.column_sized(width, self.bounds.height);
}
pub fn column_full(self: *Self) rl.Rectangle {
const left_width = self.bounds.width - self.used_width;
return self.column_sized(left_width, self.bounds.height);
}
pub fn add_gap(self: *Self, gap: f32) void {
self.used_width += gap;
}