Skip to content

Commit

Permalink
Add UpdateCtx::submit_command
Browse files Browse the repository at this point in the history
That this was missing was an oversight.
  • Loading branch information
cmyr committed Apr 17, 2020
1 parent cb96b75 commit 1384e6c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions druid/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub struct UpdateCtx<'a> {
// invalidations, which would mean a structure very much like
// `EventCtx` (and possibly using the same structure). But for
// now keep it super-simple.
pub(crate) command_queue: &'a mut CommandQueue,
pub(crate) window_id: WindowId,
pub(crate) base_state: &'a mut BaseState,
}
Expand Down Expand Up @@ -503,6 +504,23 @@ impl<'a> UpdateCtx<'a> {
self.base_state.needs_inval = true;
}

/// Submit a [`Command`] to be run after layout and paint finish.
///
/// **Note:**
///
/// Commands submited during an `update` call are handled *after* update,
/// layout, and paint have completed; this will trigger a new event cycle.
///
/// [`Command`]: struct.Command.html
pub fn submit_command(
&mut self,
command: impl Into<Command>,
target: impl Into<Option<Target>>,
) {
let target = target.into().unwrap_or_else(|| self.window_id.into());
self.command_queue.push_back((target, command.into()))
}

/// Get an object which can create text layouts.
pub fn text(&mut self) -> Text {
self.window.text()
Expand Down
1 change: 1 addition & 0 deletions druid/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
window: ctx.window,
base_state: &mut self.state,
window_id: ctx.window_id,
command_queue: ctx.command_queue,
};

self.inner
Expand Down
1 change: 1 addition & 0 deletions druid/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ impl<T: Data> Window<T> {
let mut base_state = BaseState::new(self.root.id());
let mut update_ctx = UpdateCtx {
base_state: &mut base_state,
command_queue: queue,
window: &self.handle,
window_id: self.id,
};
Expand Down

0 comments on commit 1384e6c

Please sign in to comment.