Add modifiers
to KeyPressEvent
in pane_grid
This commit is contained in:
parent
6f9cf6c70d
commit
1cd1582506
@ -115,11 +115,11 @@ impl Sandbox for Example {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_hotkey(key_code: keyboard::KeyCode) -> Option<Message> {
|
||||
fn handle_hotkey(event: pane_grid::KeyPressEvent) -> Option<Message> {
|
||||
use keyboard::KeyCode;
|
||||
use pane_grid::{Axis, Direction};
|
||||
|
||||
let direction = match key_code {
|
||||
let direction = match event.key_code {
|
||||
KeyCode::Up => Some(Direction::Up),
|
||||
KeyCode::Down => Some(Direction::Down),
|
||||
KeyCode::Left => Some(Direction::Left),
|
||||
@ -127,7 +127,7 @@ fn handle_hotkey(key_code: keyboard::KeyCode) -> Option<Message> {
|
||||
_ => None,
|
||||
};
|
||||
|
||||
match key_code {
|
||||
match event.key_code {
|
||||
KeyCode::V => Some(Message::SplitFocused(Axis::Vertical)),
|
||||
KeyCode::H => Some(Message::SplitFocused(Axis::Horizontal)),
|
||||
KeyCode::W => Some(Message::CloseFocused),
|
||||
|
@ -28,7 +28,7 @@ pub struct PaneGrid<'a, Message, Renderer> {
|
||||
modifier_keys: keyboard::ModifiersState,
|
||||
on_drag: Option<Box<dyn Fn(DragEvent) -> Message>>,
|
||||
on_resize: Option<Box<dyn Fn(ResizeEvent) -> Message>>,
|
||||
on_key_press: Option<Box<dyn Fn(keyboard::KeyCode) -> Option<Message>>>,
|
||||
on_key_press: Option<Box<dyn Fn(KeyPressEvent) -> Option<Message>>>,
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
|
||||
@ -129,7 +129,7 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
|
||||
|
||||
pub fn on_key_press(
|
||||
mut self,
|
||||
f: impl Fn(keyboard::KeyCode) -> Option<Message> + 'static,
|
||||
f: impl Fn(KeyPressEvent) -> Option<Message> + 'static,
|
||||
) -> Self {
|
||||
self.on_key_press = Some(Box::new(f));
|
||||
self
|
||||
@ -186,6 +186,12 @@ pub struct ResizeEvent {
|
||||
pub ratio: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct KeyPressEvent {
|
||||
pub key_code: keyboard::KeyCode,
|
||||
pub modifiers: keyboard::ModifiersState,
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> Widget<Message, Renderer>
|
||||
for PaneGrid<'a, Message, Renderer>
|
||||
where
|
||||
@ -369,7 +375,12 @@ where
|
||||
if state == ButtonState::Pressed {
|
||||
if let Some(_) = self.state.idle_pane() {
|
||||
if modifiers == self.modifier_keys {
|
||||
if let Some(message) = on_key_press(key_code) {
|
||||
if let Some(message) =
|
||||
on_key_press(KeyPressEvent {
|
||||
key_code,
|
||||
modifiers,
|
||||
})
|
||||
{
|
||||
messages.push(message);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user