glfw: fix failing Mod bitmask tests, make fromInt/toInt work on non-6-bit integers
Helps hexops/mach#37 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
60eeae4904
commit
7cc850982f
1 changed files with 3 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ pub const Mods = packed struct {
|
||||||
super: bool = false,
|
super: bool = false,
|
||||||
caps_lock: bool = false,
|
caps_lock: bool = false,
|
||||||
num_lock: bool = false,
|
num_lock: bool = false,
|
||||||
|
_reserved: u2 = 0,
|
||||||
|
|
||||||
inline fn verifyIntType(comptime IntType: type) void {
|
inline fn verifyIntType(comptime IntType: type) void {
|
||||||
comptime {
|
comptime {
|
||||||
|
|
@ -25,12 +26,12 @@ pub const Mods = packed struct {
|
||||||
|
|
||||||
pub inline fn toInt(self: Mods, comptime IntType: type) IntType {
|
pub inline fn toInt(self: Mods, comptime IntType: type) IntType {
|
||||||
verifyIntType(IntType);
|
verifyIntType(IntType);
|
||||||
return @bitCast(IntType, self);
|
return @intCast(IntType, @bitCast(u8, self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn fromInt(flags: anytype) Mods {
|
pub inline fn fromInt(flags: anytype) Mods {
|
||||||
verifyIntType(@TypeOf(flags));
|
verifyIntType(@TypeOf(flags));
|
||||||
return @bitCast(Mods, flags);
|
return @bitCast(Mods, @intCast(u8, flags));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue