Refactor active_input field-jumping logic (#873)

Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/873
Reviewed-by: AnErrupTion <anerruption@disroot.org>
Co-authored-by: radsammyt <radsammyt@noreply.codeberg.org>
Co-committed-by: radsammyt <radsammyt@noreply.codeberg.org>
This commit is contained in:
radsammyt
2025-12-01 20:07:59 +01:00
committed by AnErrupTion
parent d82fa82a87
commit 6cb53b6e38
2 changed files with 27 additions and 32 deletions

View File

@@ -1,3 +1,4 @@
const std = @import("std");
pub const Animation = enum {
none,
doom,
@@ -19,6 +20,26 @@ pub const Input = enum {
session,
login,
password,
/// Moves the current Input forwards by one entry. If `reverse`, then the Input
/// moves backwards. If `wrap` is true, then the entry will wrap back around
pub fn move(self: *Input, reverse: bool, wrap: bool) void {
const maxNum = @typeInfo(Input).@"enum".fields.len - 1;
const selfNum = @intFromEnum(self.*);
if (reverse) {
if (wrap) {
self.* = @enumFromInt(selfNum -% 1);
} else if (selfNum != 0) {
self.* = @enumFromInt(selfNum - 1);
}
} else {
if (wrap) {
self.* = @enumFromInt(selfNum +% 1);
} else if (selfNum != maxNum) {
self.* = @enumFromInt(selfNum + 1);
}
}
}
};
pub const ViMode = enum {