From f9dd5cbb099bbe44a57b6369be54a442363b7a8d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 12 Jul 2024 15:11:30 +0200 Subject: Introduce helper methods for alignment for all widgets --- widget/src/container.rs | 61 +++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'widget/src/container.rs') 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) -> 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, + ) -> 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, + ) -> 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 { -- cgit