mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 19:50:03 -06:00
Fix bug causing inconsistent imgui state when pressing the enter key
This commit is contained in:
@@ -493,24 +493,43 @@ bool GUI::mouseWheelCallback(double position) {
|
||||
}
|
||||
|
||||
bool GUI::keyCallback(Key key, KeyModifier modifier, KeyAction action) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
bool consumeEvent = io.WantCaptureKeyboard;
|
||||
if (consumeEvent) {
|
||||
int keyIndex = static_cast<int>(key);
|
||||
if (keyIndex < 0) {
|
||||
LERROR("Pressed key of index '" << keyIndex << "' was negative");
|
||||
}
|
||||
else {
|
||||
if (action == KeyAction::Press)
|
||||
io.KeysDown[keyIndex] = true;
|
||||
if (action == KeyAction::Release)
|
||||
io.KeysDown[keyIndex] = false;
|
||||
}
|
||||
|
||||
io.KeyShift = hasKeyModifier(modifier, KeyModifier::Shift);
|
||||
io.KeyCtrl = hasKeyModifier(modifier, KeyModifier::Control);
|
||||
io.KeyAlt = hasKeyModifier(modifier, KeyModifier::Alt);
|
||||
const int keyIndex = static_cast<int>(key);
|
||||
if (keyIndex < 0) {
|
||||
LERROR("Key of index '" << keyIndex << "' was negative");
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool hasShift = hasKeyModifier(modifier, KeyModifier::Shift);
|
||||
const bool hasCtrl = hasKeyModifier(modifier, KeyModifier::Control);
|
||||
const bool hasAlt = hasKeyModifier(modifier, KeyModifier::Alt);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
const bool consumeEvent = io.WantCaptureKeyboard;
|
||||
if (consumeEvent) {
|
||||
if (action == KeyAction::Press) {
|
||||
io.KeysDown[keyIndex] = true;
|
||||
}
|
||||
io.KeyShift = hasShift;
|
||||
io.KeyCtrl = hasCtrl;
|
||||
io.KeyAlt = hasAlt;
|
||||
}
|
||||
|
||||
// Even if the event is not consumed,
|
||||
// set keys and modifiers to false when they are released.
|
||||
if (action == KeyAction::Release) {
|
||||
io.KeysDown[keyIndex] = false;
|
||||
}
|
||||
if (!hasShift) {
|
||||
io.KeyShift = false;
|
||||
}
|
||||
if (!hasCtrl) {
|
||||
io.KeyCtrl = false;
|
||||
}
|
||||
if (!hasAlt) {
|
||||
io.KeyAlt = false;
|
||||
}
|
||||
|
||||
return consumeEvent;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user