From 01c5004959c9b11f2580840f4553ad7d706f4564 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 11 Feb 2022 22:07:21 +0700 Subject: Allow pure widgets to borrow from `Application` data :tada: --- pure/src/widget/button.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'pure/src/widget/button.rs') diff --git a/pure/src/widget/button.rs b/pure/src/widget/button.rs index ece90811..198a3af9 100644 --- a/pure/src/widget/button.rs +++ b/pure/src/widget/button.rs @@ -13,17 +13,17 @@ use iced_style::button::StyleSheet; use std::any::Any; -pub struct Button { - content: Element, +pub struct Button<'a, Message, Renderer> { + content: Element<'a, Message, Renderer>, on_press: Option, - style_sheet: Box, + style_sheet: Box, width: Length, height: Length, padding: Padding, } -impl Button { - pub fn new(content: impl Into>) -> Self { +impl<'a, Message, Renderer> Button<'a, Message, Renderer> { + pub fn new(content: impl Into>) -> Self { Button { content: content.into(), on_press: None, @@ -40,7 +40,8 @@ impl Button { } } -impl Widget for Button +impl<'a, Message, Renderer> Widget + for Button<'a, Message, Renderer> where Message: 'static + Clone, Renderer: 'static + iced_native::Renderer, @@ -96,7 +97,7 @@ where fn on_event( &mut self, - tree: &mut Tree, + tree: &mut Tree, event: Event, layout: Layout<'_>, cursor_position: Point, @@ -162,7 +163,7 @@ where fn draw( &self, - tree: &Tree, + tree: &Tree, renderer: &mut Renderer, _style: &renderer::Style, layout: Layout<'_>, @@ -238,7 +239,7 @@ where fn mouse_interaction( &self, - _tree: &Tree, + _tree: &Tree, layout: Layout<'_>, cursor_position: Point, _viewport: &Rectangle, @@ -260,13 +261,13 @@ struct State { is_pressed: bool, } -impl Into> - for Button +impl<'a, Message, Renderer> Into> + for Button<'a, Message, Renderer> where Message: Clone + 'static, Renderer: iced_native::Renderer + 'static, { - fn into(self) -> Element { + fn into(self) -> Element<'a, Message, Renderer> { Element::new(self) } } -- cgit