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
|
## Unreleased
|
||||||
|
### Changed 🔧
|
||||||
|
* `InputState`: all press functions again include key repeates (like in egui 0.19) ([#2429](https://github.com/emilk/egui/pull/2429)).
|
||||||
|
|
||||||
### Fixed 🐛
|
### 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
|
## 0.20.0 - 2022-12-08 - AccessKit, prettier text, overlapping widgets
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! The input needed by egui.
|
//! The input needed by egui.
|
||||||
|
|
||||||
|
#![allow(deprecated)] // TODO(emilk): remove
|
||||||
|
|
||||||
use crate::emath::*;
|
use crate::emath::*;
|
||||||
|
|
||||||
/// What the integrations provides to egui at the start of each frame.
|
/// What the integrations provides to egui at the start of each frame.
|
||||||
|
@ -191,13 +193,9 @@ pub enum Event {
|
||||||
modifiers: Modifiers,
|
modifiers: Modifiers,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A key was repeated while pressed.
|
/// DEPRECATED - DO NOT USE
|
||||||
KeyRepeat {
|
#[deprecated = "Do not use"]
|
||||||
key: Key,
|
KeyRepeat { key: Key, modifiers: Modifiers },
|
||||||
|
|
||||||
/// The state of the modifier keys at the time of the event.
|
|
||||||
modifiers: Modifiers,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// The mouse or touch moved to a new place.
|
/// The mouse or touch moved to a new place.
|
||||||
PointerMoved(Pos2),
|
PointerMoved(Pos2),
|
||||||
|
|
|
@ -166,20 +166,10 @@ impl InputState {
|
||||||
let mut zoom_factor_delta = 1.0;
|
let mut zoom_factor_delta = 1.0;
|
||||||
for event in &mut new.events {
|
for event in &mut new.events {
|
||||||
match event {
|
match event {
|
||||||
Event::Key {
|
Event::Key { key, pressed, .. } => {
|
||||||
key,
|
|
||||||
pressed,
|
|
||||||
modifiers,
|
|
||||||
} => {
|
|
||||||
if *pressed {
|
if *pressed {
|
||||||
// We only retain presses that are novel (i.e. the first Press event, not those generated by key-repeat)
|
keys_down.insert(*key);
|
||||||
// key repeats are represented by KeyRepeat.
|
// TODO(emilk): detect key repeats and mark the event accordingly!
|
||||||
if !keys_down.insert(*key) {
|
|
||||||
*event = Event::KeyRepeat {
|
|
||||||
key: *key,
|
|
||||||
modifiers: *modifiers,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
keys_down.remove(key);
|
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.
|
/// 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 {
|
pub fn count_and_consume_key(&mut self, modifiers: Modifiers, key: Key) -> usize {
|
||||||
let mut count = 0usize;
|
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.
|
/// 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 {
|
pub fn consume_key(&mut self, modifiers: Modifiers, key: Key) -> bool {
|
||||||
self.count_and_consume_key(modifiers, key) > 0
|
self.count_and_consume_key(modifiers, key) > 0
|
||||||
}
|
}
|
||||||
|
@ -291,28 +285,31 @@ impl InputState {
|
||||||
/// Check if the given shortcut has been pressed.
|
/// 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.
|
/// 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 {
|
pub fn consume_shortcut(&mut self, shortcut: &KeyboardShortcut) -> bool {
|
||||||
let KeyboardShortcut { modifiers, key } = *shortcut;
|
let KeyboardShortcut { modifiers, key } = *shortcut;
|
||||||
self.consume_key(modifiers, key)
|
self.consume_key(modifiers, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Was the given key pressed this frame?
|
/// Was the given key pressed this frame?
|
||||||
|
///
|
||||||
|
/// Includes key-repeat events.
|
||||||
pub fn key_pressed(&self, desired_key: Key) -> bool {
|
pub fn key_pressed(&self, desired_key: Key) -> bool {
|
||||||
self.num_presses(desired_key) > 0
|
self.num_presses(desired_key) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// How many times was the given key pressed this frame?
|
/// How many times was the given key pressed this frame?
|
||||||
|
///
|
||||||
|
/// Includes key-repeat events.
|
||||||
pub fn num_presses(&self, desired_key: Key) -> usize {
|
pub fn num_presses(&self, desired_key: Key) -> usize {
|
||||||
self.events
|
self.events
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|event| {
|
.filter(|event| {
|
||||||
matches!(
|
matches!(
|
||||||
event,
|
event,
|
||||||
Event::Key {
|
Event::Key { key, pressed: true, .. }
|
||||||
key,
|
if *key == desired_key
|
||||||
pressed: true,
|
|
||||||
..
|
|
||||||
} if *key == desired_key
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.count()
|
.count()
|
||||||
|
|
|
@ -919,10 +919,6 @@ fn events(
|
||||||
modifiers,
|
modifiers,
|
||||||
} => on_key_press(&mut cursor_range, text, galley, *key, 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 => {
|
Event::CompositionStart => {
|
||||||
state.has_ime = true;
|
state.has_ime = true;
|
||||||
None
|
None
|
||||||
|
|
Loading…
Reference in a new issue