Implement Widget::overlay for Scrollable

This commit is contained in:
Héctor Ramón Jiménez 2020-04-18 19:28:05 +02:00
parent f7a370b6b9
commit ada8d7c77f
2 changed files with 27 additions and 5 deletions

View file

@ -1,7 +1,7 @@
//! Navigate an endless amount of content with a scrollbar.
use crate::{
column, layout, mouse, Align, Clipboard, Column, Element, Event, Hasher,
Layout, Length, Point, Rectangle, Size, Widget,
Layout, Length, Overlay, Point, Rectangle, Size, Vector, Widget,
};
use std::{f32, hash::Hash, u32};
@ -315,6 +315,22 @@ where
self.content.hash_layout(state)
}
fn overlay(
&mut self,
layout: Layout<'_>,
) -> Option<Overlay<'a, Message, Renderer>> {
self.content
.overlay(layout.children().next().unwrap())
.map(|overlay| {
let bounds = layout.bounds();
let content_layout = layout.children().next().unwrap();
let content_bounds = content_layout.bounds();
let offset = self.state.offset(bounds, content_bounds);
overlay.translate(Vector::new(0.0, -(offset as f32)))
})
}
}
/// The local state of a [`Scrollable`].