Skip to content

Commit

Permalink
Changes as per linebender#831 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoshid committed Apr 26, 2020
1 parent 06914ff commit f27be6f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
2 changes: 0 additions & 2 deletions druid/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ pub struct EventCtx<'a> {
pub(crate) focus_widget: Option<WidgetId>,
pub(crate) is_handled: bool,
pub(crate) is_root: bool,
/// Map of TimerTokens and WidgetIds that requested them.
pub(crate) timers: &'a HashMap<TimerToken, WidgetId>,
}

/// A mutable context provided to the [`lifecycle`] method on widgets.
Expand Down
20 changes: 10 additions & 10 deletions druid/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
is_handled: false,
is_root: false,
focus_widget: ctx.focus_widget,
timers: &ctx.timers,
};

let rect = child_ctx.base_state.layout_rect.unwrap_or_default();
Expand Down Expand Up @@ -495,6 +494,15 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
}
}
}
InternalEvent::RouteTimer(token, widget_id) => {
let widget_id = *widget_id;
if widget_id != child_ctx.base_state.id {
recurse = child_ctx.base_state.children.may_contain(&widget_id);
Event::Internal(InternalEvent::RouteTimer(*token, widget_id))
} else {
Event::Timer(*token)
}
}
},
Event::WindowConnected => Event::WindowConnected,
Event::WindowSize(size) => {
Expand Down Expand Up @@ -571,15 +579,7 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
Event::Zoom(*zoom)
}
Event::Timer(id) => {
if let Some(widget_id) = child_ctx.timers.get(id) {
if *widget_id != child_ctx.base_state.id {
recurse = child_ctx.base_state.children.may_contain(widget_id);
}
} else {
log::error!("Timer Token must be in timers map.");
recurse = false;
}
Event::Timer(*id)
panic!("We cannot be here");
}
Event::Command(cmd) => Event::Command(cmd.clone()),
};
Expand Down
1 change: 1 addition & 0 deletions druid/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub enum InternalEvent {
MouseLeave,
/// A command still in the process of being dispatched.
TargetedCommand(Target, Command),
RouteTimer(TimerToken, WidgetId),
}

/// Application life cycle events.
Expand Down
10 changes: 8 additions & 2 deletions druid/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ impl<T: Data> Window<T> {
let scale = 96.0 / dpi;
self.size = Size::new(size.width * scale, size.height * scale);
Event::WindowSize(self.size)
},
Event::Timer(token) => {
if let Some(widget_id) = self.timers.get(&token) {
Event::Internal(InternalEvent::RouteTimer(token, *widget_id))
} else {
log::error!("No widget found for timer {:?}", token);
return false;
}
}
other => other,
};
Expand All @@ -197,15 +205,13 @@ impl<T: Data> Window<T> {
window: &self.handle,
window_id: self.id,
focus_widget: self.focus,
timers: &self.timers,
};

self.root.event(&mut ctx, &event, data, env);
ctx.is_handled
};

if let Some(focus_req) = base_state.request_focus.take() {
println!("root");
let old = self.focus;
let new = self.widget_for_focus_request(focus_req);
let event = LifeCycle::Internal(InternalLifeCycle::RouteFocusChanged { old, new });
Expand Down

0 comments on commit f27be6f

Please sign in to comment.