Skip to content

Commit f27be6f

Browse files
committed
Changes as per linebender#831 (comment)
1 parent 06914ff commit f27be6f

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

druid/src/contexts.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ pub struct EventCtx<'a> {
4444
pub(crate) focus_widget: Option<WidgetId>,
4545
pub(crate) is_handled: bool,
4646
pub(crate) is_root: bool,
47-
/// Map of TimerTokens and WidgetIds that requested them.
48-
pub(crate) timers: &'a HashMap<TimerToken, WidgetId>,
4947
}
5048

5149
/// A mutable context provided to the [`lifecycle`] method on widgets.

druid/src/core.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
455455
is_handled: false,
456456
is_root: false,
457457
focus_widget: ctx.focus_widget,
458-
timers: &ctx.timers,
459458
};
460459

461460
let rect = child_ctx.base_state.layout_rect.unwrap_or_default();
@@ -495,6 +494,15 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
495494
}
496495
}
497496
}
497+
InternalEvent::RouteTimer(token, widget_id) => {
498+
let widget_id = *widget_id;
499+
if widget_id != child_ctx.base_state.id {
500+
recurse = child_ctx.base_state.children.may_contain(&widget_id);
501+
Event::Internal(InternalEvent::RouteTimer(*token, widget_id))
502+
} else {
503+
Event::Timer(*token)
504+
}
505+
}
498506
},
499507
Event::WindowConnected => Event::WindowConnected,
500508
Event::WindowSize(size) => {
@@ -571,15 +579,7 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
571579
Event::Zoom(*zoom)
572580
}
573581
Event::Timer(id) => {
574-
if let Some(widget_id) = child_ctx.timers.get(id) {
575-
if *widget_id != child_ctx.base_state.id {
576-
recurse = child_ctx.base_state.children.may_contain(widget_id);
577-
}
578-
} else {
579-
log::error!("Timer Token must be in timers map.");
580-
recurse = false;
581-
}
582-
Event::Timer(*id)
582+
panic!("We cannot be here");
583583
}
584584
Event::Command(cmd) => Event::Command(cmd.clone()),
585585
};

druid/src/event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ pub enum InternalEvent {
147147
MouseLeave,
148148
/// A command still in the process of being dispatched.
149149
TargetedCommand(Target, Command),
150+
RouteTimer(TimerToken, WidgetId),
150151
}
151152

152153
/// Application life cycle events.

druid/src/window.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ impl<T: Data> Window<T> {
172172
let scale = 96.0 / dpi;
173173
self.size = Size::new(size.width * scale, size.height * scale);
174174
Event::WindowSize(self.size)
175+
},
176+
Event::Timer(token) => {
177+
if let Some(widget_id) = self.timers.get(&token) {
178+
Event::Internal(InternalEvent::RouteTimer(token, *widget_id))
179+
} else {
180+
log::error!("No widget found for timer {:?}", token);
181+
return false;
182+
}
175183
}
176184
other => other,
177185
};
@@ -197,15 +205,13 @@ impl<T: Data> Window<T> {
197205
window: &self.handle,
198206
window_id: self.id,
199207
focus_widget: self.focus,
200-
timers: &self.timers,
201208
};
202209

203210
self.root.event(&mut ctx, &event, data, env);
204211
ctx.is_handled
205212
};
206213

207214
if let Some(focus_req) = base_state.request_focus.take() {
208-
println!("root");
209215
let old = self.focus;
210216
let new = self.widget_for_focus_request(focus_req);
211217
let event = LifeCycle::Internal(InternalLifeCycle::RouteFocusChanged { old, new });

0 commit comments

Comments
 (0)