all: use explicit backing integers for packed structs
This commit is contained in:
parent
b63001eb4c
commit
d1ae96b650
2 changed files with 8 additions and 8 deletions
12
src/hat.zig
12
src/hat.zig
|
@ -4,12 +4,12 @@ const c = @import("c.zig").c;
|
|||
/// A bitmask of all Joystick hat states
|
||||
///
|
||||
/// See glfw.Joystick.getHats for how these are used.
|
||||
pub const Hat = packed struct {
|
||||
pub const Hat = packed struct(u8) {
|
||||
up: bool = false,
|
||||
right: bool = false,
|
||||
down: bool = false,
|
||||
left: bool = false,
|
||||
_reserved: u4 = 0,
|
||||
_padding: u4 = 0,
|
||||
|
||||
pub inline fn centered(self: Hat) bool {
|
||||
return self.up == false and self.right == false and self.down == false and self.left == false;
|
||||
|
@ -57,7 +57,7 @@ test "from int, single" {
|
|||
.right = false,
|
||||
.down = false,
|
||||
.left = false,
|
||||
._reserved = 0,
|
||||
._padding = 0,
|
||||
}, Hat.fromInt(RawHat.up));
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ test "from int, multi" {
|
|||
.right = false,
|
||||
.down = true,
|
||||
.left = true,
|
||||
._reserved = 0,
|
||||
._padding = 0,
|
||||
}, Hat.fromInt(RawHat.up | RawHat.down | RawHat.left));
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ test "to int, single" {
|
|||
.right = false,
|
||||
.down = false,
|
||||
.left = false,
|
||||
._reserved = 0,
|
||||
._padding = 0,
|
||||
};
|
||||
try std.testing.expectEqual(v.toInt(c_int), RawHat.up);
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ test "to int, multi" {
|
|||
.right = false,
|
||||
.down = true,
|
||||
.left = true,
|
||||
._reserved = 0,
|
||||
._padding = 0,
|
||||
};
|
||||
try std.testing.expectEqual(v.toInt(c_int), RawHat.up | RawHat.down | RawHat.left);
|
||||
}
|
||||
|
|
|
@ -6,14 +6,14 @@ const c = @import("c.zig").c;
|
|||
|
||||
// must be in sync with GLFW C constants in modifier group, search for "@defgroup mods Modifier key flags"
|
||||
/// A bitmask of all key modifiers
|
||||
pub const Mods = packed struct {
|
||||
pub const Mods = packed struct(u8) {
|
||||
shift: bool = false,
|
||||
control: bool = false,
|
||||
alt: bool = false,
|
||||
super: bool = false,
|
||||
caps_lock: bool = false,
|
||||
num_lock: bool = false,
|
||||
_reserved: u2 = 0,
|
||||
_padding: u2 = 0,
|
||||
|
||||
inline fn verifyIntType(comptime IntType: type) void {
|
||||
comptime {
|
||||
|
|
Loading…
Add table
Reference in a new issue