mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-21 13:04:20 +02:00
review
most of what was reviewed came from insanity checking
This commit is contained in:
parent
5c31b8bcb8
commit
6d48af424a
1 changed files with 7 additions and 7 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue