diff --git a/Cargo.toml b/Cargo.toml index d2444486..1ba7db45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,16 +37,16 @@ members = [ "web", "wgpu", "winit", - "examples/download_progress", "examples/bezier_tool", "examples/clock", "examples/counter", "examples/custom_widget", + "examples/download_progress", "examples/events", "examples/geometry", "examples/integration", - "examples/pokedex", "examples/pane_grid", + "examples/pokedex", "examples/progress_bar", "examples/solar_system", "examples/stopwatch", diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index f1d46936..7b5c349c 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -143,7 +143,7 @@ impl State { impl<'a, Message, Renderer> Widget for Button<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, Message: Clone, { fn width(&self) -> Length { @@ -234,6 +234,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::>().hash(state); + self.width.hash(state); self.content.hash_layout(state); } @@ -275,7 +277,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer, - Message: 'static + Clone, + Message: 'a + Clone, { fn from( button: Button<'a, Message, Renderer>, diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index b36d10a4..7f915456 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -110,7 +110,7 @@ impl impl Widget for Checkbox where - Renderer: self::Renderer + text::Renderer + row::Renderer, + Renderer: 'static + self::Renderer + text::Renderer + row::Renderer, { fn width(&self) -> Length { self.width @@ -205,6 +205,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::>().hash(state); + self.label.hash(state); } } @@ -253,7 +255,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer + text::Renderer + row::Renderer, - Message: 'static, + Message: 'a, { fn from( checkbox: Checkbox, diff --git a/native/src/widget/column.rs b/native/src/widget/column.rs index b1adc6e3..77b8496b 100644 --- a/native/src/widget/column.rs +++ b/native/src/widget/column.rs @@ -124,7 +124,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> { impl<'a, Message, Renderer> Widget for Column<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -190,7 +190,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { - 0.hash(state); + std::any::TypeId::of::>().hash(state); + self.width.hash(state); self.height.hash(state); self.max_width.hash(state); @@ -233,8 +234,8 @@ pub trait Renderer: crate::Renderer + Sized { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, - Message: 'static, + Renderer: 'static + self::Renderer, + Message: 'a, { fn from( column: Column<'a, Message, Renderer>, diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs index d1cbb32e..11ef23a9 100644 --- a/native/src/widget/container.rs +++ b/native/src/widget/container.rs @@ -122,7 +122,7 @@ where impl<'a, Message, Renderer> Widget for Container<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -189,7 +189,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { - 0.hash(state); + std::any::TypeId::of::>().hash(state); + self.width.hash(state); self.height.hash(state); self.max_width.hash(state); @@ -227,8 +228,8 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, - Message: 'static, + Renderer: 'static + self::Renderer, + Message: 'a, { fn from( column: Container<'a, Message, Renderer>, diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 5b067687..9dc13fa9 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -102,6 +102,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::().hash(state); + self.handle.hash(state); self.width.hash(state); self.height.hash(state); diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index a88f591a..2eca68d3 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -80,9 +80,9 @@ pub struct PaneGrid<'a, Message, Renderer> { height: Length, spacing: u16, modifier_keys: keyboard::ModifiersState, - on_drag: Option Message>>, - on_resize: Option Message>>, - on_key_press: Option Option>>, + on_drag: Option Message + 'a>>, + on_resize: Option Message + 'a>>, + on_key_press: Option Option + 'a>>, } impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { @@ -187,10 +187,10 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { /// Panes can be dragged using `Modifier keys + Left click`. /// /// [`PaneGrid`]: struct.PaneGrid.html - pub fn on_drag( - mut self, - f: impl Fn(DragEvent) -> Message + 'static, - ) -> Self { + pub fn on_drag(mut self, f: F) -> Self + where + F: 'a + Fn(DragEvent) -> Message, + { self.on_drag = Some(Box::new(f)); self } @@ -201,10 +201,10 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { /// Panes can be resized using `Modifier keys + Right click`. /// /// [`PaneGrid`]: struct.PaneGrid.html - pub fn on_resize( - mut self, - f: impl Fn(ResizeEvent) -> Message + 'static, - ) -> Self { + pub fn on_resize(mut self, f: F) -> Self + where + F: 'a + Fn(ResizeEvent) -> Message, + { self.on_resize = Some(Box::new(f)); self } @@ -226,10 +226,10 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> { /// /// [`PaneGrid`]: struct.PaneGrid.html /// [`Pane`]: struct.Pane.html - pub fn on_key_press( - mut self, - f: impl Fn(KeyPressEvent) -> Option + 'static, - ) -> Self { + pub fn on_key_press(mut self, f: F) -> Self + where + F: 'a + Fn(KeyPressEvent) -> Option, + { self.on_key_press = Some(Box::new(f)); self } @@ -348,8 +348,7 @@ pub struct KeyPressEvent { impl<'a, Message, Renderer> Widget for PaneGrid<'a, Message, Renderer> where - Renderer: self::Renderer + 'static, - Message: 'static, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -591,7 +590,7 @@ where fn hash_layout(&self, state: &mut Hasher) { use std::hash::Hash; - std::any::TypeId::of::>().hash(state); + std::any::TypeId::of::>().hash(state); self.width.hash(state); self.height.hash(state); self.state.hash_layout(state); @@ -636,8 +635,8 @@ pub trait Renderer: crate::Renderer + Sized { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: self::Renderer + 'static, - Message: 'static, + Renderer: 'static + self::Renderer, + Message: 'a, { fn from( pane_grid: PaneGrid<'a, Message, Renderer>, diff --git a/native/src/widget/progress_bar.rs b/native/src/widget/progress_bar.rs index 67d1ab83..897edb30 100644 --- a/native/src/widget/progress_bar.rs +++ b/native/src/widget/progress_bar.rs @@ -72,7 +72,7 @@ impl ProgressBar { impl Widget for ProgressBar where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -114,6 +114,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::>().hash(state); + self.width.hash(state); self.height.hash(state); } @@ -158,7 +160,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer, - Message: 'static, + Message: 'a, { fn from( progress_bar: ProgressBar, diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index cdc4862c..8fb3d0cc 100644 --- a/native/src/widget/radio.rs +++ b/native/src/widget/radio.rs @@ -77,7 +77,7 @@ impl Radio { impl Widget for Radio where - Renderer: self::Renderer + text::Renderer + row::Renderer, + Renderer: 'static + self::Renderer + text::Renderer + row::Renderer, Message: Clone, { fn width(&self) -> Length { @@ -169,6 +169,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::>().hash(state); + self.label.hash(state); } } @@ -212,7 +214,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer + row::Renderer + text::Renderer, - Message: 'static + Clone, + Message: 'a + Clone, { fn from(radio: Radio) -> Element<'a, Message, Renderer> { Element::new(radio) diff --git a/native/src/widget/row.rs b/native/src/widget/row.rs index c8812ea2..5f139f66 100644 --- a/native/src/widget/row.rs +++ b/native/src/widget/row.rs @@ -125,7 +125,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> { impl<'a, Message, Renderer> Widget for Row<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -191,7 +191,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { - 1.hash(state); + std::any::TypeId::of::>().hash(state); + self.width.hash(state); self.height.hash(state); self.max_width.hash(state); @@ -235,8 +236,8 @@ pub trait Renderer: crate::Renderer + Sized { impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + self::Renderer, - Message: 'static, + Renderer: 'static + self::Renderer, + Message: 'a, { fn from(row: Row<'a, Message, Renderer>) -> Element<'a, Message, Renderer> { Element::new(row) diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index ec9746d4..ba39edb1 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -311,7 +311,7 @@ where } fn hash_layout(&self, state: &mut Hasher) { - std::any::TypeId::of::>().hash(state); + std::any::TypeId::of::>().hash(state); self.height.hash(state); self.max_height.hash(state); @@ -506,7 +506,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer + column::Renderer, - Message: 'static, + Message: 'a, { fn from( scrollable: Scrollable<'a, Message, Renderer>, diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index 008203fe..b2fa5c9d 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -114,7 +114,7 @@ impl State { impl<'a, Message, Renderer> Widget for Slider<'a, Message, Renderer> where - Renderer: self::Renderer, + Renderer: 'static + self::Renderer, { fn width(&self) -> Length { self.width @@ -205,6 +205,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::>().hash(state); + self.width.hash(state); } } @@ -252,7 +254,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer, - Message: 'static, + Message: 'a, { fn from( slider: Slider<'a, Message, Renderer>, diff --git a/native/src/widget/space.rs b/native/src/widget/space.rs index 24c94bf6..e56a8fe1 100644 --- a/native/src/widget/space.rs +++ b/native/src/widget/space.rs @@ -77,6 +77,7 @@ where fn hash_layout(&self, state: &mut Hasher) { std::any::TypeId::of::().hash(state); + self.width.hash(state); self.height.hash(state); } @@ -97,7 +98,7 @@ pub trait Renderer: crate::Renderer { impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> where Renderer: self::Renderer, - Message: 'static, + Message: 'a, { fn from(space: Space) -> Element<'a, Message, Renderer> { Element::new(space) diff --git a/native/src/widget/svg.rs b/native/src/widget/svg.rs index b899da1e..4a227f3d 100644 --- a/native/src/widget/svg.rs +++ b/native/src/widget/svg.rs @@ -99,6 +99,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::().hash(state); + self.width.hash(state); self.height.hash(state); } diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs index 7d8cad6e..dc7c33ec 100644 --- a/native/src/widget/text.rs +++ b/native/src/widget/text.rs @@ -163,6 +163,8 @@ where } fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::().hash(state); + self.content.hash(state); self.size.hash(state); self.width.hash(state); diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index c17a1d30..3697ce09 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -172,7 +172,7 @@ impl<'a, Message, Renderer> Widget for TextInput<'a, Message, Renderer> where Renderer: 'static + self::Renderer, - Message: Clone + std::fmt::Debug, + Message: Clone, { fn width(&self) -> Length { self.width @@ -501,7 +501,7 @@ where fn hash_layout(&self, state: &mut Hasher) { use std::{any::TypeId, hash::Hash}; - TypeId::of::>().hash(state); + TypeId::of::>().hash(state); self.width.hash(state); self.max_width.hash(state); @@ -607,7 +607,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Renderer: 'static + self::Renderer, - Message: 'static + Clone + std::fmt::Debug, + Message: 'a + Clone, { fn from( text_input: TextInput<'a, Message, Renderer>,