Skip to content
Open
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
4 changes: 4 additions & 0 deletions core/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Handle events of a user interface.
use crate::clipboard;
use crate::gesture;
use crate::input_method;
use crate::keyboard;
use crate::mouse;
Expand Down Expand Up @@ -31,6 +32,9 @@ pub enum Event {

/// A clipboard event
Clipboard(clipboard::Event),

/// A gesture event
Gesture(gesture::Event),
}

/// The status of an [`Event`] after being processed.
Expand Down
60 changes: 60 additions & 0 deletions core/src/gesture.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! Handle gesture events

/// A gesture event.
///
/// _**Note:** This type is largely incomplete! If you need to track
/// additional events, feel free to [open an issue] and share your use case!_
///
/// [open an issue]: https://github.com/iced-rs/iced/issues
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Event {
/// N-finger pan gesture
/// Only available on **Wayland**.
Pan {
/// Change in pixels of pan gesture from last update.
delta: Delta,
/// Describes touch-screen input state.
phase: Phase,
},
/// Two-finger pinch gesture, often used for magnification.
/// Only available on **macOS**, and **Wayland**.
Pinch {
/// Pinch delta. Positive values indicate magnification (zooming in).
delta: f64,
/// Describes touch-screen input state.
phase: Phase,
},
/// Two-finger rotation gesture.
/// Only available on **macOS** and **Wayland**.
Rotate {
/// Rotation delta. Positive delta values indicate rotation counterclockwise.
delta: f32,
/// Describes touch-screen input state.
phase: Phase,
},
/// Double tap gesture.
/// Only available on **macOS 10.8** and later.
DoubleTap,
}

/// Change in pixels of pan gesture from last update.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Delta {
/// Change in pixels of pan gesture in X axis from last update.
pub x: f32,
/// Change in pixels of pan gesture in Y axis from last update.
pub y: f32,
}

/// Describes gesture input state.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Phase {
/// Started
Started,
/// Moded
Moved,
/// Ended
Ended,
/// Cancelled
Cancelled,
}
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod border;
pub mod clipboard;
pub mod event;
pub mod font;
pub mod gesture;
pub mod gradient;
pub mod image;
pub mod input_method;
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,14 @@
//! }
//! }
//! } else {
//! Task::none()
//! Task::none()
//! }
//! }
//! Message::Conversation(message) => {
//! if let Screen::Conversation(conversation) = &mut state.screen {
//! conversation.update(message).map(Message::Conversation)
//! } else {
//! Task::none()
//! Task::none()
//! }
//! }
//! }
Expand Down Expand Up @@ -626,6 +626,11 @@ pub mod touch {
pub use crate::core::touch::{Event, Finger};
}

pub mod gestures {
//! Listen and react to gesture events.
pub use crate::core::gesture::{Delta, Event, Phase};
}

#[allow(hidden_glob_reexports)]
pub mod widget {
//! Use the built-in widgets or create your own.
Expand Down
46 changes: 46 additions & 0 deletions winit/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//!
//! [`winit`]: https://github.com/rust-windowing/winit
//! [`iced_runtime`]: https://github.com/iced-rs/iced/tree/master/runtime

use crate::core::gesture;
use crate::core::input_method;
use crate::core::keyboard;
use crate::core::mouse;
Expand Down Expand Up @@ -199,6 +201,50 @@ pub fn window_event(
}))
}
},
WindowEvent::PanGesture {
delta: physical_delta,
phase: touch_phase,
..
} => {
let phase = match touch_phase {
winit::event::TouchPhase::Started => gesture::Phase::Started,
winit::event::TouchPhase::Moved => gesture::Phase::Moved,
winit::event::TouchPhase::Ended => gesture::Phase::Ended,
winit::event::TouchPhase::Cancelled => gesture::Phase::Cancelled,
};
let delta = gesture::Delta {
x: physical_delta.x,
y: physical_delta.y,
};
Some(Event::Gesture(gesture::Event::Pan { delta, phase }))
}
WindowEvent::PinchGesture {
delta,
phase: touch_phase,
..
} => {
let phase = match touch_phase {
winit::event::TouchPhase::Started => gesture::Phase::Started,
winit::event::TouchPhase::Moved => gesture::Phase::Moved,
winit::event::TouchPhase::Ended => gesture::Phase::Ended,
winit::event::TouchPhase::Cancelled => gesture::Phase::Cancelled,
};
Some(Event::Gesture(gesture::Event::Pinch { delta, phase }))
}
WindowEvent::RotationGesture {
delta,
phase: touch_phase,
..
} => {
let phase = match touch_phase {
winit::event::TouchPhase::Started => gesture::Phase::Started,
winit::event::TouchPhase::Moved => gesture::Phase::Moved,
winit::event::TouchPhase::Ended => gesture::Phase::Ended,
winit::event::TouchPhase::Cancelled => gesture::Phase::Cancelled,
};
Some(Event::Gesture(gesture::Event::Rotate { delta, phase }))
}
WindowEvent::DoubleTapGesture { .. } => Some(Event::Gesture(gesture::Event::DoubleTap)),
// Ignore keyboard presses/releases during window focus/unfocus
WindowEvent::KeyboardInput { is_synthetic, .. } if is_synthetic => None,
WindowEvent::KeyboardInput { event, .. } => Some(Event::Keyboard({
Expand Down