Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose methods to change viewport alignment #1953

Merged
merged 3 commits into from
Jul 13, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions widget/src/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,22 @@ 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)
.max(0.0),
y: ((self.content_bounds.height - self.bounds.height).max(0.0) - y)
.max(0.0),
}
}

/// Returns the [`RelativeOffset`] of the current [`Viewport`].
pub fn relative_offset(&self) -> RelativeOffset {
let AbsoluteOffset { x, y } = self.absolute_offset();
Expand Down