Skip to content

Commit

Permalink
Allow notifications to be submitted while handling others
Browse files Browse the repository at this point in the history
I don't think the limitation against this made any sense.
  • Loading branch information
cmyr committed Mar 16, 2021
1 parent cfd7a6f commit 6fa6656
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
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
15 changes: 5 additions & 10 deletions druid/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,18 +858,17 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
notifications: parent_notifications,
..
} = ctx;
let mut sentinal = VecDeque::new();
let mut notifications_added_in_response_to_these = VecDeque::new();
let self_id = self.id();
let mut inner_ctx = EventCtx {
state,
notifications: &mut sentinal,
notifications: &mut notifications_added_in_response_to_these,
widget_state: &mut self.state,
is_handled: false,
is_root: false,
};

for _ in 0..notifications.len() {
let notification = notifications.pop_front().unwrap();
for notification in notifications.drain(..) {
// skip notifications that were submitted by our child
if notification.source() != self_id {
let event = Event::Notification(notification);
Expand All @@ -880,19 +879,15 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
// we will try again with the next parent
parent_notifications.push_back(notification);
} else {
// could be unchecked but we avoid unsafe in druid :shrug:
unreachable!()
}
} else {
parent_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."
);
}
parent_notifications.extend(notifications_added_in_response_to_these);
}

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

0 comments on commit 6fa6656

Please sign in to comment.