[][src]Struct neutrino::widgets::checkbox::CheckBox

pub struct CheckBox { /* fields omitted */ }

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

impl Widget for CheckBox[src]

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]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,