pub struct Checkbox<S, M> { /* private fields */ }Expand description
A boolean control: marker left, label right, the whole row one hit target.
A click anywhere on the row toggles, as do Enter and Space while focused. Hover and focus raise the row the way a small ghost button raises, so pointer and keyboard users both always see what they are on.
The checked state lives in app state and arrives through
checked; without that binding the checkbox paints but is
not focusable and answers no events. With the markers chosen freely, the
same component serves as a switch ([ON]/[off]) or an ASCII toggle
([x]/[ ]) — see the checkbox demo.
Its markers answer to checked/unchecked where the selection controls
say selected/unselected: a checkbox holds one row whose two states are
its content, not a choice among many.
Implementations§
Source§impl<S, M> Checkbox<S, M>
impl<S, M> Checkbox<S, M>
Sourcepub fn checked_marker(self, marker: impl Into<String>) -> Self
pub fn checked_marker(self, marker: impl Into<String>) -> Self
The marker shown while checked.
Any string works, including multi-character pairs like [x]; the
marker column takes the wider of the pair, so the label holds still as
the state flips. Pair it with
unchecked_marker so both states read as one
control — [ON]/[off] is a switch, [x]/[ ] an ASCII checkbox.
Sourcepub fn unchecked_marker(self, marker: impl Into<String>) -> Self
pub fn unchecked_marker(self, marker: impl Into<String>) -> Self
The marker shown while unchecked.
Sourcepub fn checked(
self,
read: impl Fn(&S) -> bool + 'static,
on_change: impl Fn(bool) -> M + 'static,
) -> Self
pub fn checked( self, read: impl Fn(&S) -> bool + 'static, on_change: impl Fn(bool) -> M + 'static, ) -> Self
Bind the checked state and the message that flips it.
read runs against current app state during rendering and event
handling. on_change receives the requested state — true after a
toggle onto checked, false after one onto unchecked. Without this
binding the checkbox is not focusable and answers no events.
Sourcepub const fn disabled(self, disabled: bool) -> Self
pub const fn disabled(self, disabled: bool) -> Self
Paint and answer muted, ignoring every event.
Sourcepub fn style(self, style: impl Fn(&Theme) -> CheckboxStyle + 'static) -> Self
pub fn style(self, style: impl Fn(&Theme) -> CheckboxStyle + 'static) -> Self
Supply exact colors, taking precedence over the theme.
Sourcepub fn width(&self) -> u16
pub fn width(&self) -> u16
Columns this checkbox paints: the marker column (the wider of the two
markers), one space, the label — the same in both states, so a row
sized from this holds its label still. See CheckboxWidget::width.
Trait Implementations§
Source§impl<S: 'static, M: 'static> Component<S, M> for Checkbox<S, M>
impl<S: 'static, M: 'static> Component<S, M> for Checkbox<S, M>
Source§fn prepare(&mut self, state: &S)
fn prepare(&mut self, state: &S)
Source§fn declare(&mut self, _ctx: &mut DeclareCtx<'_, S, M>)
fn declare(&mut self, _ctx: &mut DeclareCtx<'_, S, M>)
handle_event will need to read
back. Read moreSource§fn paint(&mut self, ctx: &mut PaintCtx<'_, S>)
fn paint(&mut self, ctx: &mut PaintCtx<'_, S>)
ctx carries the paint surface, area, app state,
theme, and interaction state. Read moreSource§fn handle_event(
&mut self,
event: &Event,
_state: &S,
_ctx: &mut EventCtx<'_>,
) -> EventResult<M>
fn handle_event( &mut self, event: &Event, _state: &S, _ctx: &mut EventCtx<'_>, ) -> EventResult<M>
Source§fn scope_options(&self) -> ScopeOptions
fn scope_options(&self) -> ScopeOptions
declare, so it cannot depend on paint.Auto Trait Implementations§
impl<S, M> !RefUnwindSafe for Checkbox<S, M>
impl<S, M> !Send for Checkbox<S, M>
impl<S, M> !Sync for Checkbox<S, M>
impl<S, M> !UnwindSafe for Checkbox<S, M>
impl<S, M> Freeze for Checkbox<S, M>
impl<S, M> Unpin for Checkbox<S, M>
impl<S, M> UnsafeUnpin for Checkbox<S, M>
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
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 more