Merge pull request #701 from rodrigorc/FixWinitKeyboard

Fix keyboard modifiers in Winit with the new ImGui version.
This commit is contained in:
dbr/Ben 2023-01-15 21:55:44 +10:30 committed by GitHub
commit 93cde6aa4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 8 deletions

View File

@ -143,10 +143,22 @@ fn handle_key(io: &mut Io, key: &Scancode, pressed: bool) {
/// Handle changes in the key modifier states.
fn handle_key_modifier(io: &mut Io, keymod: &Mod) {
io.key_shift = keymod.intersects(Mod::LSHIFTMOD | Mod::RSHIFTMOD);
io.key_ctrl = keymod.intersects(Mod::LCTRLMOD | Mod::RCTRLMOD);
io.key_alt = keymod.intersects(Mod::LALTMOD | Mod::RALTMOD);
io.key_super = keymod.intersects(Mod::LGUIMOD | Mod::RGUIMOD);
io.add_key_event(
imgui::Key::ModShift,
keymod.intersects(Mod::LSHIFTMOD | Mod::RSHIFTMOD),
);
io.add_key_event(
imgui::Key::ModCtrl,
keymod.intersects(Mod::LCTRLMOD | Mod::RCTRLMOD),
);
io.add_key_event(
imgui::Key::ModAlt,
keymod.intersects(Mod::LALTMOD | Mod::RALTMOD),
);
io.add_key_event(
imgui::Key::ModSuper,
keymod.intersects(Mod::LGUIMOD | Mod::RGUIMOD),
);
}
/// Map an imgui::MouseCursor to an equivalent sdl2::mouse::SystemCursor.

View File

@ -399,10 +399,10 @@ impl WinitPlatform {
// not reliably send modifier states during certain events like ScreenCapture.
// Gotta let the people show off their pretty imgui widgets!
if let WindowEvent::ModifiersChanged(modifiers) = event {
io.key_shift = modifiers.shift();
io.key_ctrl = modifiers.ctrl();
io.key_alt = modifiers.alt();
io.key_super = modifiers.logo();
io.add_key_event(Key::ModShift, modifiers.shift());
io.add_key_event(Key::ModCtrl, modifiers.ctrl());
io.add_key_event(Key::ModAlt, modifiers.alt());
io.add_key_event(Key::ModSuper, modifiers.logo());
}
self.handle_window_event(io, window, event);

View File

@ -147,6 +147,11 @@ pub enum Key {
ReservedForModShift = sys::ImGuiKey_ReservedForModShift,
ReservedForModAlt = sys::ImGuiKey_ReservedForModAlt,
ReservedForModSuper = sys::ImGuiKey_ReservedForModSuper,
ModCtrl = sys::ImGuiMod_Ctrl,
ModShift = sys::ImGuiMod_Shift,
ModAlt = sys::ImGuiMod_Alt,
ModSuper = sys::ImGuiMod_Super,
ModShortcut = sys::ImGuiMod_Shortcut,
}
impl Key {