Skip to main content

Command

Struct Command 

Source
pub struct Command { /* private fields */ }
Expand description

An application operation shared by buttons, menus, toolbars, and direct callers (docs/commands.md): one id, one title, one availability, one handler, presented through button, menu_item and toolbar_item.

Built with Command::new in the scope that owns it. Clones share the handler and reactive sources. Builders configure a copy, not existing presentations. Invocation after the owning scope’s disposal is a no-op. This is a UI-thread value, not a global registry or a native edit role.

use day_pieces::prelude::*;
use day_reactive::Signal;

let count = Signal::new(0);
let add = Command::new(day_core::id!(add), "Add one", move || count.update(|n| *n += 1))
    .enabled(move || count.get() < 3);
assert!(add.invoke());
assert_eq!(count.get(), 1);

Implementations§

Source§

impl Command

Source

pub fn new<M>( id: ElementId, label: impl IntoText<M>, action: impl Fn() + 'static, ) -> Command

A command with its default presentation id, its title (the same sources as a button: a literal, a localized text, a signal, a closure) and its synchronous handler. Availability is checked before the handler is called. Captures the current reactive scope as the command’s owner.

Source

pub fn enabled<M>(self, enabled: impl IntoReactive<bool, M>) -> Self

Availability shared by every presentation and checked again on every invocation.

Source

pub fn checked<M>(self, checked: impl IntoReactive<bool, M>) -> Self

Optional check state. The handler owns mutations; invoking never flips this itself.

Source

pub fn icon(self, symbol: Symbol) -> Self

Source

pub fn image(self, name: impl Into<ImageName>) -> Self

Source

pub fn shortcut(self, shortcut: Shortcut) -> Self

Menu accelerator metadata. Only installing a menu entry installs the shortcut.

Source

pub fn id(&self) -> &str

Source

pub fn label(&self) -> String

Current title, with tracked reads for reactive presentation builders.

Source

pub fn is_enabled(&self) -> bool

Source

pub fn is_checked(&self) -> Option<bool>

Source

pub fn invoke(&self) -> bool

Run if still available. Returns whether the handler ran, not whether its work succeeded. Reads are untracked; invoking inside an effect does not subscribe it to the handler.

Source

pub fn button(&self) -> Decorated<Button>

A live button with this command’s default id, title, icon, availability, and handler. A push button does not draw a check mark. Add presentation styling as usual.

Source

pub fn menu_item(&self) -> MenuEntry

A live menu entry: its title, availability and check mark follow the command, and the menu it sits in re-lowers when they change. Invocation always rechecks availability.

Source

pub fn toolbar_item(&self) -> ToolbarEntry

Snapshot for a derived toolbar: .toolbar(move || vec![command.toolbar_item()]). Checked commands draw a toggle; the handler remains the sole owner of its state. Reactive builders refresh titles/checks; availability also gets a targeted live binding.

Trait Implementations§

Source§

impl Clone for Command

Source§

fn clone(&self) -> Command

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoReactive<T, StaticMark> for T
where T: Clone + 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Day API ↩ Guides· daybrite.dev