diff options
Diffstat (limited to 'widget/src/container.rs')
| -rw-r--r-- | widget/src/container.rs | 67 | 
1 files changed, 59 insertions, 8 deletions
| diff --git a/widget/src/container.rs b/widget/src/container.rs index 21405722..51967707 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -92,6 +92,46 @@ where          self      } +    /// 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`]. +    /// +    /// 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) +    } + +    /// Sets the [`Container`] to fill all the available space. +    /// +    /// 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 { +        self.width(Length::Fill).height(Length::Fill) +    } +      /// Sets the maximum width of the [`Container`].      pub fn max_width(mut self, max_width: impl Into<Pixels>) -> Self {          self.max_width = max_width.into().0; @@ -116,16 +156,27 @@ where          self      } -    /// Centers the contents in the horizontal axis of the [`Container`]. -    pub fn center_x(mut self) -> Self { -        self.horizontal_alignment = alignment::Horizontal::Center; -        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)      } -    /// Centers the contents in the vertical axis of the [`Container`]. -    pub fn center_y(mut self) -> Self { -        self.vertical_alignment = alignment::Vertical::Center; -        self +    /// Sets the height of the [`Container`] and centers its contents vertically. +    pub fn center_y(self, height: impl Into<Length>) -> Self { +        self.height(height).align_y(alignment::Vertical::Center) +    } + +    /// Centers the contents in both the horizontal and vertical axes of the +    /// [`Container`]. +    /// +    /// This is equivalent to chaining [`center_x`] and [`center_y`]. +    /// +    /// [`center_x`]: Self::center_x +    /// [`center_y`]: Self::center_y +    pub fn center(self, length: impl Into<Length>) -> Self { +        let length = length.into(); + +        self.center_x(length).center_y(length)      }      /// Sets whether the contents of the [`Container`] should be clipped on | 
