Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arrow keys to move away focus from a Slider #3641

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions crates/egui/src/data/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,11 +1494,17 @@ pub struct EventFilter {
/// Default: `false`
pub tab: bool,

/// If `true`, pressing arrows will act on the widget,
/// and NOT move focus away from the focused widget.
/// If `true`, pressing horizontal arrows will act on the
/// widget, and NOT move focus away from the focused widget.
///
/// Default: `false`
pub horizontal_arrows: bool,

/// If `true`, pressing vertical arrows will act on the
/// widget, and NOT move focus away from the focused widget.
///
/// Default: `false`
pub arrows: bool,
pub vertical_arrows: bool,

/// If `true`, pressing escape will act on the widget,
/// and NOT surrender focus from the focused widget.
Expand All @@ -1512,7 +1518,8 @@ impl Default for EventFilter {
fn default() -> Self {
Self {
tab: false,
arrows: false,
horizontal_arrows: false,
vertical_arrows: false,
escape: false,
}
}
Expand All @@ -1523,10 +1530,8 @@ impl EventFilter {
if let Event::Key { key, .. } = event {
match key {
crate::Key::Tab => self.tab,
crate::Key::ArrowUp
| crate::Key::ArrowRight
| crate::Key::ArrowDown
| crate::Key::ArrowLeft => self.arrows,
crate::Key::ArrowUp | crate::Key::ArrowDown => self.vertical_arrows,
crate::Key::ArrowRight | crate::Key::ArrowLeft => self.horizontal_arrows,
crate::Key::Escape => self.escape,
_ => true,
}
Expand Down
8 changes: 7 additions & 1 deletion crates/egui/src/widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,13 @@ impl<'a> Slider<'a> {
m.set_focus_lock_filter(
response.id,
EventFilter {
arrows: true, // pressing arrows should not move focus to next widget
// pressing arrows in the orientation of the
// slider should not move focus to next widget
horizontal_arrows: matches!(
self.orientation,
SliderOrientation::Horizontal
),
vertical_arrows: matches!(self.orientation, SliderOrientation::Vertical),
..Default::default()
},
);
Expand Down
6 changes: 4 additions & 2 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ impl<'t> TextEdit<'t> {
desired_width: None,
desired_height_rows: 4,
event_filter: EventFilter {
arrows: true, // moving the cursor is really important
tab: false, // tab is used to change focus, not to insert a tab character
// moving the cursor is really important
horizontal_arrows: true,
vertical_arrows: true,
tab: false, // tab is used to change focus, not to insert a tab character
..Default::default()
},
cursor_at_end: true,
Expand Down
Loading