Key callbacks to quit from a playground.

This commit is contained in:
Chinmay Garde
2021-07-02 16:00:21 -07:00
committed by Dan Field
parent f08b91396d
commit d04587c735

View File

@@ -22,6 +22,16 @@ Playground::Playground() = default;
Playground::~Playground() = default;
static void PlaygroundKeyCallback(GLFWwindow* window,
int key,
int scancode,
int action,
int mods) {
if ((key == GLFW_KEY_ESCAPE || key == GLFW_KEY_Q) && action == GLFW_RELEASE) {
::glfwSetWindowShouldClose(window, GLFW_TRUE);
}
}
bool Playground::OpenPlaygroundHere(std::function<bool()> closure) {
if (!closure) {
return true;
@@ -45,6 +55,9 @@ bool Playground::OpenPlaygroundHere(std::function<bool()> closure) {
return false;
}
::glfwSetWindowUserPointer(window, this);
::glfwSetKeyCallback(window, &PlaygroundKeyCallback);
fml::ScopedCleanupClosure close_window(
[window]() { ::glfwDestroyWindow(window); });