Skip to content

Commit 21abef4

Browse files
committed
nuon: Make widgets fully inmutable
1 parent fa60bc6 commit 21abef4

10 files changed

Lines changed: 10 additions & 49 deletions

File tree

‎neothesia/src/scene/playing_scene/top_bar/widget/looper.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<MSG> Widget<MSG> for Looper<MSG> {
154154
}
155155

156156
fn update(
157-
&mut self,
157+
&self,
158158
event: Event,
159159
layout: &Node,
160160
tree: &mut Tree<Self::State>,

‎neothesia/src/scene/playing_scene/top_bar/widget/progress_bar.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<MSG: Clone> Widget<MSG> for ProgressBar<MSG> {
101101
}
102102

103103
fn update(
104-
&mut self,
104+
&self,
105105
event: Event,
106106
layout: &Node,
107107
tree: &mut Tree<Self::State>,

‎neothesia/src/scene/playing_scene/top_bar/widget/speed_pill.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ impl<MSG: Clone> Widget<MSG> for SpeedPill<MSG> {
7575
&self.children
7676
}
7777

78-
fn children_mut(&mut self) -> &mut [Element<MSG>] {
79-
&mut self.children
80-
}
81-
8278
fn layout(&self, tree: &mut Tree<Self::State>, parent: &ParentLayout, ctx: &LayoutCtx) -> Node {
8379
let minus = self.children[0].as_widget().layout(
8480
tree.children[0].remap_mut(),

‎nuon/src/lib.rs‎

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,13 @@ pub trait WidgetAny<MSG> {
103103
fn state(&self) -> Box<dyn Any>;
104104

105105
fn children(&self) -> &[Element<MSG>];
106-
fn children_mut(&mut self) -> &mut [Element<MSG>];
107106
fn children_tree(&self) -> Vec<Tree>;
108107

109108
fn diff(&self, tree: &mut Tree);
110109

111110
fn layout(&self, tree: &mut Tree, avalilable: &ParentLayout, ctx: &LayoutCtx) -> Node;
112111
fn render(&self, renderer: &mut dyn Renderer, layout: &Node, tree: &Tree, ctx: &RenderCtx);
113-
fn update(
114-
&mut self,
115-
event: input::Event,
116-
layout: &Node,
117-
tree: &mut Tree,
118-
ctx: &mut UpdateCtx<MSG>,
119-
);
112+
fn update(&self, event: input::Event, layout: &Node, tree: &mut Tree, ctx: &mut UpdateCtx<MSG>);
120113
}
121114

122115
impl<MSG, W: Widget<MSG>> WidgetAny<MSG> for W {
@@ -132,10 +125,6 @@ impl<MSG, W: Widget<MSG>> WidgetAny<MSG> for W {
132125
Widget::children(self)
133126
}
134127

135-
fn children_mut(&mut self) -> &mut [Element<MSG>] {
136-
Widget::children_mut(self)
137-
}
138-
139128
fn children_tree(&self) -> Vec<Tree> {
140129
Widget::children_tree(self)
141130
}
@@ -153,7 +142,7 @@ impl<MSG, W: Widget<MSG>> WidgetAny<MSG> for W {
153142
}
154143

155144
fn update(
156-
&mut self,
145+
&self,
157146
event: input::Event,
158147
layout: &Node,
159148
tree: &mut Tree,
@@ -174,10 +163,6 @@ pub trait Widget<MSG> {
174163
&[]
175164
}
176165

177-
fn children_mut(&mut self) -> &mut [Element<MSG>] {
178-
&mut []
179-
}
180-
181166
fn children_tree(&self) -> Vec<Tree> {
182167
self.children()
183168
.iter()
@@ -204,7 +189,7 @@ pub trait Widget<MSG> {
204189
}
205190

206191
fn update(
207-
&mut self,
192+
&self,
208193
event: input::Event,
209194
layout: &Node,
210195
tree: &mut Tree<Self::State>,
@@ -236,20 +221,20 @@ pub fn default_render<MSG, W: Widget<MSG> + ?Sized>(
236221
}
237222

238223
pub fn default_update<MSG, W: Widget<MSG> + ?Sized>(
239-
this: &mut W,
224+
this: &W,
240225
event: input::Event,
241226
layout: &Node,
242227
tree: &mut Tree<W::State>,
243228
ctx: &mut UpdateCtx<MSG>,
244229
) {
245230
for ((ch, layout), tree) in this
246-
.children_mut()
247-
.iter_mut()
231+
.children()
232+
.iter()
248233
.zip(layout.children.iter())
249234
.zip(tree.children.iter_mut())
250235
.rev()
251236
{
252-
ch.as_widget_mut().update(event.clone(), layout, tree, ctx);
237+
ch.as_widget().update(event.clone(), layout, tree, ctx);
253238

254239
if ctx.is_event_captured() {
255240
return;

‎nuon/src/widget/button.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<MSG: Clone> Widget<MSG> for Button<MSG> {
140140
}
141141

142142
fn update(
143-
&mut self,
143+
&self,
144144
event: Event,
145145
layout: &Node,
146146
tree: &mut Tree<Self::State>,

‎nuon/src/widget/column.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ impl<MSG> Widget<MSG> for Column<MSG> {
4747
&self.children
4848
}
4949

50-
fn children_mut(&mut self) -> &mut [Element<MSG>] {
51-
&mut self.children
52-
}
53-
5450
fn layout(&self, tree: &mut Tree<Self::State>, parent: &ParentLayout, ctx: &LayoutCtx) -> Node {
5551
column_layout(self, tree, parent, ctx, self.gap)
5652
}

‎nuon/src/widget/container.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ impl<MSG> Widget<MSG> for Container<MSG> {
6565
&self.child
6666
}
6767

68-
fn children_mut(&mut self) -> &mut [Element<MSG>] {
69-
&mut self.child
70-
}
71-
7268
fn layout(&self, tree: &mut Tree<Self::State>, parent: &ParentLayout, ctx: &LayoutCtx) -> Node {
7369
let parent = &ParentLayout {
7470
x: parent.x + self.x,

‎nuon/src/widget/row.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ impl<MSG> Widget<MSG> for Row<MSG> {
4747
&self.children
4848
}
4949

50-
fn children_mut(&mut self) -> &mut [Element<MSG>] {
51-
&mut self.children
52-
}
53-
5450
fn layout(&self, tree: &mut Tree<Self::State>, parent: &ParentLayout, ctx: &LayoutCtx) -> Node {
5551
row_layout(self, tree, parent, ctx, self.gap)
5652
}

‎nuon/src/widget/stack.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ impl<MSG> Widget<MSG> for Stack<MSG> {
4040
&self.children
4141
}
4242

43-
fn children_mut(&mut self) -> &mut [Element<MSG>] {
44-
&mut self.children
45-
}
46-
4743
fn layout(&self, tree: &mut Tree<Self::State>, parent: &ParentLayout, ctx: &LayoutCtx) -> Node {
4844
stack_layout(self, tree, parent, ctx)
4945
}

‎nuon/src/widget/trilayout.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ impl<MSG> Widget<MSG> for TriLayout<MSG> {
5454
&self.children
5555
}
5656

57-
fn children_mut(&mut self) -> &mut [Element<MSG>] {
58-
&mut self.children
59-
}
60-
6157
fn layout(&self, tree: &mut Tree<Self::State>, parent: &ParentLayout, ctx: &LayoutCtx) -> Node {
6258
let start = self.children[0].as_widget().layout(
6359
&mut tree.children[0],

0 commit comments

Comments
 (0)