Expose function helpers to build widgets in pure::widget

`button("Hello")` is easier to write and read than
`Button::new("Hello")`.
This commit is contained in:
Héctor Ramón Jiménez 2022-02-11 18:42:15 +07:00
parent 66d69b5c9a
commit 43a7ad72ef
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
3 changed files with 25 additions and 7 deletions

View file

@ -71,3 +71,20 @@ pub trait Widget<Message, Renderer> {
event::Status::Ignored
}
}
pub fn column<Message, Renderer>() -> Column<Message, Renderer> {
Column::new()
}
pub fn button<Message, Renderer>(
content: impl Into<Element<Message, Renderer>>,
) -> Button<Message, Renderer> {
Button::new(content)
}
pub fn text<Renderer>(text: impl ToString) -> Text<Renderer>
where
Renderer: iced_native::text::Renderer,
{
Text::new(text)
}

View file

@ -24,9 +24,9 @@ where
impl<Renderer: text::Renderer> Text<Renderer> {
/// Create a new fragment of [`Text`] with the given contents.
pub fn new<T: Into<String>>(label: T) -> Self {
pub fn new<T: ToString>(label: T) -> Self {
Text {
content: label.into(),
content: label.to_string(),
size: None,
color: None,
font: Default::default(),