1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-21 01:44:21 +00:00

handle blur and focus events correctly, focusin and focusout aren't enough

This commit is contained in:
SlowRiot 2024-12-06 17:22:46 +00:00
parent 60984d1a34
commit 9fd9bf9f50

View file

@ -482,6 +482,28 @@ void ImGui_ImplEmscripten_Init() {
return true; // the event was consumed
}
);
emscripten_set_blur_callback(
EMSCRIPTEN_EVENT_TARGET_WINDOW, // target
nullptr, // userData
false, // useCapture
[](int /*event_type*/, EmscriptenFocusEvent const */*event*/, void */*data*/) { // event_type == EMSCRIPTEN_EVENT_BLUR
auto &imgui_io{ImGui::GetIO()};
imgui_io.AddFocusEvent(false);
imgui_io.ClearInputKeys(); // clear pending input keys on focus gain
return true; // the event was consumed
}
);
emscripten_set_focus_callback(
EMSCRIPTEN_EVENT_TARGET_WINDOW, // target
nullptr, // userData
false, // useCapture
[](int /*event_type*/, EmscriptenFocusEvent const */*event*/, void */*data*/) { // event_type == EMSCRIPTEN_EVENT_FOCUS
auto &imgui_io{ImGui::GetIO()};
imgui_io.AddFocusEvent(true);
imgui_io.ClearInputKeys(); // clear pending input keys on focus loss - for example if you press tab to cycle to another part of the UI
return true; // the event was consumed
}
);
emscripten_set_focusin_callback(
EMSCRIPTEN_EVENT_TARGET_WINDOW, // target
nullptr, // userData