Allow arrow keys to move away focus from a Slider (#3641)
This commit is contained in:
parent
9faf4b44ff
commit
37762f72ff
|
|
@ -1576,11 +1576,17 @@ pub struct EventFilter {
|
||||||
/// Default: `false`
|
/// Default: `false`
|
||||||
pub tab: bool,
|
pub tab: bool,
|
||||||
|
|
||||||
/// If `true`, pressing arrows will act on the widget,
|
/// If `true`, pressing horizontal arrows will act on the
|
||||||
/// and NOT move focus away from the focused widget.
|
/// widget, and NOT move focus away from the focused widget.
|
||||||
///
|
///
|
||||||
/// Default: `false`
|
/// Default: `false`
|
||||||
pub arrows: bool,
|
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 vertical_arrows: bool,
|
||||||
|
|
||||||
/// If `true`, pressing escape will act on the widget,
|
/// If `true`, pressing escape will act on the widget,
|
||||||
/// and NOT surrender focus from the focused widget.
|
/// and NOT surrender focus from the focused widget.
|
||||||
|
|
@ -1594,7 +1600,8 @@ impl Default for EventFilter {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
tab: false,
|
tab: false,
|
||||||
arrows: false,
|
horizontal_arrows: false,
|
||||||
|
vertical_arrows: false,
|
||||||
escape: false,
|
escape: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1605,10 +1612,8 @@ impl EventFilter {
|
||||||
if let Event::Key { key, .. } = event {
|
if let Event::Key { key, .. } = event {
|
||||||
match key {
|
match key {
|
||||||
crate::Key::Tab => self.tab,
|
crate::Key::Tab => self.tab,
|
||||||
crate::Key::ArrowUp
|
crate::Key::ArrowUp | crate::Key::ArrowDown => self.vertical_arrows,
|
||||||
| crate::Key::ArrowRight
|
crate::Key::ArrowRight | crate::Key::ArrowLeft => self.horizontal_arrows,
|
||||||
| crate::Key::ArrowDown
|
|
||||||
| crate::Key::ArrowLeft => self.arrows,
|
|
||||||
crate::Key::Escape => self.escape,
|
crate::Key::Escape => self.escape,
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -609,7 +609,13 @@ impl<'a> Slider<'a> {
|
||||||
m.set_focus_lock_filter(
|
m.set_focus_lock_filter(
|
||||||
response.id,
|
response.id,
|
||||||
EventFilter {
|
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()
|
..Default::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -118,8 +118,10 @@ impl<'t> TextEdit<'t> {
|
||||||
desired_width: None,
|
desired_width: None,
|
||||||
desired_height_rows: 4,
|
desired_height_rows: 4,
|
||||||
event_filter: EventFilter {
|
event_filter: EventFilter {
|
||||||
arrows: true, // moving the cursor is really important
|
// moving the cursor is really important
|
||||||
tab: false, // tab is used to change focus, not to insert a tab character
|
horizontal_arrows: true,
|
||||||
|
vertical_arrows: true,
|
||||||
|
tab: false, // tab is used to change focus, not to insert a tab character
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
cursor_at_end: true,
|
cursor_at_end: true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue