Export widget modules in iced_pure

... and fix collisions with the new `helpers`
This commit is contained in:
Héctor Ramón Jiménez 2022-03-16 17:37:19 +07:00
parent cdd906f563
commit d7100fd259
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
31 changed files with 378 additions and 232 deletions

153
pure/src/helpers.rs Normal file
View file

@ -0,0 +1,153 @@
use crate::widget;
use crate::Element;
use iced_native::Length;
use std::borrow::Cow;
use std::ops::RangeInclusive;
pub fn container<'a, Message, Renderer>(
content: impl Into<Element<'a, Message, Renderer>>,
) -> widget::Container<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
{
widget::Container::new(content)
}
pub fn column<'a, Message, Renderer>() -> widget::Column<'a, Message, Renderer>
{
widget::Column::new()
}
pub fn row<'a, Message, Renderer>() -> widget::Row<'a, Message, Renderer> {
widget::Row::new()
}
pub fn scrollable<'a, Message, Renderer>(
content: impl Into<Element<'a, Message, Renderer>>,
) -> widget::Scrollable<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
{
widget::Scrollable::new(content)
}
pub fn button<'a, Message, Renderer>(
content: impl Into<Element<'a, Message, Renderer>>,
) -> widget::Button<'a, Message, Renderer> {
widget::Button::new(content)
}
pub fn text<Renderer>(text: impl Into<String>) -> widget::Text<Renderer>
where
Renderer: iced_native::text::Renderer,
{
widget::Text::new(text)
}
pub fn checkbox<'a, Message, Renderer>(
label: impl Into<String>,
is_checked: bool,
f: impl Fn(bool) -> Message + 'a,
) -> widget::Checkbox<'a, Message, Renderer>
where
Renderer: iced_native::text::Renderer,
{
widget::Checkbox::new(is_checked, label, f)
}
pub fn radio<'a, Message, Renderer, V>(
label: impl Into<String>,
value: V,
selected: Option<V>,
on_click: impl FnOnce(V) -> Message,
) -> widget::Radio<'a, Message, Renderer>
where
Message: Clone,
Renderer: iced_native::text::Renderer,
V: Copy + Eq,
{
widget::Radio::new(value, label, selected, on_click)
}
pub fn toggler<'a, Message, Renderer>(
label: impl Into<Option<String>>,
is_checked: bool,
f: impl Fn(bool) -> Message + 'a,
) -> widget::Toggler<'a, Message, Renderer>
where
Renderer: iced_native::text::Renderer,
{
widget::Toggler::new(is_checked, label, f)
}
pub fn text_input<'a, Message, Renderer>(
placeholder: &str,
value: &str,
on_change: impl Fn(String) -> Message + 'a,
) -> widget::TextInput<'a, Message, Renderer>
where
Message: Clone,
Renderer: iced_native::text::Renderer,
{
widget::TextInput::new(placeholder, value, on_change)
}
pub fn slider<'a, Message, T>(
range: std::ops::RangeInclusive<T>,
value: T,
on_change: impl Fn(T) -> Message + 'a,
) -> widget::Slider<'a, T, Message>
where
Message: Clone,
T: Copy + From<u8> + std::cmp::PartialOrd,
{
widget::Slider::new(range, value, on_change)
}
pub fn pick_list<'a, Message, Renderer, T>(
options: impl Into<Cow<'a, [T]>>,
selected: Option<T>,
on_selected: impl Fn(T) -> Message + 'a,
) -> widget::PickList<'a, T, Message, Renderer>
where
T: ToString + Eq + 'static,
[T]: ToOwned<Owned = Vec<T>>,
Renderer: iced_native::text::Renderer,
{
widget::PickList::new(options, selected, on_selected)
}
pub fn image<Handle>(handle: impl Into<Handle>) -> widget::Image<Handle> {
widget::Image::new(handle.into())
}
pub fn horizontal_space(width: Length) -> widget::Space {
widget::Space::with_width(width)
}
pub fn vertical_space(height: Length) -> widget::Space {
widget::Space::with_height(height)
}
/// Creates a horizontal [`Rule`] with the given height.
pub fn horizontal_rule<'a>(height: u16) -> widget::Rule<'a> {
widget::Rule::horizontal(height)
}
/// Creates a vertical [`Rule`] with the given width.
pub fn vertical_rule<'a>(width: u16) -> widget::Rule<'a> {
widget::Rule::horizontal(width)
}
/// Creates a new [`ProgressBar`].
///
/// It expects:
/// * an inclusive range of possible values
/// * the current value of the [`ProgressBar`]
pub fn progress_bar<'a>(
range: RangeInclusive<f32>,
value: f32,
) -> widget::ProgressBar<'a> {
widget::ProgressBar::new(range, value)
}

View file

@ -1,9 +1,14 @@
pub mod helpers;
pub mod overlay;
pub mod widget;
pub(crate) mod flex;
pub use widget::*;
mod element;
pub use element::Element;
pub use helpers::*;
pub use widget::Widget;
use iced_native::event::{self, Event};
use iced_native::layout::{self, Layout};

View file

@ -1,4 +1,4 @@
use crate::Tree;
use crate::widget::Tree;
use iced_native::Layout;

View file

@ -1,29 +1,27 @@
pub mod button;
pub mod checkbox;
pub mod container;
pub mod image;
pub mod pane_grid;
pub mod pick_list;
pub mod progress_bar;
pub mod radio;
pub mod rule;
pub mod scrollable;
pub mod slider;
pub mod text_input;
pub mod toggler;
pub mod tree;
mod button;
mod checkbox;
mod column;
mod container;
mod element;
mod pick_list;
mod radio;
mod row;
mod scrollable;
mod slider;
mod space;
mod text;
mod text_input;
mod toggler;
pub use button::Button;
pub use checkbox::Checkbox;
pub use column::Column;
pub use container::Container;
pub use element::Element;
pub use image::Image;
pub use pane_grid::PaneGrid;
pub use pick_list::PickList;
@ -46,9 +44,6 @@ use iced_native::overlay;
use iced_native::renderer;
use iced_native::{Clipboard, Length, Point, Rectangle, Shell};
use std::borrow::Cow;
use std::ops::RangeInclusive;
pub trait Widget<Message, Renderer> {
fn width(&self) -> Length;
@ -117,149 +112,3 @@ pub trait Widget<Message, Renderer> {
None
}
}
pub fn container<'a, Message, Renderer>(
content: impl Into<Element<'a, Message, Renderer>>,
) -> Container<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
{
Container::new(content)
}
pub fn column<'a, Message, Renderer>() -> Column<'a, Message, Renderer> {
Column::new()
}
pub fn row<'a, Message, Renderer>() -> Row<'a, Message, Renderer> {
Row::new()
}
pub fn scrollable<'a, Message, Renderer>(
content: impl Into<Element<'a, Message, Renderer>>,
) -> Scrollable<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
{
Scrollable::new(content)
}
pub fn button<'a, Message, Renderer>(
content: impl Into<Element<'a, Message, Renderer>>,
) -> Button<'a, Message, Renderer> {
Button::new(content)
}
pub fn text<Renderer>(text: impl Into<String>) -> Text<Renderer>
where
Renderer: iced_native::text::Renderer,
{
Text::new(text)
}
pub fn checkbox<'a, Message, Renderer>(
label: impl Into<String>,
is_checked: bool,
f: impl Fn(bool) -> Message + 'a,
) -> Checkbox<'a, Message, Renderer>
where
Renderer: iced_native::text::Renderer,
{
Checkbox::new(is_checked, label, f)
}
pub fn radio<'a, Message, Renderer, V>(
label: impl Into<String>,
value: V,
selected: Option<V>,
on_click: impl FnOnce(V) -> Message,
) -> Radio<'a, Message, Renderer>
where
Message: Clone,
Renderer: iced_native::text::Renderer,
V: Copy + Eq,
{
Radio::new(value, label, selected, on_click)
}
pub fn toggler<'a, Message, Renderer>(
label: impl Into<Option<String>>,
is_checked: bool,
f: impl Fn(bool) -> Message + 'a,
) -> Toggler<'a, Message, Renderer>
where
Renderer: iced_native::text::Renderer,
{
Toggler::new(is_checked, label, f)
}
pub fn text_input<'a, Message, Renderer>(
placeholder: &str,
value: &str,
on_change: impl Fn(String) -> Message + 'a,
) -> TextInput<'a, Message, Renderer>
where
Message: Clone,
Renderer: iced_native::text::Renderer,
{
TextInput::new(placeholder, value, on_change)
}
pub fn slider<'a, Message, T>(
range: std::ops::RangeInclusive<T>,
value: T,
on_change: impl Fn(T) -> Message + 'a,
) -> Slider<'a, T, Message>
where
Message: Clone,
T: Copy + From<u8> + std::cmp::PartialOrd,
{
Slider::new(range, value, on_change)
}
pub fn pick_list<'a, Message, Renderer, T>(
options: impl Into<Cow<'a, [T]>>,
selected: Option<T>,
on_selected: impl Fn(T) -> Message + 'a,
) -> PickList<'a, T, Message, Renderer>
where
T: ToString + Eq + 'static,
[T]: ToOwned<Owned = Vec<T>>,
Renderer: iced_native::text::Renderer,
{
PickList::new(options, selected, on_selected)
}
pub fn image<Handle>(handle: impl Into<Handle>) -> Image<Handle> {
Image::new(handle.into())
}
pub fn horizontal_space(width: Length) -> Space {
Space::with_width(width)
}
pub fn vertical_space(height: Length) -> Space {
Space::with_height(height)
}
/// Creates a horizontal [`Rule`] with the given height.
pub fn horizontal_rule<'a>(height: u16) -> Rule<'a> {
Rule::horizontal(height)
}
/// Creates a vertical [`Rule`] with the given width.
pub fn vertical_rule<'a>(width: u16) -> Rule<'a> {
Rule::horizontal(width)
}
/// Creates a new [`ProgressBar`].
///
/// It expects:
/// * an inclusive range of possible values
/// * the current value of the [`ProgressBar`]
pub fn progress_bar<'a>(
range: RangeInclusive<f32>,
value: f32,
) -> ProgressBar<'a> {
ProgressBar::new(range, value)
}

View file

@ -1,6 +1,6 @@
use crate::overlay;
use crate::widget::tree::{self, Tree};
use crate::widget::{Element, Widget};
use crate::{Element, Widget};
use iced_native::event::{self, Event};
use iced_native::layout;
@ -10,9 +10,10 @@ use iced_native::widget::button;
use iced_native::{
Clipboard, Layout, Length, Padding, Point, Rectangle, Shell,
};
use iced_style::button::StyleSheet;
pub use button::State;
pub use iced_style::button::{Style, StyleSheet};
use button::State;
pub struct Button<'a, Message, Renderer> {
content: Element<'a, Message, Renderer>,

View file

@ -1,4 +1,5 @@
use crate::{Element, Tree, Widget};
use crate::widget::Tree;
use crate::{Element, Widget};
use iced_native::event::{self, Event};
use iced_native::layout::{self, Layout};
@ -7,7 +8,7 @@ use iced_native::renderer;
use iced_native::text;
use iced_native::{Clipboard, Length, Point, Rectangle, Shell};
pub use iced_native::widget::Checkbox;
pub use iced_native::widget::checkbox::{Checkbox, Style, StyleSheet};
impl<'a, Message, Renderer> Widget<Message, Renderer>
for Checkbox<'a, Message, Renderer>

View file

@ -1,6 +1,7 @@
use crate::flex;
use crate::overlay;
use crate::widget::{Element, Tree, Widget};
use crate::widget::Tree;
use crate::{Element, Widget};
use iced_native::event::{self, Event};
use iced_native::layout::{self, Layout};

View file

@ -1,5 +1,6 @@
//! Decorate content and apply alignment.
use crate::{Element, Tree, Widget};
use crate::widget::Tree;
use crate::{Element, Widget};
use iced_native::alignment;
use iced_native::event::{self, Event};

View file

@ -54,7 +54,8 @@ pub use iced_style::pane_grid::{Line, StyleSheet};
/// ## Example
///
/// ```
/// # use iced_pure::widget::{pane_grid, text};
/// # use iced_pure::widget::pane_grid;
/// # use iced_pure::text;
/// #
/// # type PaneGrid<'a, Message> =
/// # iced_pure::widget::PaneGrid<'a, Message, iced_native::renderer::Null>;

View file

@ -1,4 +1,5 @@
use crate::{Element, Tree, Widget};
use crate::widget::Tree;
use crate::{Element, Widget};
use iced_native::event::{self, Event};
use iced_native::layout::{self, Layout};

View file

@ -1,4 +1,5 @@
use crate::{Element, Tree, Widget};
use crate::widget::Tree;
use crate::{Element, Widget};
use iced_native::event::{self, Event};
use iced_native::layout::{self, Layout};
@ -7,7 +8,7 @@ use iced_native::renderer;
use iced_native::text;
use iced_native::{Clipboard, Length, Point, Rectangle, Shell};
pub use iced_native::widget::Radio;
pub use iced_native::widget::radio::{Radio, Style, StyleSheet};
impl<'a, Message, Renderer> Widget<Message, Renderer>
for Radio<'a, Message, Renderer>

View file

@ -1,6 +1,7 @@
use crate::flex;
use crate::overlay;
use crate::widget::{Element, Tree, Widget};
use crate::widget::Tree;
use crate::{Element, Widget};
use iced_native::event::{self, Event};
use iced_native::layout::{self, Layout};

View file

@ -1,4 +1,5 @@
use crate::{Element, Tree, Widget};
use crate::widget::Tree;
use crate::{Element, Widget};
use iced_native::event::{self, Event};
use iced_native::layout::{self, Layout};

View file

@ -9,7 +9,7 @@ use iced_native::renderer;
use iced_native::widget::scrollable;
use iced_native::{Clipboard, Length, Point, Rectangle, Shell, Vector};
pub use iced_style::scrollable::StyleSheet;
pub use iced_style::scrollable::{Scrollbar, Scroller, StyleSheet};
/// A widget that can vertically display an infinite amount of content with a
/// scrollbar.

View file

@ -1,4 +1,5 @@
use crate::{Element, Tree, Widget};
use crate::widget::Tree;
use crate::{Element, Widget};
use iced_native::event::{self, Event};
use iced_native::layout::{self, Layout};

View file

@ -1,4 +1,5 @@
use crate::{Element, Tree, Widget};
use crate::widget::Tree;
use crate::{Element, Widget};
use iced_native::layout::{self, Layout};
use iced_native::renderer;

View file

@ -1,5 +1,5 @@
use crate::widget::tree::{self, Tree};
use crate::widget::{Element, Widget};
use crate::{Element, Widget};
use iced_native::event::{self, Event};
use iced_native::layout::{self, Layout};
@ -9,7 +9,7 @@ use iced_native::text;
use iced_native::widget::text_input;
use iced_native::{Clipboard, Length, Padding, Point, Rectangle, Shell};
pub use iced_style::text_input::StyleSheet;
pub use iced_style::text_input::{Style, StyleSheet};
/// A field that can be filled with text.
///

View file

@ -1,4 +1,4 @@
use crate::widget::Element;
use crate::Element;
use std::any::{self, Any};