Merge branch 'master' into beacon

This commit is contained in:
Héctor Ramón Jiménez 2024-05-14 20:10:29 +02:00
commit a90b1fba89
No known key found for this signature in database
GPG key ID: 4C07CEC81AFA161F
14 changed files with 41 additions and 42 deletions

View file

@ -122,9 +122,6 @@ where
/// Sets the [`Container`] to fill all the available space.
///
/// This can be useful to quickly position content when chained with
/// alignment functions—like [`center`].
///
/// Calling this method is equivalent to chaining [`fill_x`] and
/// [`fill_y`].
///
@ -159,20 +156,14 @@ where
self
}
/// Sets the [`Container`] to fill the available space in the horizontal axis
/// and centers its contents there.
pub fn center_x(mut self) -> Self {
self.width = Length::Fill;
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)
}
/// Sets the [`Container`] to fill the available space in the vertical axis
/// and centers its contents there.
pub fn center_y(mut self) -> Self {
self.height = Length::Fill;
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
@ -182,8 +173,10 @@ where
///
/// [`center_x`]: Self::center_x
/// [`center_y`]: Self::center_y
pub fn center(self) -> Self {
self.center_x().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

View file

@ -84,9 +84,10 @@ where
///
/// This is equivalent to:
/// ```rust,no_run
/// # use iced_widget::core::Length;
/// # use iced_widget::Container;
/// # fn container<A>(x: A) -> Container<'static, ()> { unreachable!() }
/// let centered = container("Centered!").center();
/// let centered = container("Centered!").center(Length::Fill);
/// ```
///
/// [`Container`]: crate::Container
@ -97,7 +98,7 @@ where
Theme: container::Catalog + 'a,
Renderer: core::Renderer,
{
container(content).fill().center()
container(content).center(Length::Fill)
}
/// Creates a new [`Column`] with the given children.