From 43a7ad72ef070929278e6d03d98077ac267fe2a6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 11 Feb 2022 18:42:15 +0700 Subject: Expose function helpers to build widgets in `pure::widget` `button("Hello")` is easier to write and read than `Button::new("Hello")`. --- pure/src/widget.rs | 17 +++++++++++++++++ pure/src/widget/text.rs | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'pure') diff --git a/pure/src/widget.rs b/pure/src/widget.rs index bf63b999..7215e99e 100644 --- a/pure/src/widget.rs +++ b/pure/src/widget.rs @@ -71,3 +71,20 @@ pub trait Widget { event::Status::Ignored } } + +pub fn column() -> Column { + Column::new() +} + +pub fn button( + content: impl Into>, +) -> Button { + Button::new(content) +} + +pub fn text(text: impl ToString) -> Text +where + Renderer: iced_native::text::Renderer, +{ + Text::new(text) +} diff --git a/pure/src/widget/text.rs b/pure/src/widget/text.rs index e3a7d299..73ff71e2 100644 --- a/pure/src/widget/text.rs +++ b/pure/src/widget/text.rs @@ -24,9 +24,9 @@ where impl Text { /// Create a new fragment of [`Text`] with the given contents. - pub fn new>(label: T) -> Self { + pub fn new(label: T) -> Self { Text { - content: label.into(), + content: label.to_string(), size: None, color: None, font: Default::default(), -- cgit