Fix keyboard modifiers in Winit with the new ImGui version.

This commit is contained in:
Rodrigo Rivas Costa 2023-01-14 13:12:12 +01:00
parent 23a07ab1a6
commit 2106e17dea
3 changed files with 13 additions and 8 deletions

View File

@ -143,10 +143,10 @@ 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(Key::ModShift, keymod.intersects(Mod::LSHIFTMOD | Mod::RSHIFTMOD));
io.add_key_event(Key::ModCtrl, keymod.intersects(Mod::LCTRLMOD | Mod::RCTRLMOD));
io.add_key_event(Key::ModAlt, keymod.intersects(Mod::LALTMOD | Mod::RALTMOD));
io.add_key_event(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 {