glfw: add Window.shouldClose
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
badc8939b5
commit
a9446f4ed6
2 changed files with 19 additions and 1 deletions
|
|
@ -232,6 +232,24 @@ pub fn destroy(self: Window) void {
|
||||||
getError() catch {};
|
getError() catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks the close flag of the specified window.
|
||||||
|
///
|
||||||
|
/// This function returns the value of the close flag of the specified window.
|
||||||
|
///
|
||||||
|
/// @thread_safety This function may be called from any thread. Access is not synchronized.
|
||||||
|
///
|
||||||
|
/// see also: window_close
|
||||||
|
pub fn shouldClose(self: Window) bool {
|
||||||
|
const flag = c.glfwWindowShouldClose(self.handle);
|
||||||
|
|
||||||
|
// The only error shouldClose could return would be glfw.Error.NotInitialized, which would
|
||||||
|
// definitely have occurred before calls to shouldClose. Returning an error here makes the API
|
||||||
|
// awkward to use, so we discard it instead.
|
||||||
|
getError() catch {};
|
||||||
|
|
||||||
|
return flag == c.GLFW_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
test "defaultHints" {
|
test "defaultHints" {
|
||||||
const glfw = @import("main.zig");
|
const glfw = @import("main.zig");
|
||||||
try glfw.init();
|
try glfw.init();
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ pub fn basicTest() !void {
|
||||||
defer window.destroy();
|
defer window.destroy();
|
||||||
|
|
||||||
var start = std.time.milliTimestamp();
|
var start = std.time.milliTimestamp();
|
||||||
while (std.time.milliTimestamp() < start + 1000 and c.glfwWindowShouldClose(window.handle) != c.GLFW_TRUE) {
|
while (std.time.milliTimestamp() < start + 1000 and !window.shouldClose()) {
|
||||||
c.glfwPollEvents();
|
c.glfwPollEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue