Struct Checkbox
pub struct Checkbox { /* private fields */ }
Expand description
A checkbox used to display and toggle a boolean state.
Pressing the checkbox triggers the on_toggle
callback.
§Examples
§Basic checkbox
The checkbox must bound to some boolean data.
Checkbox::new(cx, AppData::value);
§Checkbox with an action
A checkbox can be used to trigger a callback when toggled. Usually this is emitting an event responsible for changing the data the checkbox is bound to.
Checkbox::new(cx, AppData::value).on_toggle(|cx| cx.emit(AppEvent::ToggleValue));
§Checkbox with a label
A checkbox is usually used with a label next to it describing what data the checkbox
is bound to or what the checkbox does when pressed. This can be done, for example, by
wrapping the checkbox in an HStack
and adding a Label
to it.
The Label can be used to trigger the checkbox by assigning the checkbox an id name and using it with the describing
modifier on the label.
HStack::new(cx, |cx| {
Checkbox::new(cx, AppData::value).id("check1");
Label::new(cx, "Press me").describing("check1");
});
§Custom checkbox
The with_icons
constructor can be used to create a checkbox with custom icons for both checked and unchecked states.
Checkbox::with_icons(cx, AppData::value, None, Some(ICON_X))
.on_toggle(|cx| cx.emit(AppEvent::ToggleValue));
Implementations§
§impl Checkbox
impl Checkbox
pub fn with_icons<T>(
cx: &mut Context,
checked: impl Lens<Target = bool>,
icon_default: Option<impl Res<T> + Clone + 'static>,
icon_checked: Option<impl Res<T> + Clone + 'static>,
) -> Handle<'_, Checkbox>
pub fn with_icons<T>( cx: &mut Context, checked: impl Lens<Target = bool>, icon_default: Option<impl Res<T> + Clone + 'static>, icon_checked: Option<impl Res<T> + Clone + 'static>, ) -> Handle<'_, Checkbox>
Creates a new checkbox with custom icons for both checked and unchecked states.
§Examples
Checkbox::with_icons(cx, AppData::value, None, Some(ICON_X))
.on_toggle(|cx| cx.emit(AppEvent::ToggleValue));
pub fn intermediate( cx: &mut Context, checked: impl Lens<Target = bool>, intermediate: impl Lens<Target = bool>, ) -> Handle<'_, Checkbox>
Trait Implementations§
§impl View for Checkbox
impl View for Checkbox
§fn element(&self) -> Option<&'static str>
fn element(&self) -> Option<&'static str>
§fn event(&mut self, cx: &mut EventContext<'_>, event: &mut Event)
fn event(&mut self, cx: &mut EventContext<'_>, event: &mut Event)
§fn build<F>(self, cx: &mut Context, content: F) -> Handle<'_, Self>
fn build<F>(self, cx: &mut Context, content: F) -> Handle<'_, Self>
§fn draw(&self, cx: &mut DrawContext<'_>, canvas: &Canvas)
fn draw(&self, cx: &mut DrawContext<'_>, canvas: &Canvas)
fn accessibility(&self, cx: &mut AccessContext<'_>, node: &mut AccessNode)
Auto Trait Implementations§
impl Freeze for Checkbox
impl !RefUnwindSafe for Checkbox
impl !Send for Checkbox
impl !Sync for Checkbox
impl Unpin for Checkbox
impl !UnwindSafe for Checkbox
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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
.§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
.§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.§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.