[−][src]Struct neutrino::widgets::checkbox::CheckBox
A togglable checkbox with a label
Fields
name: String
state: CheckBoxState
listener: Option<Box<dyn CheckBoxListener>>
Default values
name: name.to_string()
state:
text: "CheckBox".to_string()
checked: false
disabled: false
stretched: false
style: "".to_string()
listener: None
Style
div.checkbox[.disabled][.checked]
div.checkbox-outer
div.checkbox-inner
label
Example
use std::cell::RefCell; use std::rc::Rc; use neutrino::widgets::checkbox::{CheckBox, CheckBoxListener, CheckBoxState}; use neutrino::utils::theme::Theme; use neutrino::{App, Window}; struct Switch { value: bool, } impl Switch { fn new() -> Self { Self { value: false } } fn value(&self) -> bool { self.value } fn toggle(&mut self) { self.value = !self.value; } } struct MyCheckBoxListener { switch: Rc<RefCell<Switch>>, } impl MyCheckBoxListener { pub fn new(switch: Rc<RefCell<Switch>>) -> Self { Self { switch } } } impl CheckBoxListener for MyCheckBoxListener { fn on_change(&self, _state: &CheckBoxState) { self.switch.borrow_mut().toggle(); } fn on_update(&self, state: &mut CheckBoxState) { state.set_checked(self.switch.borrow().value()); } } fn main() { let switch = Rc::new(RefCell::new(Switch::new())); let my_listener = MyCheckBoxListener::new(Rc::clone(&switch)); let mut my_checkbox = CheckBox::new("my_checkbox"); my_checkbox.set_text("Toggle me !"); my_checkbox.set_listener(Box::new(my_listener)); }
Methods
impl CheckBox
[src]
pub fn new(name: &str) -> Self
[src]
Create a CheckBox
pub fn set_text(&mut self, text: &str)
[src]
Set the text
pub fn set_checked(&mut self)
[src]
Set the checked flag to true
pub fn set_disabled(&mut self)
[src]
Set the disabled flag to true
pub fn set_stretched(&mut self)
[src]
Set the stretched flag to true
pub fn set_listener(&mut self, listener: Box<dyn CheckBoxListener>)
[src]
Set the listener
pub fn set_style(&mut self, style: &str)
[src]
Set the style
Trait Implementations
Auto Trait Implementations
impl !Send for CheckBox
impl Unpin for CheckBox
impl !Sync for CheckBox
impl !UnwindSafe for CheckBox
impl !RefUnwindSafe for CheckBox
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,