Revert key-repeat behavior (#2429)
* Revert key-repeat behavior This fixes key-repeats everywhere in egui where it was broken,including: - Enter in TextEdit:s - Arrow keys for sliders and dragvalues - … * Update changelog * Remove old comment
This commit is contained in:
parent
e7471f1191
commit
0a1b85f35a
4 changed files with 24 additions and 30 deletions
|
@ -5,8 +5,11 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG
|
|||
|
||||
|
||||
## Unreleased
|
||||
### Changed 🔧
|
||||
* `InputState`: all press functions again include key repeates (like in egui 0.19) ([#2429](https://github.com/emilk/egui/pull/2429)).
|
||||
|
||||
### Fixed 🐛
|
||||
* Fix key-repeat for backspace and arrow keys in `TextEdit` ([#2416](https://github.com/emilk/egui/pull/2416)).
|
||||
* Fix key-repeats for `TextEdit`, `Slider`s, etc ([#2429](https://github.com/emilk/egui/pull/2429)).
|
||||
|
||||
|
||||
## 0.20.0 - 2022-12-08 - AccessKit, prettier text, overlapping widgets
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! The input needed by egui.
|
||||
|
||||
#![allow(deprecated)] // TODO(emilk): remove
|
||||
|
||||
use crate::emath::*;
|
||||
|
||||
/// What the integrations provides to egui at the start of each frame.
|
||||
|
@ -191,13 +193,9 @@ pub enum Event {
|
|||
modifiers: Modifiers,
|
||||
},
|
||||
|
||||
/// A key was repeated while pressed.
|
||||
KeyRepeat {
|
||||
key: Key,
|
||||
|
||||
/// The state of the modifier keys at the time of the event.
|
||||
modifiers: Modifiers,
|
||||
},
|
||||
/// DEPRECATED - DO NOT USE
|
||||
#[deprecated = "Do not use"]
|
||||
KeyRepeat { key: Key, modifiers: Modifiers },
|
||||
|
||||
/// The mouse or touch moved to a new place.
|
||||
PointerMoved(Pos2),
|
||||
|
|
|
@ -166,20 +166,10 @@ impl InputState {
|
|||
let mut zoom_factor_delta = 1.0;
|
||||
for event in &mut new.events {
|
||||
match event {
|
||||
Event::Key {
|
||||
key,
|
||||
pressed,
|
||||
modifiers,
|
||||
} => {
|
||||
Event::Key { key, pressed, .. } => {
|
||||
if *pressed {
|
||||
// We only retain presses that are novel (i.e. the first Press event, not those generated by key-repeat)
|
||||
// key repeats are represented by KeyRepeat.
|
||||
if !keys_down.insert(*key) {
|
||||
*event = Event::KeyRepeat {
|
||||
key: *key,
|
||||
modifiers: *modifiers,
|
||||
};
|
||||
}
|
||||
keys_down.insert(*key);
|
||||
// TODO(emilk): detect key repeats and mark the event accordingly!
|
||||
} else {
|
||||
keys_down.remove(key);
|
||||
}
|
||||
|
@ -262,6 +252,8 @@ impl InputState {
|
|||
}
|
||||
|
||||
/// Count presses of a key. If non-zero, the presses are consumed, so that this will only return non-zero once.
|
||||
///
|
||||
/// Includes key-repeat events.
|
||||
pub fn count_and_consume_key(&mut self, modifiers: Modifiers, key: Key) -> usize {
|
||||
let mut count = 0usize;
|
||||
|
||||
|
@ -284,6 +276,8 @@ impl InputState {
|
|||
}
|
||||
|
||||
/// Check for a key press. If found, `true` is returned and the key pressed is consumed, so that this will only return `true` once.
|
||||
///
|
||||
/// Includes key-repeat events.
|
||||
pub fn consume_key(&mut self, modifiers: Modifiers, key: Key) -> bool {
|
||||
self.count_and_consume_key(modifiers, key) > 0
|
||||
}
|
||||
|
@ -291,28 +285,31 @@ impl InputState {
|
|||
/// Check if the given shortcut has been pressed.
|
||||
///
|
||||
/// If so, `true` is returned and the key pressed is consumed, so that this will only return `true` once.
|
||||
///
|
||||
/// Includes key-repeat events.
|
||||
pub fn consume_shortcut(&mut self, shortcut: &KeyboardShortcut) -> bool {
|
||||
let KeyboardShortcut { modifiers, key } = *shortcut;
|
||||
self.consume_key(modifiers, key)
|
||||
}
|
||||
|
||||
/// Was the given key pressed this frame?
|
||||
///
|
||||
/// Includes key-repeat events.
|
||||
pub fn key_pressed(&self, desired_key: Key) -> bool {
|
||||
self.num_presses(desired_key) > 0
|
||||
}
|
||||
|
||||
/// How many times was the given key pressed this frame?
|
||||
///
|
||||
/// Includes key-repeat events.
|
||||
pub fn num_presses(&self, desired_key: Key) -> usize {
|
||||
self.events
|
||||
.iter()
|
||||
.filter(|event| {
|
||||
matches!(
|
||||
event,
|
||||
Event::Key {
|
||||
key,
|
||||
pressed: true,
|
||||
..
|
||||
} if *key == desired_key
|
||||
Event::Key { key, pressed: true, .. }
|
||||
if *key == desired_key
|
||||
)
|
||||
})
|
||||
.count()
|
||||
|
|
|
@ -919,10 +919,6 @@ fn events(
|
|||
modifiers,
|
||||
} => on_key_press(&mut cursor_range, text, galley, *key, modifiers),
|
||||
|
||||
Event::KeyRepeat { key, modifiers } => {
|
||||
on_key_press(&mut cursor_range, text, galley, *key, modifiers)
|
||||
}
|
||||
|
||||
Event::CompositionStart => {
|
||||
state.has_ime = true;
|
||||
None
|
||||
|
|
Loading…
Reference in a new issue