diff options
Diffstat (limited to 'widget/src/helpers.rs')
-rw-r--r-- | widget/src/helpers.rs | 180 |
1 files changed, 177 insertions, 3 deletions
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs index 5a0f8107..17cf94cc 100644 --- a/widget/src/helpers.rs +++ b/widget/src/helpers.rs @@ -24,7 +24,7 @@ use crate::text_input::{self, TextInput}; use crate::toggler::{self, Toggler}; use crate::tooltip::{self, Tooltip}; use crate::vertical_slider::{self, VerticalSlider}; -use crate::{Column, MouseArea, Pin, Row, Space, Stack, Themer}; +use crate::{Column, MouseArea, Pin, Pop, Row, Space, Stack, Themer}; use std::borrow::Borrow; use std::ops::RangeInclusive; @@ -232,10 +232,10 @@ where /// /// This is equivalent to: /// ```rust,no_run -/// # use iced_widget::core::Length; +/// # use iced_widget::core::Length::Fill; /// # use iced_widget::Container; /// # fn container<A>(x: A) -> Container<'static, ()> { unreachable!() } -/// let centered = container("Centered!").center(Length::Fill); +/// let center = container("Center!").center(Fill); /// ``` /// /// [`Container`]: crate::Container @@ -249,6 +249,166 @@ where container(content).center(Length::Fill) } +/// Creates a new [`Container`] that fills all the available space +/// horizontally and centers its contents inside. +/// +/// This is equivalent to: +/// ```rust,no_run +/// # use iced_widget::core::Length::Fill; +/// # use iced_widget::Container; +/// # fn container<A>(x: A) -> Container<'static, ()> { unreachable!() } +/// let center_x = container("Horizontal Center!").center_x(Fill); +/// ``` +/// +/// [`Container`]: crate::Container +pub fn center_x<'a, Message, Theme, Renderer>( + content: impl Into<Element<'a, Message, Theme, Renderer>>, +) -> Container<'a, Message, Theme, Renderer> +where + Theme: container::Catalog + 'a, + Renderer: core::Renderer, +{ + container(content).center_x(Length::Fill) +} + +/// Creates a new [`Container`] that fills all the available space +/// vertically and centers its contents inside. +/// +/// This is equivalent to: +/// ```rust,no_run +/// # use iced_widget::core::Length::Fill; +/// # use iced_widget::Container; +/// # fn container<A>(x: A) -> Container<'static, ()> { unreachable!() } +/// let center_y = container("Vertical Center!").center_y(Fill); +/// ``` +/// +/// [`Container`]: crate::Container +pub fn center_y<'a, Message, Theme, Renderer>( + content: impl Into<Element<'a, Message, Theme, Renderer>>, +) -> Container<'a, Message, Theme, Renderer> +where + Theme: container::Catalog + 'a, + Renderer: core::Renderer, +{ + container(content).center_y(Length::Fill) +} + +/// Creates a new [`Container`] that fills all the available space +/// horizontally and right-aligns its contents inside. +/// +/// This is equivalent to: +/// ```rust,no_run +/// # use iced_widget::core::Length::Fill; +/// # use iced_widget::Container; +/// # fn container<A>(x: A) -> Container<'static, ()> { unreachable!() } +/// let right = container("Right!").align_right(Fill); +/// ``` +/// +/// [`Container`]: crate::Container +pub fn right<'a, Message, Theme, Renderer>( + content: impl Into<Element<'a, Message, Theme, Renderer>>, +) -> Container<'a, Message, Theme, Renderer> +where + Theme: container::Catalog + 'a, + Renderer: core::Renderer, +{ + container(content).align_right(Length::Fill) +} + +/// Creates a new [`Container`] that fills all the available space +/// and aligns its contents inside to the right center. +/// +/// This is equivalent to: +/// ```rust,no_run +/// # use iced_widget::core::Length::Fill; +/// # use iced_widget::Container; +/// # fn container<A>(x: A) -> Container<'static, ()> { unreachable!() } +/// let right_center = container("Bottom Center!").align_right(Fill).center_y(Fill); +/// ``` +/// +/// [`Container`]: crate::Container +pub fn right_center<'a, Message, Theme, Renderer>( + content: impl Into<Element<'a, Message, Theme, Renderer>>, +) -> Container<'a, Message, Theme, Renderer> +where + Theme: container::Catalog + 'a, + Renderer: core::Renderer, +{ + container(content) + .align_right(Length::Fill) + .center_y(Length::Fill) +} + +/// Creates a new [`Container`] that fills all the available space +/// vertically and bottom-aligns its contents inside. +/// +/// This is equivalent to: +/// ```rust,no_run +/// # use iced_widget::core::Length::Fill; +/// # use iced_widget::Container; +/// # fn container<A>(x: A) -> Container<'static, ()> { unreachable!() } +/// let bottom = container("Bottom!").align_bottom(Fill); +/// ``` +/// +/// [`Container`]: crate::Container +pub fn bottom<'a, Message, Theme, Renderer>( + content: impl Into<Element<'a, Message, Theme, Renderer>>, +) -> Container<'a, Message, Theme, Renderer> +where + Theme: container::Catalog + 'a, + Renderer: core::Renderer, +{ + container(content).align_bottom(Length::Fill) +} + +/// Creates a new [`Container`] that fills all the available space +/// and aligns its contents inside to the bottom center. +/// +/// This is equivalent to: +/// ```rust,no_run +/// # use iced_widget::core::Length::Fill; +/// # use iced_widget::Container; +/// # fn container<A>(x: A) -> Container<'static, ()> { unreachable!() } +/// let bottom_center = container("Bottom Center!").center_x(Fill).align_bottom(Fill); +/// ``` +/// +/// [`Container`]: crate::Container +pub fn bottom_center<'a, Message, Theme, Renderer>( + content: impl Into<Element<'a, Message, Theme, Renderer>>, +) -> Container<'a, Message, Theme, Renderer> +where + Theme: container::Catalog + 'a, + Renderer: core::Renderer, +{ + container(content) + .center_x(Length::Fill) + .align_bottom(Length::Fill) +} + +/// Creates a new [`Container`] that fills all the available space +/// and aligns its contents inside to the bottom right corner. +/// +/// This is equivalent to: +/// ```rust,no_run +/// # use iced_widget::core::Length::Fill; +/// # use iced_widget::Container; +/// # fn container<A>(x: A) -> Container<'static, ()> { unreachable!() } +/// let bottom_right = container("Bottom!").align_right(Fill).align_bottom(Fill); +/// ``` +/// +/// [`Container`]: crate::Container +pub fn bottom_right<'a, Message, Theme, Renderer>( + content: impl Into<Element<'a, Message, Theme, Renderer>>, +) -> Container<'a, Message, Theme, Renderer> +where + Theme: container::Catalog + 'a, + Renderer: core::Renderer, +{ + container(content) + .align_right(Length::Fill) + .align_bottom(Length::Fill) +} + /// Creates a new [`Pin`] widget with the given content. /// /// A [`Pin`] widget positions its contents at some fixed coordinates inside of its boundaries. @@ -810,6 +970,20 @@ where }) } +/// Creates a new [`Pop`] widget. +/// +/// A [`Pop`] widget can generate messages when it pops in and out of view. +/// It can even notify you with anticipation at a given distance! +pub fn pop<'a, Message, Theme, Renderer>( + content: impl Into<Element<'a, Message, Theme, Renderer>>, +) -> Pop<'a, Message, Theme, Renderer> +where + Renderer: core::Renderer, + Message: Clone, +{ + Pop::new(content) +} + /// Creates a new [`Scrollable`] with the provided content. /// /// Scrollables let users navigate an endless amount of content with a scrollbar. |