diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/src/widget/scrollable.rs | 28 | 
1 files changed, 26 insertions, 2 deletions
| diff --git a/core/src/widget/scrollable.rs b/core/src/widget/scrollable.rs index dd62b658..4e5c4ad0 100644 --- a/core/src/widget/scrollable.rs +++ b/core/src/widget/scrollable.rs @@ -1,4 +1,4 @@ -use crate::{Align, Column, Justify, Length}; +use crate::{Align, Column, Justify, Length, Rectangle};  #[derive(Debug)]  pub struct Scrollable<'a, Element> { @@ -112,11 +112,35 @@ impl<'a, Element> Scrollable<'a, Element> {  #[derive(Debug, Clone, Copy, Default)]  pub struct State { -    pub offset: u32, +    offset: u32,  }  impl State {      pub fn new() -> Self {          State::default()      } + +    pub fn scroll( +        &mut self, +        delta_y: f32, +        bounds: Rectangle, +        content_bounds: Rectangle, +    ) { +        if bounds.height >= content_bounds.height { +            return; +        } + +        // TODO: Configurable speed (?) +        self.offset = (self.offset as i32 - delta_y.round() as i32 * 15) +            .max(0) +            .min((content_bounds.height - bounds.height) as i32) +            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) +    }  } | 
