pub struct WorkbenchButton {
pub id: &'static str,
pub glyph: &'static str,
pub tooltip: &'static str,
pub when: Option<fn(&ButtonState<'_>) -> bool>,
pub pressed: Option<fn(&ButtonState<'_>) -> bool>,
pub disabled: Option<fn(&ButtonState<'_>) -> Option<&'static str>>,
pub caption: Option<fn(&ButtonState<'_>) -> String>,
pub menu: &'static [WorkbenchButton],
}Expand description
A workbench-specific toolbar button, DATA ONLY (no egui, no behavior): the
shared toolbar-button helper renders it and a click surfaces id out of the
toolbar to the shell, which dispatches on id.
A button may be CONDITIONAL on document state (Self::when) and may read
as PRESSED from it (Self::pressed). Both are predicates over the
document (ButtonState) rather than flags the toolbar sets, so the
declaration still owns the whole answer and the row stays a renderer:
Drawing’s sheet buttons are offered only while a sheet is OPEN, and the armed
sketch draw tool is the lit button. A None predicate is the plain case —
always offered, never pressed — which is most buttons.
Three more readings came with the eCAD editors, whose actions carry them:
an offered button can be DISABLED with a reason (Self::disabled), its
label can be LIVE (Self::caption), and it can be a MENU of other buttons
(Self::menu).
Fields§
§id: &'static strStable id the shell matches on when the button is clicked.
glyph: &'static strThe single unicode glyph shown on the square button.
tooltip: &'static strHover tooltip / human label.
when: Option<fn(&ButtonState<'_>) -> bool>When this button is OFFERED at all. None = always.
pressed: Option<fn(&ButtonState<'_>) -> bool>When this button draws PRESSED (a toggle reflecting live state, the way
the toolbar’s wireframe and projection buttons do). None = a plain
momentary button.
disabled: Option<fn(&ButtonState<'_>) -> Option<&'static str>>Why an OFFERED button cannot act right now, or None when it can. A
disabled button is drawn greyed with the reason on hover, and the
workbench_button command refuses it with the same reason — never a
silent no-op. None = never disabled.
This is eCAD’s enabled, kept apart from offered the way eCAD keeps
it: Finish wire is on the row whenever the wire tool is, and greyed
until there is a wire to finish, rather than blinking in and out.
caption: Option<fn(&ButtonState<'_>) -> String>A LIVE label that replaces Self::tooltip where one is drawn, for a
button whose words describe state (Bend: vertical first) or depend on
the document (a copper layer’s name). None = the tooltip.
A MENU button’s entries: clicking it opens a menu of these, each with
its live caption and pressed state, instead of surfacing its own id.
The entries are buttons in every other respect — ids the lookup finds
and the workbench_button command presses. A menu is offered while any
entry is. Empty = an ordinary button.
Implementations§
Source§impl WorkbenchButton
impl WorkbenchButton
Sourcepub fn offered(&self, state: &ButtonState<'_>) -> bool
pub fn offered(&self, state: &ButtonState<'_>) -> bool
Whether state offers this button. The ONE reading of Self::when —
the toolbar row, the workbench_button command and describe_workbenches
all route through it, so a button an agent can call is exactly a button
the user can see.
Sourcepub fn is_pressed(&self, state: &ButtonState<'_>) -> bool
pub fn is_pressed(&self, state: &ButtonState<'_>) -> bool
Whether this button draws pressed in state.
Sourcepub fn disabled_reason(&self, state: &ButtonState<'_>) -> Option<&'static str>
pub fn disabled_reason(&self, state: &ButtonState<'_>) -> Option<&'static str>
Why this button cannot act in state, or None when it can.
Sourcepub fn label(&self, state: &ButtonState<'_>) -> String
pub fn label(&self, state: &ButtonState<'_>) -> String
The words this button shows in state: its live caption, or its tooltip.
Auto Trait Implementations§
impl Freeze for WorkbenchButton
impl RefUnwindSafe for WorkbenchButton
impl Send for WorkbenchButton
impl Sync for WorkbenchButton
impl Unpin for WorkbenchButton
impl UnsafeUnpin for WorkbenchButton
impl UnwindSafe for WorkbenchButton
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.