diff options
Diffstat (limited to 'pure/src/helpers.rs')
-rw-r--r-- | pure/src/helpers.rs | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/pure/src/helpers.rs b/pure/src/helpers.rs index 24f6dbaa..2c4a37be 100644 --- a/pure/src/helpers.rs +++ b/pure/src/helpers.rs @@ -1,3 +1,4 @@ +//! Helper functions to create pure widgets. use crate::widget; use crate::Element; @@ -5,6 +6,9 @@ use iced_native::Length; use std::borrow::Cow; use std::ops::RangeInclusive; +/// Creates a new [`Container`] with the provided content. +/// +/// [`Container`]: widget::Container pub fn container<'a, Message, Renderer>( content: impl Into<Element<'a, Message, Renderer>>, ) -> widget::Container<'a, Message, Renderer> @@ -14,15 +18,24 @@ where widget::Container::new(content) } +/// Creates a new [`Column`]. +/// +/// [`Column`]: widget::Column pub fn column<'a, Message, Renderer>() -> widget::Column<'a, Message, Renderer> { widget::Column::new() } +/// Creates a new [`Row`]. +/// +/// [`Row`]: widget::Row pub fn row<'a, Message, Renderer>() -> widget::Row<'a, Message, Renderer> { widget::Row::new() } +/// Creates a new [`Scrollable`] with the provided content. +/// +/// [`Scrollable`]: widget::Scrollable pub fn scrollable<'a, Message, Renderer>( content: impl Into<Element<'a, Message, Renderer>>, ) -> widget::Scrollable<'a, Message, Renderer> @@ -32,12 +45,33 @@ where widget::Scrollable::new(content) } +/// Creates a new [`Button`] with the provided content. +/// +/// [`Button`]: widget::Button pub fn button<'a, Message, Renderer>( content: impl Into<Element<'a, Message, Renderer>>, ) -> widget::Button<'a, Message, Renderer> { widget::Button::new(content) } +/// Creates a new [`Tooltip`] with the provided content, tooltip text, and [`tooltip::Position`]. +/// +/// [`Tooltip`]: widget::Tooltip +/// [`tooltip::Position`]: widget::tooltip::Position +pub fn tooltip<'a, Message, Renderer>( + content: impl Into<Element<'a, Message, Renderer>>, + tooltip: impl ToString, + position: widget::tooltip::Position, +) -> widget::Tooltip<'a, Message, Renderer> +where + Renderer: iced_native::text::Renderer, +{ + widget::Tooltip::new(content, tooltip, position) +} + +/// Creates a new [`Text`] widget with the provided content. +/// +/// [`Text`]: widget::Text pub fn text<Renderer>(text: impl Into<String>) -> widget::Text<Renderer> where Renderer: iced_native::text::Renderer, @@ -45,6 +79,9 @@ where widget::Text::new(text) } +/// Creates a new [`Checkbox`]. +/// +/// [`Checkbox`]: widget::Checkbox pub fn checkbox<'a, Message, Renderer>( label: impl Into<String>, is_checked: bool, @@ -56,6 +93,9 @@ where widget::Checkbox::new(is_checked, label, f) } +/// Creates a new [`Radio`]. +/// +/// [`Radio`]: widget::Radio pub fn radio<'a, Message, Renderer, V>( label: impl Into<String>, value: V, @@ -70,6 +110,9 @@ where widget::Radio::new(value, label, selected, on_click) } +/// Creates a new [`Toggler`]. +/// +/// [`Toggler`]: widget::Toggler pub fn toggler<'a, Message, Renderer>( label: impl Into<Option<String>>, is_checked: bool, @@ -81,6 +124,9 @@ where widget::Toggler::new(is_checked, label, f) } +/// Creates a new [`TextInput`]. +/// +/// [`TextInput`]: widget::TextInput pub fn text_input<'a, Message, Renderer>( placeholder: &str, value: &str, @@ -93,6 +139,9 @@ where widget::TextInput::new(placeholder, value, on_change) } +/// Creates a new [`Slider`]. +/// +/// [`Slider`]: widget::Slider pub fn slider<'a, Message, T>( range: std::ops::RangeInclusive<T>, value: T, @@ -105,6 +154,9 @@ where widget::Slider::new(range, value, on_change) } +/// Creates a new [`PickList`]. +/// +/// [`PickList`]: widget::PickList pub fn pick_list<'a, Message, Renderer, T>( options: impl Into<Cow<'a, [T]>>, selected: Option<T>, @@ -118,24 +170,37 @@ where widget::PickList::new(options, selected, on_selected) } +/// Creates a new [`Image`]. +/// +/// [`Image`]: widget::Image pub fn image<Handle>(handle: impl Into<Handle>) -> widget::Image<Handle> { widget::Image::new(handle.into()) } +/// Creates a new horizontal [`Space`] with the given [`Length`]. +/// +/// [`Space`]: widget::Space pub fn horizontal_space(width: Length) -> widget::Space { widget::Space::with_width(width) } +/// Creates a new vertical [`Space`] with the given [`Length`]. +/// +/// [`Space`]: widget::Space pub fn vertical_space(height: Length) -> widget::Space { widget::Space::with_height(height) } /// Creates a horizontal [`Rule`] with the given height. +/// +/// [`Rule`]: widget::Rule pub fn horizontal_rule<'a>(height: u16) -> widget::Rule<'a> { widget::Rule::horizontal(height) } /// Creates a vertical [`Rule`] with the given width. +/// +/// [`Rule`]: widget::Rule pub fn vertical_rule<'a>(width: u16) -> widget::Rule<'a> { widget::Rule::horizontal(width) } @@ -143,8 +208,10 @@ pub fn vertical_rule<'a>(width: u16) -> widget::Rule<'a> { /// Creates a new [`ProgressBar`]. /// /// It expects: -/// * an inclusive range of possible values -/// * the current value of the [`ProgressBar`] +/// * an inclusive range of possible values, and +/// * the current value of the [`ProgressBar`]. +/// +/// [`ProgressBar`]: widget::ProgressBar pub fn progress_bar<'a>( range: RangeInclusive<f32>, value: f32, |