Skip to content

Add UpdateCtx::submit_command #855

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

Merged
merged 1 commit into from
Apr 17, 2020
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
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