diff --git a/src/enums.zig b/src/enums.zig index b629396..07dc3eb 100644 --- a/src/enums.zig +++ b/src/enums.zig @@ -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); } } }