summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-29 05:09:54 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-29 05:09:54 +0100
commit29588f604af66fb4911f791c0c402fccd30ba64b (patch)
tree09cfc0049cdb9f80616bbb925a1b24672f5d2d06 /core
parent9dabbf78857c3a60583227d3aa2fa6e030f085d0 (diff)
downloadiced-29588f604af66fb4911f791c0c402fccd30ba64b.tar.gz
iced-29588f604af66fb4911f791c0c402fccd30ba64b.tar.bz2
iced-29588f604af66fb4911f791c0c402fccd30ba64b.zip
Implement scrollbar interactions! :tada:
Diffstat (limited to 'core')
-rw-r--r--core/src/widget/scrollable.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/core/src/widget/scrollable.rs b/core/src/widget/scrollable.rs
index 1bad8555..31a5abed 100644
--- a/core/src/widget/scrollable.rs
+++ b/core/src/widget/scrollable.rs
@@ -1,4 +1,4 @@
-use crate::{Align, Column, Length, Rectangle};
+use crate::{Align, Column, Length, Point, Rectangle};
#[derive(Debug)]
pub struct Scrollable<'a, Element> {
@@ -103,6 +103,7 @@ impl<'a, Element> Scrollable<'a, Element> {
#[derive(Debug, Clone, Copy, Default)]
pub struct State {
+ pub scrollbar_grabbed_at: Option<Point>,
offset: u32,
}
@@ -121,17 +122,30 @@ impl State {
return;
}
- // TODO: Configurable speed (?)
- self.offset = (self.offset as i32 - delta_y.round() as i32 * 15)
+ self.offset = (self.offset as i32 - delta_y.round() as i32)
.max(0)
.min((content_bounds.height - bounds.height) as i32)
as u32;
}
+ pub fn scroll_to(
+ &mut self,
+ percentage: f32,
+ bounds: Rectangle,
+ content_bounds: Rectangle,
+ ) {
+ self.offset = ((content_bounds.height - bounds.height) * percentage)
+ .max(0.0) as u32;
+ }
+
pub fn offset(&self, bounds: Rectangle, content_bounds: Rectangle) -> u32 {
let hidden_content =
(content_bounds.height - bounds.height).round() as u32;
self.offset.min(hidden_content).max(0)
}
+
+ pub fn is_scrollbar_grabbed(&self) -> bool {
+ self.scrollbar_grabbed_at.is_some()
+ }
}