From 2897061ffd21bf27b1ac4a55f099671a542eb6a8 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 30 Oct 2021 13:00:04 -0700 Subject: [PATCH] glfw: make Hat.fromInt, Hat.toInt work on non-5-bit integers Helps hexops/mach#37 Signed-off-by: Stephen Gutekanst --- glfw/src/hat.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/glfw/src/hat.zig b/glfw/src/hat.zig index d819a65c..b865994c 100644 --- a/glfw/src/hat.zig +++ b/glfw/src/hat.zig @@ -10,6 +10,7 @@ pub const Hat = packed struct { right: bool = false, down: bool = false, left: bool = false, + _reserved: u3 = 0, inline fn verifyIntType(comptime IntType: type) void { comptime { @@ -22,12 +23,12 @@ pub const Hat = packed struct { pub inline fn toInt(self: Hat, comptime IntType: type) IntType { verifyIntType(IntType); - return @bitCast(IntType, self); + return @intCast(IntType, @bitCast(u8, self)); } pub inline fn fromInt(flags: anytype) Hat { verifyIntType(@TypeOf(flags)); - return @bitCast(Hat, flags); + return @bitCast(Hat, @intCast(u8, flags)); } };