items no longer pile up

This commit is contained in:
Jeeves 2025-05-30 21:10:25 -06:00
parent 35dd123504
commit 7e9ea6e641

View file

@ -81,7 +81,7 @@ pub fn main() !void {
}
}
var debug_draw = true;
var debug_draw = false;
var global_font: raylib.Font = undefined;
@ -105,6 +105,7 @@ pub const Scales = struct {
column_position_spacing: f32,
column_item_spacing: f32,
column_item_start: f32,
column_item_before_start: f32,
/// Recalculate scales after screen resize.
pub fn recalculate(self: *Scales) void {
@ -124,6 +125,7 @@ pub const Scales = struct {
self.column_position_spacing = 64;
self.column_item_spacing = 16;
self.column_item_start = 117.8;
self.column_item_before_start = 48;
}
};
@ -203,8 +205,13 @@ pub const Column = struct {
if (up or down) self.refresh(true);
}
fn refresh(self: *Column, animate: bool) void {
var y = scales.column_item_start;
fn refresh(self: *Column, comptime animate: bool) void {
var y = scales.column_item_before_start - (scales.item_icon_small_height + scales.column_item_spacing) * @as(f32, @floatFromInt(self.selected));
for (self.items.items[0..self.selected]) |item| {
item.setPosition(animate, .{ .x = scales.column_position_center.x, .y = y });
y += scales.item_icon_small_height + scales.column_item_spacing;
}
y = scales.column_item_start;
for (self.items.items[self.selected..]) |item| {
item.setPosition(animate, .{ .x = scales.column_position_center.x, .y = y });
y += scales.item_icon_small_height + scales.column_item_spacing;
@ -295,7 +302,7 @@ pub const Item = struct {
);
}
pub fn setPosition(self: *Item, animate: bool, position: raylib.Vector2) void {
pub fn setPosition(self: *Item, comptime animate: bool, position: raylib.Vector2) void {
if (animate) {
self.animator.time = 0;
self.animator.start_position = self.position;