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

Add align_x and align_y helpers to Scrollable #2499

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all 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
26 changes: 26 additions & 0 deletions widget/src/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading