Skip to content

Commit

Permalink
Merge pull request #1953 from tarkah/feat/viewport-translation
Browse files Browse the repository at this point in the history
Expose methods to change viewport alignment
  • Loading branch information
hecrj authored Jul 13, 2023
2 parents 21bd514 + d367584 commit fca8373
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions widget/src/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fca8373

Please sign in to comment.