From 21abef4cade9aaaa09d748d6d687d2cdc1e37db6 Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Sat, 7 Dec 2024 20:14:25 +0100 Subject: [PATCH] nuon: Make widgets fully inmutable --- .../playing_scene/top_bar/widget/looper.rs | 2 +- .../top_bar/widget/progress_bar.rs | 2 +- .../top_bar/widget/speed_pill.rs | 4 --- nuon/src/lib.rs | 29 +++++-------------- nuon/src/widget/button.rs | 2 +- nuon/src/widget/column.rs | 4 --- nuon/src/widget/container.rs | 4 --- nuon/src/widget/row.rs | 4 --- nuon/src/widget/stack.rs | 4 --- nuon/src/widget/trilayout.rs | 4 --- 10 files changed, 10 insertions(+), 49 deletions(-) diff --git a/neothesia/src/scene/playing_scene/top_bar/widget/looper.rs b/neothesia/src/scene/playing_scene/top_bar/widget/looper.rs index 1a52b27..446bca2 100644 --- a/neothesia/src/scene/playing_scene/top_bar/widget/looper.rs +++ b/neothesia/src/scene/playing_scene/top_bar/widget/looper.rs @@ -154,7 +154,7 @@ impl Widget for Looper { } fn update( - &mut self, + &self, event: Event, layout: &Node, tree: &mut Tree, diff --git a/neothesia/src/scene/playing_scene/top_bar/widget/progress_bar.rs b/neothesia/src/scene/playing_scene/top_bar/widget/progress_bar.rs index 4b70ef8..65ceaa4 100644 --- a/neothesia/src/scene/playing_scene/top_bar/widget/progress_bar.rs +++ b/neothesia/src/scene/playing_scene/top_bar/widget/progress_bar.rs @@ -101,7 +101,7 @@ impl Widget for ProgressBar { } fn update( - &mut self, + &self, event: Event, layout: &Node, tree: &mut Tree, diff --git a/neothesia/src/scene/playing_scene/top_bar/widget/speed_pill.rs b/neothesia/src/scene/playing_scene/top_bar/widget/speed_pill.rs index 607facd..afbb367 100644 --- a/neothesia/src/scene/playing_scene/top_bar/widget/speed_pill.rs +++ b/neothesia/src/scene/playing_scene/top_bar/widget/speed_pill.rs @@ -75,10 +75,6 @@ impl Widget for SpeedPill { &self.children } - fn children_mut(&mut self) -> &mut [Element] { - &mut self.children - } - fn layout(&self, tree: &mut Tree, parent: &ParentLayout, ctx: &LayoutCtx) -> Node { let minus = self.children[0].as_widget().layout( tree.children[0].remap_mut(), diff --git a/nuon/src/lib.rs b/nuon/src/lib.rs index ea5e108..506fddc 100644 --- a/nuon/src/lib.rs +++ b/nuon/src/lib.rs @@ -103,20 +103,13 @@ pub trait WidgetAny { fn state(&self) -> Box; fn children(&self) -> &[Element]; - fn children_mut(&mut self) -> &mut [Element]; fn children_tree(&self) -> Vec; fn diff(&self, tree: &mut Tree); fn layout(&self, tree: &mut Tree, avalilable: &ParentLayout, ctx: &LayoutCtx) -> Node; fn render(&self, renderer: &mut dyn Renderer, layout: &Node, tree: &Tree, ctx: &RenderCtx); - fn update( - &mut self, - event: input::Event, - layout: &Node, - tree: &mut Tree, - ctx: &mut UpdateCtx, - ); + fn update(&self, event: input::Event, layout: &Node, tree: &mut Tree, ctx: &mut UpdateCtx); } impl> WidgetAny for W { @@ -132,10 +125,6 @@ impl> WidgetAny for W { Widget::children(self) } - fn children_mut(&mut self) -> &mut [Element] { - Widget::children_mut(self) - } - fn children_tree(&self) -> Vec { Widget::children_tree(self) } @@ -153,7 +142,7 @@ impl> WidgetAny for W { } fn update( - &mut self, + &self, event: input::Event, layout: &Node, tree: &mut Tree, @@ -174,10 +163,6 @@ pub trait Widget { &[] } - fn children_mut(&mut self) -> &mut [Element] { - &mut [] - } - fn children_tree(&self) -> Vec { self.children() .iter() @@ -204,7 +189,7 @@ pub trait Widget { } fn update( - &mut self, + &self, event: input::Event, layout: &Node, tree: &mut Tree, @@ -236,20 +221,20 @@ pub fn default_render + ?Sized>( } pub fn default_update + ?Sized>( - this: &mut W, + this: &W, event: input::Event, layout: &Node, tree: &mut Tree, ctx: &mut UpdateCtx, ) { for ((ch, layout), tree) in this - .children_mut() - .iter_mut() + .children() + .iter() .zip(layout.children.iter()) .zip(tree.children.iter_mut()) .rev() { - ch.as_widget_mut().update(event.clone(), layout, tree, ctx); + ch.as_widget().update(event.clone(), layout, tree, ctx); if ctx.is_event_captured() { return; diff --git a/nuon/src/widget/button.rs b/nuon/src/widget/button.rs index a3ea2bf..ebb69be 100644 --- a/nuon/src/widget/button.rs +++ b/nuon/src/widget/button.rs @@ -140,7 +140,7 @@ impl Widget for Button { } fn update( - &mut self, + &self, event: Event, layout: &Node, tree: &mut Tree, diff --git a/nuon/src/widget/column.rs b/nuon/src/widget/column.rs index 9e5c30b..6689e23 100644 --- a/nuon/src/widget/column.rs +++ b/nuon/src/widget/column.rs @@ -47,10 +47,6 @@ impl Widget for Column { &self.children } - fn children_mut(&mut self) -> &mut [Element] { - &mut self.children - } - fn layout(&self, tree: &mut Tree, parent: &ParentLayout, ctx: &LayoutCtx) -> Node { column_layout(self, tree, parent, ctx, self.gap) } diff --git a/nuon/src/widget/container.rs b/nuon/src/widget/container.rs index 9a5c17c..3ce267f 100644 --- a/nuon/src/widget/container.rs +++ b/nuon/src/widget/container.rs @@ -65,10 +65,6 @@ impl Widget for Container { &self.child } - fn children_mut(&mut self) -> &mut [Element] { - &mut self.child - } - fn layout(&self, tree: &mut Tree, parent: &ParentLayout, ctx: &LayoutCtx) -> Node { let parent = &ParentLayout { x: parent.x + self.x, diff --git a/nuon/src/widget/row.rs b/nuon/src/widget/row.rs index edf7a07..aea6322 100644 --- a/nuon/src/widget/row.rs +++ b/nuon/src/widget/row.rs @@ -47,10 +47,6 @@ impl Widget for Row { &self.children } - fn children_mut(&mut self) -> &mut [Element] { - &mut self.children - } - fn layout(&self, tree: &mut Tree, parent: &ParentLayout, ctx: &LayoutCtx) -> Node { row_layout(self, tree, parent, ctx, self.gap) } diff --git a/nuon/src/widget/stack.rs b/nuon/src/widget/stack.rs index a1b1e1a..bd69e93 100644 --- a/nuon/src/widget/stack.rs +++ b/nuon/src/widget/stack.rs @@ -40,10 +40,6 @@ impl Widget for Stack { &self.children } - fn children_mut(&mut self) -> &mut [Element] { - &mut self.children - } - fn layout(&self, tree: &mut Tree, parent: &ParentLayout, ctx: &LayoutCtx) -> Node { stack_layout(self, tree, parent, ctx) } diff --git a/nuon/src/widget/trilayout.rs b/nuon/src/widget/trilayout.rs index 8534a64..37d0db7 100644 --- a/nuon/src/widget/trilayout.rs +++ b/nuon/src/widget/trilayout.rs @@ -54,10 +54,6 @@ impl Widget for TriLayout { &self.children } - fn children_mut(&mut self) -> &mut [Element] { - &mut self.children - } - fn layout(&self, tree: &mut Tree, parent: &ParentLayout, ctx: &LayoutCtx) -> Node { let start = self.children[0].as_widget().layout( &mut tree.children[0],