summaryrefslogtreecommitdiffstats
path: root/widget/src/container.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-12 15:11:30 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-12 15:14:43 +0200
commitf9dd5cbb099bbe44a57b6369be54a442363b7a8d (patch)
treefe16084bc47faadc32d698aa446ea202f7949a4c /widget/src/container.rs
parentbe06060117da061ad8cad94ab0830c06def6b147 (diff)
downloadiced-f9dd5cbb099bbe44a57b6369be54a442363b7a8d.tar.gz
iced-f9dd5cbb099bbe44a57b6369be54a442363b7a8d.tar.bz2
iced-f9dd5cbb099bbe44a57b6369be54a442363b7a8d.zip
Introduce helper methods for alignment for all widgets
Diffstat (limited to 'widget/src/container.rs')
-rw-r--r--widget/src/container.rs61
1 files changed, 39 insertions, 22 deletions
diff --git a/widget/src/container.rs b/widget/src/container.rs
index 08d5cb17..adfe347c 100644
--- a/widget/src/container.rs
+++ b/widget/src/container.rs
@@ -94,27 +94,19 @@ where
/// Sets the [`Container`] to fill the available space in the horizontal axis.
///
- /// This can be useful to quickly position content when chained with
- /// alignment functions—like [`center_x`].
- ///
/// Calling this method is equivalent to calling [`width`] with a
/// [`Length::Fill`].
///
- /// [`center_x`]: Self::center_x
/// [`width`]: Self::width
pub fn fill_x(self) -> Self {
self.width(Length::Fill)
}
- /// Sets the [`Container`] to fill the available space in the vetical axis.
- ///
- /// This can be useful to quickly position content when chained with
- /// alignment functions—like [`center_y`].
+ /// Sets the [`Container`] to fill the available space in the vertical axis.
///
/// Calling this method is equivalent to calling [`height`] with a
/// [`Length::Fill`].
///
- /// [`center_y`]: Self::center_x
/// [`height`]: Self::height
pub fn fill_y(self) -> Self {
self.height(Length::Fill)
@@ -125,7 +117,6 @@ where
/// Calling this method is equivalent to chaining [`fill_x`] and
/// [`fill_y`].
///
- /// [`center`]: Self::center
/// [`fill_x`]: Self::fill_x
/// [`fill_y`]: Self::fill_y
pub fn fill(self) -> Self {
@@ -144,18 +135,6 @@ where
self
}
- /// Sets the content alignment for the horizontal axis of the [`Container`].
- pub fn align_x(mut self, alignment: alignment::Horizontal) -> Self {
- self.horizontal_alignment = alignment;
- self
- }
-
- /// Sets the content alignment for the vertical axis of the [`Container`].
- pub fn align_y(mut self, alignment: alignment::Vertical) -> Self {
- self.vertical_alignment = alignment;
- self
- }
-
/// Sets the width of the [`Container`] and centers its contents horizontally.
pub fn center_x(self, width: impl Into<Length>) -> Self {
self.width(width).align_x(alignment::Horizontal::Center)
@@ -179,6 +158,44 @@ where
self.center_x(length).center_y(length)
}
+ /// Aligns the contents of the [`Container`] to the left.
+ pub fn align_left(self) -> Self {
+ self.align_x(alignment::left())
+ }
+
+ /// Aligns the contents of the [`Container`] to the right.
+ pub fn align_right(self) -> Self {
+ self.align_x(alignment::right())
+ }
+
+ /// Aligns the contents of the [`Container`] to the top.
+ pub fn align_top(self) -> Self {
+ self.align_y(alignment::top())
+ }
+
+ /// Aligns the contents of the [`Container`] to the bottom.
+ pub fn align_bottom(self) -> Self {
+ self.align_y(alignment::bottom())
+ }
+
+ /// Sets the content alignment for the horizontal axis of the [`Container`].
+ pub fn align_x(
+ mut self,
+ alignment: impl Into<alignment::Horizontal>,
+ ) -> Self {
+ self.horizontal_alignment = alignment.into();
+ self
+ }
+
+ /// Sets the content alignment for the vertical axis of the [`Container`].
+ pub fn align_y(
+ mut self,
+ alignment: impl Into<alignment::Vertical>,
+ ) -> Self {
+ self.vertical_alignment = alignment.into();
+ self
+ }
+
/// Sets whether the contents of the [`Container`] should be clipped on
/// overflow.
pub fn clip(mut self, clip: bool) -> Self {