43 lines
1.2 KiB
Zig
43 lines
1.2 KiB
Zig
const rl = @import("raylib");
|
|
const Stack = @This();
|
|
|
|
pub const Direction = enum {
|
|
top_to_bottom,
|
|
bottom_to_top,
|
|
left_to_right
|
|
};
|
|
|
|
unused_box: rl.Rectangle,
|
|
dir: Direction,
|
|
gap: f32 = 0,
|
|
|
|
pub fn init(box: rl.Rectangle, dir: Direction) Stack {
|
|
return Stack{
|
|
.unused_box = box,
|
|
.dir = dir
|
|
};
|
|
}
|
|
|
|
pub fn next(self: *Stack, size: f32) rl.Rectangle {
|
|
return switch (self.dir) {
|
|
.top_to_bottom => {
|
|
const next_box = rl.Rectangle.init(self.unused_box.x, self.unused_box.y, self.unused_box.width, size);
|
|
self.unused_box.y += size;
|
|
self.unused_box.y += self.gap;
|
|
return next_box;
|
|
},
|
|
.bottom_to_top => {
|
|
const next_box = rl.Rectangle.init(self.unused_box.x, self.unused_box.y + self.unused_box.height - size, self.unused_box.width, size);
|
|
self.unused_box.height -= size;
|
|
self.unused_box.height -= self.gap;
|
|
return next_box;
|
|
},
|
|
.left_to_right => {
|
|
const next_box = rl.Rectangle.init(self.unused_box.x, self.unused_box.y, size, self.unused_box.height);
|
|
self.unused_box.x += size;
|
|
self.unused_box.x += self.gap;
|
|
return next_box;
|
|
},
|
|
};
|
|
}
|