diff options
Diffstat (limited to 'widget/src/container.rs')
-rw-r--r-- | widget/src/container.rs | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/widget/src/container.rs b/widget/src/container.rs index 8b6638d4..e917471f 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -13,7 +13,7 @@ use crate::core::{ Padding, Pixels, Point, Rectangle, Shadow, Shell, Size, Theme, Vector, Widget, }; -use crate::runtime::Command; +use crate::runtime::Task; /// An element decorating some content. /// @@ -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 @@ -265,7 +258,7 @@ where tree: &mut Tree, layout: Layout<'_>, renderer: &Renderer, - operation: &mut dyn Operation<Message>, + operation: &mut dyn Operation<()>, ) { operation.container( self.id.as_ref().map(|id| &id.0), @@ -464,9 +457,9 @@ impl From<Id> for widget::Id { } } -/// Produces a [`Command`] that queries the visible screen bounds of the +/// Produces a [`Task`] that queries the visible screen bounds of the /// [`Container`] with the given [`Id`]. -pub fn visible_bounds(id: Id) -> Command<Option<Rectangle>> { +pub fn visible_bounds(id: Id) -> Task<Option<Rectangle>> { struct VisibleBounds { target: widget::Id, depth: usize, @@ -545,7 +538,7 @@ pub fn visible_bounds(id: Id) -> Command<Option<Rectangle>> { } } - Command::widget(VisibleBounds { + Task::widget(VisibleBounds { target: id.into(), depth: 0, scrollables: Vec::new(), |