diff --git a/CHANGELOG.md b/CHANGELOG.md index d10ca5cf8..90676008b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.6.2] - 15-Aug-2021 + +### Fixed + +- Fix receiving input when holding a button ([#37](https://github.com/mvlabat/bevy_egui/pull/37)). + ## [0.6.1] - 20-Jul-2021 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index b84382830..319a71fc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_egui" -version = "0.6.1" +version = "0.6.2" authors = ["mvlabat "] description = "A plugin for Egui integration into Bevy" license = "MIT" diff --git a/src/systems.rs b/src/systems.rs index 34819e0be..4b3b9f06d 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -6,9 +6,9 @@ use bevy::{ core::Time, ecs::system::{Local, Res, ResMut, SystemParam}, input::{ - keyboard::KeyCode, + keyboard::{KeyCode, KeyboardInput}, mouse::{MouseButton, MouseScrollUnit, MouseWheel}, - Input, + ElementState, Input, }, utils::HashMap, window::{ @@ -23,6 +23,7 @@ pub struct InputEvents<'a> { ev_cursor: EventReader<'a, CursorMoved>, ev_mouse_wheel: EventReader<'a, MouseWheel>, ev_received_character: EventReader<'a, ReceivedCharacter>, + ev_keyboard_input: EventReader<'a, KeyboardInput>, ev_window_focused: EventReader<'a, WindowFocused>, ev_window_created: EventReader<'a, WindowCreated>, } @@ -205,78 +206,51 @@ pub fn process_input( } } - for pressed_key in input_resources.keyboard_input.get_just_pressed() { - if let Some(key) = bevy_to_egui_key(*pressed_key) { - input_resources - .egui_input - .get_mut(&*window_resources.focused_window) - .unwrap() - .raw_input - .events - .push(egui::Event::Key { - key, - pressed: true, - modifiers, - }) - } - } - for pressed_key in input_resources.keyboard_input.get_just_released() { - if let Some(key) = bevy_to_egui_key(*pressed_key) { - input_resources - .egui_input - .get_mut(&*window_resources.focused_window) - .unwrap() - .raw_input - .events - .push(egui::Event::Key { - key, - pressed: false, - modifiers, - }) - } - } - - for egui_input in input_resources.egui_input.values_mut() { - egui_input.raw_input.predicted_dt = time.delta_seconds(); - } - let focused_input = input_resources .egui_input .get_mut(&*window_resources.focused_window) .unwrap(); - #[cfg(feature = "manage_clipboard")] - { - let mut copy = false; - let mut cut = false; - let mut paste = None; - if command && input_resources.keyboard_input.just_pressed(KeyCode::C) { - copy = true; - } - if command && input_resources.keyboard_input.just_pressed(KeyCode::X) { - cut = true; - } - if command && input_resources.keyboard_input.just_pressed(KeyCode::V) { - if let Some(contents) = input_resources.egui_clipboard.get_contents() { - paste = Some(contents); + for ev in input_events.ev_keyboard_input.iter() { + if let Some(key) = ev.key_code.and_then(bevy_to_egui_key) { + let egui_event = egui::Event::Key { + key, + pressed: match ev.state { + ElementState::Pressed => true, + ElementState::Released => false, + }, + modifiers, + }; + focused_input.raw_input.events.push(egui_event); + + #[cfg(feature = "manage_clipboard")] + if command { + match key { + egui::Key::C => { + focused_input.raw_input.events.push(egui::Event::Copy); + } + egui::Key::X => { + focused_input.raw_input.events.push(egui::Event::Cut); + } + egui::Key::V => { + if let Some(contents) = input_resources.egui_clipboard.get_contents() { + focused_input + .raw_input + .events + .push(egui::Event::Text(contents)) + } + } + _ => {} + } } } - - if copy { - focused_input.raw_input.events.push(egui::Event::Copy); - } - if cut { - focused_input.raw_input.events.push(egui::Event::Cut); - } - if let Some(content) = paste { - focused_input - .raw_input - .events - .push(egui::Event::Text(content)) - } - }; + } focused_input.raw_input.modifiers = modifiers; + + for egui_input in input_resources.egui_input.values_mut() { + egui_input.raw_input.predicted_dt = time.delta_seconds(); + } } pub fn begin_frame(