glfw: add Joystick.getName
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
8bcc2cf51a
commit
1e6afa3bcf
1 changed files with 34 additions and 28 deletions
|
@ -178,34 +178,30 @@ pub inline fn getHats(self: Joystick) Error!?[]const u8 {
|
||||||
return hats[0..@intCast(usize, count)];
|
return hats[0..@intCast(usize, count)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(joystick)
|
/// Returns the name of the specified joystick.
|
||||||
// /// Returns the name of the specified joystick.
|
///
|
||||||
// ///
|
/// This function returns the name, encoded as UTF-8, of the specified joystick. The returned string
|
||||||
// /// This function returns the name, encoded as UTF-8, of the specified joystick.
|
/// is allocated and freed by GLFW. You should not free it yourself.
|
||||||
// /// The returned string is allocated and freed by GLFW. You should not free it
|
///
|
||||||
// /// yourself.
|
/// If the specified joystick is not present this function will return null but will not generate an
|
||||||
// ///
|
/// error. This can be used instead of first calling glfw.Joystick.present.
|
||||||
// /// If the specified joystick is not present this function will return null
|
///
|
||||||
// /// but will not generate an error. This can be used instead of first calling
|
/// @return The UTF-8 encoded name of the joystick, or null if the joystick is not present or an
|
||||||
// /// @ref glfwJoystickPresent.
|
/// error occurred.
|
||||||
// ///
|
///
|
||||||
// /// @param[in] jid The [joystick](@ref joysticks) to query.
|
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
|
||||||
// /// @return The UTF-8 encoded name of the joystick, or null if the joystick
|
///
|
||||||
// /// is not present or an error occurred.
|
/// @pointer_lifetime The returned string is allocated and freed by GLFW. You should not free it
|
||||||
// ///
|
/// yourself. It is valid until the specified joystick is disconnected or the library is terminated.
|
||||||
// /// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
|
///
|
||||||
// ///
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
// /// @pointer_lifetime The returned string is allocated and freed by GLFW. You
|
///
|
||||||
// /// should not free it yourself. It is valid until the specified joystick is
|
/// see also: joystick_name
|
||||||
// /// disconnected or the library is terminated.
|
pub inline fn getName(self: Joystick) Error![*c]const u8 {
|
||||||
// ///
|
const name = c.glfwGetJoystickName(self.jid);
|
||||||
// /// @thread_safety This function must only be called from the main thread.
|
try getError();
|
||||||
// ///
|
return name;
|
||||||
// /// see also: joystick_name
|
}
|
||||||
// ///
|
|
||||||
// ///
|
|
||||||
// /// @ingroup input
|
|
||||||
// GLFWAPI const char* glfwGetJoystickName(int jid);
|
|
||||||
|
|
||||||
// TODO(joystick)
|
// TODO(joystick)
|
||||||
// /// Returns the SDL compatible GUID of the specified joystick.
|
// /// Returns the SDL compatible GUID of the specified joystick.
|
||||||
|
@ -466,6 +462,16 @@ test "getHats" {
|
||||||
_ = joystick.getHats() catch |err| std.debug.print("failed to get joystick hats, joysticks not supported? error={}\n", .{err});
|
_ = joystick.getHats() catch |err| std.debug.print("failed to get joystick hats, joysticks not supported? error={}\n", .{err});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "getName" {
|
||||||
|
const glfw = @import("main.zig");
|
||||||
|
try glfw.init();
|
||||||
|
defer glfw.terminate();
|
||||||
|
|
||||||
|
const joystick = glfw.Joystick{ .jid = glfw.Joystick.one };
|
||||||
|
|
||||||
|
_ = joystick.getName() catch |err| std.debug.print("failed to get joystick name, joysticks not supported? error={}\n", .{err});
|
||||||
|
}
|
||||||
|
|
||||||
test "setUserPointer_syntax" {
|
test "setUserPointer_syntax" {
|
||||||
const glfw = @import("main.zig");
|
const glfw = @import("main.zig");
|
||||||
try glfw.init();
|
try glfw.init();
|
||||||
|
|
Loading…
Add table
Reference in a new issue