Fix overlay translation for Scrollable in iced_pure

This commit is contained in:
Héctor Ramón Jiménez 2022-02-16 17:15:56 +07:00
parent 6e242fe0e5
commit 0ca066277a
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -7,7 +7,7 @@ use iced_native::layout::{self, Layout};
use iced_native::mouse;
use iced_native::renderer;
use iced_native::widget::scrollable;
use iced_native::{Clipboard, Hasher, Length, Point, Rectangle, Shell};
use iced_native::{Clipboard, Hasher, Length, Point, Rectangle, Shell, Vector};
pub use iced_style::scrollable::StyleSheet;
@ -238,11 +238,24 @@ where
layout: Layout<'_>,
renderer: &Renderer,
) -> Option<overlay::Element<'b, Message, Renderer>> {
self.content.as_widget_mut().overlay(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
)
self.content
.as_widget_mut()
.overlay(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
)
.map(|overlay| {
let bounds = layout.bounds();
let content_layout = layout.children().next().unwrap();
let content_bounds = content_layout.bounds();
let offset = tree
.state
.downcast_ref::<scrollable::State>()
.offset(bounds, content_bounds);
overlay.translate(Vector::new(0.0, -(offset as f32)))
})
}
}