Skip to content

Commit

Permalink
Update documentation of submit_command methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
luleyleo committed Sep 6, 2020
1 parent f45a331 commit f0b2dd6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions druid/src/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ impl<'a> DelegateCtx<'a> {
/// submitted during the handling of an event are executed before
/// the [`update()`] method is called.
///
/// [`Target::Auto`] commands will be sent to every window (`Target::Global`).
///
/// [`Command`]: struct.Command.html
/// [`update()`]: trait.Widget.html#tymethod.update
pub fn submit_command(&mut self, command: impl Into<Command>) {
Expand Down
10 changes: 9 additions & 1 deletion druid/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ pub enum Target {
/// The target is a specific widget.
Widget(WidgetId),
/// The target will be determined automatically.
///
/// How this behaves depends on the context used to submit the command.
/// Each `submit_command` function should have documentation about the specific behavior.
Auto,
}

Expand Down Expand Up @@ -251,7 +254,7 @@ impl Selector<()> {
/// A selector that does nothing.
pub const NOOP: Selector = Selector::new("");

/// Set the commands target.
/// Turns this into a command with the specified target.
pub fn to(self, target: impl Into<Target>) -> Command {
Command::from(self).to(target.into())
}
Expand All @@ -275,7 +278,12 @@ impl<T: Any> Selector<T> {
/// If the payload is `()` there is no need to call this,
/// as `Selector<()>` implements `Into<Command>`.
///
/// By default, the command will have [`Target::Auto`].
/// The [`Command::to`] method can be used to override this.
///
/// [`Command::new`]: struct.Command.html#method.new
/// [`Command::to`]: struct.Command.html#method.to
/// [`Target::Auto`]: enum.Target.html#variant.Auto
pub fn with(self, payload: T) -> Command {
Command::new(self, payload, Target::Auto)
}
Expand Down
2 changes: 2 additions & 0 deletions druid/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ impl_context_method!(
/// the [`update`] method is called; events submitted during [`update`]
/// are handled after painting.
///
/// [`Target::Auto`] commands will be sent to the window containing the widget.
///
/// [`Command`]: struct.Command.html
/// [`update`]: trait.Widget.html#tymethod.update
pub fn submit_command(&mut self, cmd: impl Into<Command>) {
Expand Down
5 changes: 3 additions & 2 deletions druid/src/ext_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,16 @@ impl ExtEventSink {
///
/// The `payload` must implement `Any + Send + Sync`.
///
/// If no explicit `Target` is submitted, the `Command` will be sent to
/// If submitted with `Target::Auto`, the [`Command`] will be sent to
/// the application's first window; if that window is subsequently closed,
/// then the command will be sent to *an arbitrary other window*.
///
/// This behavior may be changed in the future; in any case, you should
/// probably provide an explicit `Target`.
/// probably provide an explicit [`Target`].
///
/// [`Command`]: struct.Command.html
/// [`Selector`]: struct.Selector.html
/// [`Target`]: struct.Target.html
pub fn submit_command<T: Any + Send>(
&self,
selector: Selector<T>,
Expand Down

0 comments on commit f0b2dd6

Please sign in to comment.