glfw: make Hat.fromInt, Hat.toInt work on non-5-bit integers
Helps hexops/mach#37 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
7cc850982f
commit
2897061ffd
1 changed files with 3 additions and 2 deletions
|
|
@ -10,6 +10,7 @@ pub const Hat = packed struct {
|
||||||
right: bool = false,
|
right: bool = false,
|
||||||
down: bool = false,
|
down: bool = false,
|
||||||
left: bool = false,
|
left: bool = false,
|
||||||
|
_reserved: u3 = 0,
|
||||||
|
|
||||||
inline fn verifyIntType(comptime IntType: type) void {
|
inline fn verifyIntType(comptime IntType: type) void {
|
||||||
comptime {
|
comptime {
|
||||||
|
|
@ -22,12 +23,12 @@ pub const Hat = packed struct {
|
||||||
|
|
||||||
pub inline fn toInt(self: Hat, comptime IntType: type) IntType {
|
pub inline fn toInt(self: Hat, comptime IntType: type) IntType {
|
||||||
verifyIntType(IntType);
|
verifyIntType(IntType);
|
||||||
return @bitCast(IntType, self);
|
return @intCast(IntType, @bitCast(u8, self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn fromInt(flags: anytype) Hat {
|
pub inline fn fromInt(flags: anytype) Hat {
|
||||||
verifyIntType(@TypeOf(flags));
|
verifyIntType(@TypeOf(flags));
|
||||||
return @bitCast(Hat, flags);
|
return @bitCast(Hat, @intCast(u8, flags));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue