Skip to content

Commit

Permalink
Take Event by reference in Widget::update
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Feb 4, 2025
1 parent 1b01d67 commit afef368
Show file tree
Hide file tree
Showing 49 changed files with 111 additions and 155 deletions.
4 changes: 2 additions & 2 deletions core/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ where
fn update(
&mut self,
tree: &mut Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down Expand Up @@ -447,7 +447,7 @@ where
fn update(
&mut self,
state: &mut Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down
2 changes: 1 addition & 1 deletion core/src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
/// By default, it does nothing.
fn update(
&mut self,
_event: Event,
_event: &Event,
_layout: Layout<'_>,
_cursor: mouse::Cursor,
_renderer: &Renderer,
Expand Down
4 changes: 2 additions & 2 deletions core/src/overlay/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ where
/// Processes a runtime [`Event`].
pub fn update(
&mut self,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down Expand Up @@ -150,7 +150,7 @@ where

fn update(
&mut self,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down
11 changes: 2 additions & 9 deletions core/src/overlay/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,15 @@ where

fn update(
&mut self,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
) {
for (child, layout) in self.children.iter_mut().zip(layout.children()) {
child.update(
event.clone(),
layout,
cursor,
renderer,
clipboard,
shell,
);
child.update(event, layout, cursor, renderer, clipboard, shell);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ where
fn update(
&mut self,
_state: &mut Tree,
_event: Event,
_event: &Event,
_layout: Layout<'_>,
_cursor: mouse::Cursor,
_renderer: &Renderer,
Expand Down
2 changes: 1 addition & 1 deletion examples/bezier_tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mod bezier {
fn update(
&self,
state: &mut Self::State,
event: Event,
event: &Event,
bounds: Rectangle,
cursor: mouse::Cursor,
) -> Option<canvas::Action<Curve>> {
Expand Down
4 changes: 2 additions & 2 deletions examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ mod grid {
fn update(
&self,
interaction: &mut Interaction,
event: Event,
event: &Event,
bounds: Rectangle,
cursor: mouse::Cursor,
) -> Option<canvas::Action<Message>> {
Expand Down Expand Up @@ -471,7 +471,7 @@ mod grid {
_ => action.and_capture(),
})
}
mouse::Event::WheelScrolled { delta } => match delta {
mouse::Event::WheelScrolled { delta } => match *delta {
mouse::ScrollDelta::Lines { y, .. }
| mouse::ScrollDelta::Pixels { y, .. } => {
if y < 0.0 && self.scaling > Self::MIN_SCALING
Expand Down
4 changes: 2 additions & 2 deletions examples/loading_spinners/src/circular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ where
fn update(
&mut self,
tree: &mut Tree,
event: Event,
event: &Event,
_layout: Layout<'_>,
_cursor: mouse::Cursor,
_renderer: &Renderer,
Expand All @@ -278,7 +278,7 @@ where
state.animation = state.animation.timed_transition(
self.cycle_duration,
self.rotation_duration,
now,
*now,
);

state.cache.clear();
Expand Down
4 changes: 2 additions & 2 deletions examples/loading_spinners/src/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ where
fn update(
&mut self,
tree: &mut Tree,
event: Event,
event: &Event,
_layout: Layout<'_>,
_cursor: mouse::Cursor,
_renderer: &Renderer,
Expand All @@ -189,7 +189,7 @@ where
let state = tree.state.downcast_mut::<State>();

if let Event::Window(window::Event::RedrawRequested(now)) = event {
*state = state.timed_transition(self.cycle_duration, now);
*state = state.timed_transition(self.cycle_duration, *now);

shell.request_redraw();
}
Expand Down
4 changes: 2 additions & 2 deletions examples/multitouch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ impl canvas::Program<Message> for Multitouch {
fn update(
&self,
_state: &mut Self::State,
event: Event,
event: &Event,
_bounds: Rectangle,
_cursor: mouse::Cursor,
) -> Option<canvas::Action<Message>> {
let message = match event {
let message = match event.clone() {
Event::Touch(
touch::Event::FingerPressed { id, position }
| touch::Event::FingerMoved { id, position },
Expand Down
2 changes: 1 addition & 1 deletion examples/sierpinski_triangle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl canvas::Program<Message> for SierpinskiGraph {
fn update(
&self,
_state: &mut Self::State,
event: Event,
event: &Event,
bounds: Rectangle,
cursor: mouse::Cursor,
) -> Option<canvas::Action<Message>> {
Expand Down
6 changes: 3 additions & 3 deletions examples/toast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ mod toast {
fn update(
&mut self,
state: &mut Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down Expand Up @@ -491,7 +491,7 @@ mod toast {

fn update(
&mut self,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down Expand Up @@ -530,7 +530,7 @@ mod toast {

child.as_widget_mut().update(
state,
event.clone(),
event,
layout,
cursor,
renderer,
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/overlay/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ where
/// Processes a runtime [`Event`].
pub fn update(
&mut self,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand All @@ -170,7 +170,7 @@ where
fn recurse<Message, Theme, Renderer>(
element: &mut overlay::Element<'_, Message, Theme, Renderer>,
layout: Layout<'_>,
event: Event,
event: &Event,
cursor: mouse::Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
Expand All @@ -188,7 +188,7 @@ where
recurse(
&mut nested,
nested_layout,
event.clone(),
event,
cursor,
renderer,
clipboard,
Expand Down
3 changes: 1 addition & 2 deletions runtime/src/user_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ where
let mut layout = overlay.layout(renderer, bounds);
let mut event_statuses = Vec::new();

for event in events.iter().cloned() {
for event in events {
let mut shell = Shell::new(messages);

overlay.update(
Expand Down Expand Up @@ -294,7 +294,6 @@ where

let event_statuses = events
.iter()
.cloned()
.zip(overlay_statuses)
.map(|(event, overlay_status)| {
if matches!(overlay_status, event::Status::Captured) {
Expand Down
4 changes: 2 additions & 2 deletions widget/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ where
fn update(
&mut self,
tree: &mut Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand All @@ -285,7 +285,7 @@ where
) {
self.content.as_widget_mut().update(
&mut tree.children[0],
event.clone(),
event,
layout.children().next().unwrap(),
cursor,
renderer,
Expand Down
2 changes: 1 addition & 1 deletion widget/src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ where
fn update(
&mut self,
tree: &mut Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down
4 changes: 2 additions & 2 deletions widget/src/canvas/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ where
fn update(
&self,
_state: &mut Self::State,
_event: Event,
_event: &Event,
_bounds: Rectangle,
_cursor: mouse::Cursor,
) -> Option<Action<Message>> {
Expand Down Expand Up @@ -82,7 +82,7 @@ where
fn update(
&self,
state: &mut Self::State,
event: Event,
event: &Event,
bounds: Rectangle,
cursor: mouse::Cursor,
) -> Option<Action<Message>> {
Expand Down
2 changes: 1 addition & 1 deletion widget/src/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ where
fn update(
&mut self,
_tree: &mut Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
_renderer: &Renderer,
Expand Down
10 changes: 2 additions & 8 deletions widget/src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ where
fn update(
&mut self,
tree: &mut Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand All @@ -275,13 +275,7 @@ where
.zip(layout.children())
{
child.as_widget_mut().update(
state,
event.clone(),
layout,
cursor,
renderer,
clipboard,
shell,
state, event, layout, cursor, renderer, clipboard, shell,
viewport,
);
}
Expand Down
6 changes: 3 additions & 3 deletions widget/src/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ where
fn update(
&mut self,
tree: &mut widget::Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down Expand Up @@ -540,7 +540,7 @@ where
// Provide it to the widget
self.text_input.update(
&mut tree.children[0],
event.clone(),
event,
layout,
cursor,
renderer,
Expand Down Expand Up @@ -737,7 +737,7 @@ where
let mut local_shell = Shell::new(&mut local_messages);
self.text_input.update(
&mut tree.children[0],
Event::Mouse(mouse::Event::ButtonPressed(
&Event::Mouse(mouse::Event::ButtonPressed(
mouse::Button::Left,
)),
layout,
Expand Down
2 changes: 1 addition & 1 deletion widget/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ where
fn update(
&mut self,
tree: &mut Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down
16 changes: 5 additions & 11 deletions widget/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ where
fn update(
&mut self,
state: &mut Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down Expand Up @@ -836,7 +836,7 @@ where
fn update(
&mut self,
tree: &mut Tree,
event: Event,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
Expand Down Expand Up @@ -885,14 +885,8 @@ where
let redraw_request = shell.redraw_request();

self.top.as_widget_mut().update(
top_tree,
event.clone(),
top_layout,
cursor,
renderer,
clipboard,
shell,
viewport,
top_tree, event, top_layout, cursor, renderer, clipboard,
shell, viewport,
);

// Ignore redraw requests of invisible content
Expand All @@ -907,7 +901,7 @@ where

self.base.as_widget_mut().update(
base_tree,
event.clone(),
event,
base_layout,
cursor,
renderer,
Expand Down
Loading

0 comments on commit afef368

Please sign in to comment.