summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-02-16 17:15:56 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-02-16 17:15:56 +0700
commit0ca066277a296469fff95bef48e8c23e1d2b375e (patch)
tree4a49fde8e021da2e06320feea812293b1e17d3af
parent6e242fe0e506f8086371a24f03e7fbe3a10ca2ae (diff)
downloadiced-0ca066277a296469fff95bef48e8c23e1d2b375e.tar.gz
iced-0ca066277a296469fff95bef48e8c23e1d2b375e.tar.bz2
iced-0ca066277a296469fff95bef48e8c23e1d2b375e.zip
Fix `overlay` translation for `Scrollable` in `iced_pure`
-rw-r--r--pure/src/widget/scrollable.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/pure/src/widget/scrollable.rs b/pure/src/widget/scrollable.rs
index 6653125e..8a206a6c 100644
--- a/pure/src/widget/scrollable.rs
+++ b/pure/src/widget/scrollable.rs
@@ -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)))
+ })
}
}