From bec3ca56c305bfcf2e1d4305c9175824b9e40e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 11 Jul 2024 04:37:03 +0200 Subject: [PATCH] Add `align_x` and `align_y` helpers to `Scrollable` --- widget/src/scrollable.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 3ff1f8a17a..62f8fcfeb2 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -109,6 +109,32 @@ where self } + /// Inverts the alignment of the horizontal direction of the [`Scrollable`], if applicable. + pub fn align_x(mut self, alignment: Alignment) -> Self { + match &mut self.direction { + Direction::Horizontal(horizontal) + | Direction::Both { horizontal, .. } => { + horizontal.alignment = alignment; + } + Direction::Vertical(_) => {} + } + + self + } + + /// Sets the alignment of the vertical direction of the [`Scrollable`], if applicable. + pub fn align_y(mut self, alignment: Alignment) -> Self { + match &mut self.direction { + Direction::Vertical(vertical) + | Direction::Both { vertical, .. } => { + vertical.alignment = alignment; + } + Direction::Horizontal(_) => {} + } + + self + } + /// Sets the style of this [`Scrollable`]. #[must_use] pub fn style(mut self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self