diff options
author | 2023-07-13 03:14:13 +0200 | |
---|---|---|
committer | 2023-07-13 03:14:13 +0200 | |
commit | fca8373516cdaefcb8595b4d544407792a4cfcc0 (patch) | |
tree | 05fb413e814c62ef343e4d21e242e9c954e8ecd4 /widget | |
parent | 21bd51426d900e271206f314e0c915dd41065521 (diff) | |
parent | d36758405789d6a305d978eefb46a1ca90d141d2 (diff) | |
download | iced-fca8373516cdaefcb8595b4d544407792a4cfcc0.tar.gz iced-fca8373516cdaefcb8595b4d544407792a4cfcc0.tar.bz2 iced-fca8373516cdaefcb8595b4d544407792a4cfcc0.zip |
Merge pull request #1953 from tarkah/feat/viewport-translation
Expose methods to change viewport alignment
Diffstat (limited to '')
-rw-r--r-- | widget/src/scrollable.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 88746ac4..e0aeeebd 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -1095,6 +1095,20 @@ impl Viewport { AbsoluteOffset { x, y } } + /// Returns the [`AbsoluteOffset`] of the current [`Viewport`], but with its + /// alignment reversed. + /// + /// This method can be useful to switch the alignment of a [`Scrollable`] + /// while maintaining its scrolling position. + pub fn absolute_offset_reversed(&self) -> AbsoluteOffset { + let AbsoluteOffset { x, y } = self.absolute_offset(); + + AbsoluteOffset { + x: (self.content_bounds.width - self.bounds.width).max(0.0) - x, + y: (self.content_bounds.height - self.bounds.height).max(0.0) - y, + } + } + /// Returns the [`RelativeOffset`] of the current [`Viewport`]. pub fn relative_offset(&self) -> RelativeOffset { let AbsoluteOffset { x, y } = self.absolute_offset(); |