Skip to content

Commit

Permalink
Merge pull request #1956 from tarkah/feat/on-event-viewport
Browse files Browse the repository at this point in the history
Add viewport to `Widget::on_event`
  • Loading branch information
hecrj authored Jul 15, 2023
2 parents e462f48 + 42c423b commit fd07791
Show file tree
Hide file tree
Showing 30 changed files with 77 additions and 5 deletions.
9 changes: 6 additions & 3 deletions core/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, B>,
viewport: &Rectangle,
) -> event::Status {
let mut local_messages = Vec::new();
let mut local_shell = Shell::new(&mut local_messages);
Expand All @@ -392,6 +393,7 @@ where
renderer,
clipboard,
&mut local_shell,
viewport,
);

shell.merge(local_shell, &self.mapper);
Expand Down Expand Up @@ -511,10 +513,11 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.element
.widget
.on_event(state, event, layout, cursor, renderer, clipboard, shell)
self.element.widget.on_event(
state, event, layout, cursor, renderer, clipboard, shell, viewport,
)
}

fn draw(
Expand Down
1 change: 1 addition & 0 deletions core/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ where
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
event::Status::Ignored
}
Expand Down
1 change: 1 addition & 0 deletions examples/loading_spinners/src/circular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ where
_renderer: &iced::Renderer<Theme>,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
const FRAME_RATE: u64 = 60;

Expand Down
1 change: 1 addition & 0 deletions examples/loading_spinners/src/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ where
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
const FRAME_RATE: u64 = 60;

Expand Down
3 changes: 3 additions & 0 deletions examples/modal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ mod modal {
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.base.as_widget_mut().on_event(
&mut state.children[0],
Expand All @@ -309,6 +310,7 @@ mod modal {
renderer,
clipboard,
shell,
viewport,
)
}

Expand Down Expand Up @@ -446,6 +448,7 @@ mod modal {
renderer,
clipboard,
shell,
&layout.bounds(),
)
}

Expand Down
5 changes: 5 additions & 0 deletions examples/toast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ mod toast {
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.content.as_widget_mut().on_event(
&mut state.children[0],
Expand All @@ -409,6 +410,7 @@ mod toast {
renderer,
clipboard,
shell,
viewport,
)
}

Expand Down Expand Up @@ -559,6 +561,8 @@ mod toast {
}
}

let viewport = layout.bounds();

self.toasts
.iter_mut()
.zip(self.state.iter_mut())
Expand All @@ -576,6 +580,7 @@ mod toast {
renderer,
clipboard,
&mut local_shell,
&viewport,
);

if !local_shell.is_empty() {
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/user_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ where
(cursor, vec![event::Status::Ignored; events.len()])
};

let viewport = Rectangle::with_size(self.bounds);

let _ = ManuallyDrop::into_inner(manual_overlay);

let event_statuses = events
Expand All @@ -305,6 +307,7 @@ where
renderer,
clipboard,
&mut shell,
&viewport,
);

if matches!(event_status, event::Status::Captured) {
Expand Down
2 changes: 2 additions & 0 deletions widget/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
if let event::Status::Captured = self.content.as_widget_mut().on_event(
&mut tree.children[0],
Expand All @@ -209,6 +210,7 @@ where
renderer,
clipboard,
shell,
viewport,
) {
return event::Status::Captured;
}
Expand Down
1 change: 1 addition & 0 deletions widget/src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ where
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
let bounds = layout.bounds();

Expand Down
1 change: 1 addition & 0 deletions widget/src/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ where
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))
Expand Down
2 changes: 2 additions & 0 deletions widget/src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.children
.iter_mut()
Expand All @@ -184,6 +185,7 @@ where
renderer,
clipboard,
shell,
viewport,
)
})
.fold(event::Status::Ignored, event::Status::merge)
Expand Down
2 changes: 2 additions & 0 deletions widget/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.content.as_widget_mut().on_event(
&mut tree.children[0],
Expand All @@ -209,6 +210,7 @@ where
renderer,
clipboard,
shell,
viewport,
)
}

Expand Down
1 change: 1 addition & 0 deletions widget/src/image/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ where
renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
let bounds = layout.bounds();

Expand Down
2 changes: 2 additions & 0 deletions widget/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.with_element_mut(|element| {
element.as_widget_mut().on_event(
Expand All @@ -196,6 +197,7 @@ where
renderer,
clipboard,
shell,
viewport,
)
})
}
Expand Down
2 changes: 2 additions & 0 deletions widget/src/lazy/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
let mut local_messages = Vec::new();
let mut local_shell = Shell::new(&mut local_messages);
Expand All @@ -284,6 +285,7 @@ where
renderer,
clipboard,
&mut local_shell,
viewport,
)
});

Expand Down
2 changes: 2 additions & 0 deletions widget/src/lazy/responsive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
let state = tree.state.downcast_mut::<State>();
let mut content = self.content.borrow_mut();
Expand All @@ -203,6 +204,7 @@ where
renderer,
clipboard,
&mut local_shell,
viewport,
)
},
);
Expand Down
2 changes: 2 additions & 0 deletions widget/src/mouse_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
if let event::Status::Captured = self.content.as_widget_mut().on_event(
&mut tree.children[0],
Expand All @@ -159,6 +160,7 @@ where
renderer,
clipboard,
shell,
viewport,
) {
return event::Status::Captured;
}
Expand Down
4 changes: 4 additions & 0 deletions widget/src/overlay/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,11 @@ where
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
) -> event::Status {
let bounds = layout.bounds();

self.container.on_event(
self.state, event, layout, cursor, renderer, clipboard, shell,
&bounds,
)
}

Expand Down Expand Up @@ -377,6 +380,7 @@ where
renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
Expand Down
2 changes: 2 additions & 0 deletions widget/src/pane_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
let action = tree.state.downcast_mut::<state::Action>();

Expand Down Expand Up @@ -357,6 +358,7 @@ where
renderer,
clipboard,
shell,
viewport,
is_picked,
)
})
Expand Down
3 changes: 3 additions & 0 deletions widget/src/pane_grid/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
is_picked: bool,
) -> event::Status {
let mut event_status = event::Status::Ignored;
Expand All @@ -237,6 +238,7 @@ where
renderer,
clipboard,
shell,
viewport,
);

children.next().unwrap()
Expand All @@ -255,6 +257,7 @@ where
renderer,
clipboard,
shell,
viewport,
)
};

Expand Down
3 changes: 3 additions & 0 deletions widget/src/pane_grid/title_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
let mut children = layout.children();
let padded = children.next().unwrap();
Expand All @@ -328,6 +329,7 @@ where
renderer,
clipboard,
shell,
viewport,
)
} else {
event::Status::Ignored
Expand All @@ -342,6 +344,7 @@ where
renderer,
clipboard,
shell,
viewport,
)
} else {
event::Status::Ignored
Expand Down
1 change: 1 addition & 0 deletions widget/src/pick_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ where
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
update(
event,
Expand Down
1 change: 1 addition & 0 deletions widget/src/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ where
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))
Expand Down
2 changes: 2 additions & 0 deletions widget/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.children
.iter_mut()
Expand All @@ -173,6 +174,7 @@ where
renderer,
clipboard,
shell,
viewport,
)
})
.fold(event::Status::Ignored, event::Status::merge)
Expand Down
Loading

0 comments on commit fd07791

Please sign in to comment.