most of what was reviewed came from insanity checking
This commit is contained in:
RadsammyT 2025-12-01 12:14:59 -05:00
commit 6d48af424a
No known key found for this signature in database
GPG key ID: 07BAADCA8A7D4F1E

View file

@ -22,21 +22,21 @@ pub const Input = enum {
password,
/// Moves the current Input forwards by one entry. If `reverse`, then the Input
/// moves backwards. If `overflow` is true, then the entry will wrap back around
/// moves backwards. If `wrap` is true, then the entry will wrap back around
pub fn move(self: *Input, reverse: bool, wrap: bool) void {
const len = @typeInfo(Input).@"enum".fields.len - 1;
const maxNum = @typeInfo(Input).@"enum".fields.len - 1;
const selfNum = @intFromEnum(self.*);
if (reverse) {
if (wrap) {
self.* = @as(Input, @enumFromInt(selfNum -% 1));
self.* = @enumFromInt(selfNum -% 1);
} else if (selfNum != 0) {
self.* = @as(Input, @enumFromInt(std.math.clamp(selfNum - 1, 0, len)));
self.* = @enumFromInt(selfNum - 1);
}
} else {
if (wrap) {
self.* = @as(Input, @enumFromInt(selfNum +% 1));
} else if (selfNum != len) {
self.* = @as(Input, @enumFromInt(std.math.clamp(selfNum + 1, 0, len)));
self.* = @enumFromInt(selfNum +% 1);
} else if (selfNum != maxNum) {
self.* = @enumFromInt(selfNum + 1);
}
}
}