Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification fixups #1640

Merged
merged 2 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You can find its changes [documented below](#070---2021-01-01).
- Shell: IME API and macOS IME implementation ([#1619] by [@lord])
- Scroll::content_must_fill and a few other new Scroll methods ([#1635] by [@cmyr])
- New `TextBox` widget with IME integration ([#1636] by [@cmyr])
- `Notification`s can be submitted while handling other `Notification`s ([#1640] by [@cmyr])
- Added ListIter implementations for OrdMap ([#1641] by [@Lejero])

### Changed
Expand All @@ -39,6 +40,8 @@ You can find its changes [documented below](#070---2021-01-01).
### Removed

### Fixed
- `Notification`s will not be delivered to the widget that sends them ([#1640] by [@cmyr])


- Fixed docs of derived Lens ([#1523] by [@Maan2003])
- Use correct fill rule when rendering SVG paths ([#1606] by [@SecondFlight])
Expand Down Expand Up @@ -638,6 +641,7 @@ Last release without a changelog :(
[#1634]: https://github.com/linebender/druid/pull/1634
[#1635]: https://github.com/linebender/druid/pull/1635
[#1636]: https://github.com/linebender/druid/pull/1636
[#1640]: https://github.com/linebender/druid/pull/1640
[#1641]: https://github.com/linebender/druid/pull/1641
[#1647]: https://github.com/linebender/druid/pull/1647

Expand Down
36 changes: 17 additions & 19 deletions druid/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,35 +858,33 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
notifications: parent_notifications,
..
} = ctx;
let mut sentinal = VecDeque::new();
let self_id = self.id();
let mut inner_ctx = EventCtx {
state,
notifications: &mut sentinal,
notifications: parent_notifications,
widget_state: &mut self.state,
is_handled: false,
is_root: false,
};

for _ in 0..notifications.len() {
let notification = notifications.pop_front().unwrap();
let event = Event::Notification(notification);
self.inner.event(&mut inner_ctx, &event, data, env);
if inner_ctx.is_handled {
inner_ctx.is_handled = false;
} else if let Event::Notification(notification) = event {
// we will try again with the next parent
parent_notifications.push_back(notification);
for notification in notifications.drain(..) {
// skip notifications that were submitted by our child
if notification.source() != self_id {
let event = Event::Notification(notification);
self.inner.event(&mut inner_ctx, &event, data, env);
if inner_ctx.is_handled {
inner_ctx.is_handled = false;
} else if let Event::Notification(notification) = event {
// we will try again with the next parent
inner_ctx.notifications.push_back(notification);
} else {
// could be unchecked but we avoid unsafe in druid :shrug:
unreachable!()
}
} else {
unreachable!()
inner_ctx.notifications.push_back(notification);
}
}

if !inner_ctx.notifications.is_empty() {
warn!(
"A Notification was submitted while handling another \
notification; the submitted notification will be ignored."
);
}
}

/// Propagate a [`LifeCycle`] event.
Expand Down