glfw: make setKeyCallback use Key enum directly
Helps hexops/mach#37 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
f6f758859a
commit
2e6b73b388
1 changed files with 5 additions and 4 deletions
|
|
@ -49,8 +49,9 @@ pub const InternalUserPointer = struct {
|
||||||
setMaximizeCallback: ?fn (window: Window, maximized: bool) void,
|
setMaximizeCallback: ?fn (window: Window, maximized: bool) void,
|
||||||
setFramebufferSizeCallback: ?fn (window: Window, width: isize, height: isize) void,
|
setFramebufferSizeCallback: ?fn (window: Window, width: isize, height: isize) void,
|
||||||
setContentScaleCallback: ?fn (window: Window, xscale: f32, yscale: f32) void,
|
setContentScaleCallback: ?fn (window: Window, xscale: f32, yscale: f32) void,
|
||||||
setKeyCallback: ?fn (window: Window, key: isize, scancode: isize, action: Action, mods: Mods) void,
|
setKeyCallback: ?fn (window: Window, key: Key, scancode: isize, action: Action, mods: Mods) void,
|
||||||
setCharCallback: ?fn (window: Window, codepoint: u21) void,
|
setCharCallback: ?fn (window: Window, codepoint: u21) void,
|
||||||
|
// TODO(enumify): button
|
||||||
setMouseButtonCallback: ?fn (window: Window, button: isize, action: Action, mods: Mods) void,
|
setMouseButtonCallback: ?fn (window: Window, button: isize, action: Action, mods: Mods) void,
|
||||||
setCursorPosCallback: ?fn (window: Window, xpos: f64, ypos: f64) void,
|
setCursorPosCallback: ?fn (window: Window, xpos: f64, ypos: f64) void,
|
||||||
setCursorEnterCallback: ?fn (window: Window, entered: bool) void,
|
setCursorEnterCallback: ?fn (window: Window, entered: bool) void,
|
||||||
|
|
@ -1525,7 +1526,7 @@ pub inline fn setCursor(self: Window, cursor: Cursor) Error!void {
|
||||||
fn setKeyCallbackWrapper(handle: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void {
|
fn setKeyCallbackWrapper(handle: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void {
|
||||||
const window = from(handle.?) catch unreachable;
|
const window = from(handle.?) catch unreachable;
|
||||||
const internal = window.getInternal();
|
const internal = window.getInternal();
|
||||||
internal.setKeyCallback.?(window, @intCast(isize, key), @intCast(isize, scancode), @intToEnum(Action, action), Mods.fromInt(mods));
|
internal.setKeyCallback.?(window, @intToEnum(Key, key), @intCast(isize, scancode), @intToEnum(Action, action), Mods.fromInt(mods));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the key callback.
|
/// Sets the key callback.
|
||||||
|
|
@ -1562,7 +1563,7 @@ fn setKeyCallbackWrapper(handle: ?*c.GLFWwindow, key: c_int, scancode: c_int, ac
|
||||||
/// @thread_safety This function must only be called from the main thread.
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
///
|
///
|
||||||
/// see also: input_key
|
/// see also: input_key
|
||||||
pub inline fn setKeyCallback(self: Window, callback: ?fn (window: Window, key: isize, scancode: isize, action: Action, mods: Mods) void) void {
|
pub inline fn setKeyCallback(self: Window, callback: ?fn (window: Window, key: Key, scancode: isize, action: Action, mods: Mods) void) void {
|
||||||
var internal = self.getInternal();
|
var internal = self.getInternal();
|
||||||
internal.setKeyCallback = callback;
|
internal.setKeyCallback = callback;
|
||||||
_ = c.glfwSetKeyCallback(self.handle, if (callback != null) setKeyCallbackWrapper else null);
|
_ = c.glfwSetKeyCallback(self.handle, if (callback != null) setKeyCallbackWrapper else null);
|
||||||
|
|
@ -2697,7 +2698,7 @@ test "setKeyCallback" {
|
||||||
defer window.destroy();
|
defer window.destroy();
|
||||||
|
|
||||||
window.setKeyCallback((struct {
|
window.setKeyCallback((struct {
|
||||||
fn callback(_window: Window, key: isize, scancode: isize, action: Action, mods: Mods) void {
|
fn callback(_window: Window, key: Key, scancode: isize, action: Action, mods: Mods) void {
|
||||||
_ = _window;
|
_ = _window;
|
||||||
_ = key;
|
_ = key;
|
||||||
_ = scancode;
|
_ = scancode;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue