Skip to content
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

Small fixes split out from #1107 . #1119

Merged
merged 3 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ You can find its changes [documented below](#060---2020-06-01).
- `WidgetExt::debug_widget_id` and `debug_paint_layout` now also apply to the widget they are called on. ([#1100] by [@finnerale])
- X11: Fix X11 errors caused by destroyed windows. ([#1103] by [@jneem])
- `ViewSwitcher` now skips the update after switching widgets. ([#1113] by [@finnerale])
- Key and KeyOrValue derive Clone ([#1119] by [@rjwittams])
- Allow submit_command from the layout method in Widgets ([#1119] by [@rjwittams])
jneem marked this conversation as resolved.
Show resolved Hide resolved

### Visual

Expand Down
39 changes: 26 additions & 13 deletions druid/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,6 @@ impl_context_method!(EventCtx<'_, '_>, UpdateCtx<'_, '_>, LifeCycleCtx<'_, '_>,
self.request_layout();
}

/// Submit a [`Command`] to be run after this event is handled.
///
/// Commands are run in the order they are submitted; all commands
/// submitted during the handling of an event are executed before
/// the [`update`] method is called; events submitted during [`update`]
/// are handled after painting.
///
/// [`Command`]: struct.Command.html
/// [`update`]: trait.Widget.html#tymethod.update
pub fn submit_command(&mut self, cmd: impl Into<Command>, target: impl Into<Option<Target>>) {
self.state.submit_command(cmd.into(), target.into())
}

/// Set the menu of the window containing the current widget.
/// `T` must be the application's root `Data` type (the type provided to [`AppLauncher::launch`]).
///
Expand All @@ -340,6 +327,32 @@ impl_context_method!(EventCtx<'_, '_>, UpdateCtx<'_, '_>, LifeCycleCtx<'_, '_>,
}
});

// methods on event, update, and lifecycle
impl_context_method!(
EventCtx<'_, '_>,
UpdateCtx<'_, '_>,
LifeCycleCtx<'_, '_>,
LayoutCtx<'_, '_>,
{
/// Submit a [`Command`] to be run after this event is handled.
///
/// Commands are run in the order they are submitted; all commands
/// submitted during the handling of an event are executed before
/// the [`update`] method is called; events submitted during [`update`]
/// are handled after painting.
///
/// [`Command`]: struct.Command.html
/// [`update`]: trait.Widget.html#tymethod.update
pub fn submit_command(
&mut self,
cmd: impl Into<Command>,
target: impl Into<Option<Target>>,
) {
self.state.submit_command(cmd.into(), target.into())
}
}
);

impl EventCtx<'_, '_> {
/// Set the cursor icon.
///
Expand Down
2 changes: 2 additions & 0 deletions druid/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct EnvImpl {
///
/// [`ValueType`]: trait.ValueType.html
/// [`Env`]: struct.Env.html
#[derive(Clone)]
pub struct Key<T> {
key: &'static str,
value_type: PhantomData<*const T>,
Expand Down Expand Up @@ -116,6 +117,7 @@ pub enum Value {
///
/// [`Key<T>`]: struct.Key.html
/// [`Env`]: struct.Env.html
#[derive(Clone)]
pub enum KeyOrValue<T> {
Concrete(Value),
Key(Key<T>),
Expand Down