summaryrefslogtreecommitdiffstats
path: root/native/src/widget/scrollable.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-12-15 06:13:19 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-12-15 06:13:19 +0100
commit09110a93b06ae33af6870b4aded8637748cecace (patch)
tree64f4d9a4dde51ef44ea47f94c2079e5346df4c6c /native/src/widget/scrollable.rs
parenta42b3c6998274e75fd10f5ff3cecbdb37b9e3895 (diff)
parent36bdc0be1a0f959c84c18286b85c1ab51be330e6 (diff)
downloadiced-09110a93b06ae33af6870b4aded8637748cecace.tar.gz
iced-09110a93b06ae33af6870b4aded8637748cecace.tar.bz2
iced-09110a93b06ae33af6870b4aded8637748cecace.zip
Merge branch 'ios-support-wip' into feature/touch-support
Diffstat (limited to '')
-rw-r--r--native/src/widget/scrollable.rs49
1 files changed, 46 insertions, 3 deletions
diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs
index e23ab06a..8c321ee5 100644
--- a/native/src/widget/scrollable.rs
+++ b/native/src/widget/scrollable.rs
@@ -4,6 +4,7 @@ use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::overlay;
+use crate::touch::{self, Touch};
use crate::{
Align, Clipboard, Column, Element, Hasher, Layout, Length, Point,
Rectangle, Size, Vector, Widget,
@@ -229,6 +230,26 @@ where
return event::Status::Captured;
}
+ Event::Touch(Touch { phase, .. }) => match phase {
+ touch::Phase::Started => {
+ self.state.scroll_box_touched_at =
+ Some(cursor_position);
+ }
+ touch::Phase::Moved => {
+ if let Some(scroll_box_touched_at) =
+ self.state.scroll_box_touched_at
+ {
+ let delta =
+ cursor_position.y - scroll_box_touched_at.y;
+ self.state.scroll(delta, bounds, content_bounds);
+ self.state.scroll_box_touched_at =
+ Some(cursor_position);
+ }
+ }
+ touch::Phase::Ended | touch::Phase::Canceled => {
+ self.state.scroll_box_touched_at = None;
+ }
+ },
_ => {}
}
}
@@ -237,12 +258,24 @@ where
match event {
Event::Mouse(mouse::Event::ButtonReleased(
mouse::Button::Left,
- )) => {
+ ))
+ | Event::Touch(Touch {
+ phase: touch::Phase::Ended,
+ ..
+ })
+ | Event::Touch(Touch {
+ phase: touch::Phase::Canceled,
+ ..
+ }) => {
self.state.scroller_grabbed_at = None;
return event::Status::Captured;
}
- Event::Mouse(mouse::Event::CursorMoved { .. }) => {
+ Event::Mouse(mouse::Event::CursorMoved { .. })
+ | Event::Touch(Touch {
+ phase: touch::Phase::Moved,
+ ..
+ }) => {
if let (Some(scrollbar), Some(scroller_grabbed_at)) =
(scrollbar, self.state.scroller_grabbed_at)
{
@@ -264,7 +297,11 @@ where
match event {
Event::Mouse(mouse::Event::ButtonPressed(
mouse::Button::Left,
- )) => {
+ ))
+ | Event::Touch(Touch {
+ phase: touch::Phase::Started,
+ ..
+ }) => {
if let Some(scrollbar) = scrollbar {
if let Some(scroller_grabbed_at) =
scrollbar.grab_scroller(cursor_position)
@@ -385,6 +422,7 @@ where
#[derive(Debug, Clone, Copy, Default)]
pub struct State {
scroller_grabbed_at: Option<f32>,
+ scroll_box_touched_at: Option<Point>,
offset: f32,
}
@@ -439,6 +477,11 @@ impl State {
pub fn is_scroller_grabbed(&self) -> bool {
self.scroller_grabbed_at.is_some()
}
+
+ /// Returns whether the scroll box is currently touched or not.
+ pub fn is_scroll_box_touched(&self) -> bool {
+ self.scroll_box_touched_at.is_some()
+ }
}
/// The scrollbar of a [`Scrollable`].