FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    settable_prop

    macro · ferroui-reactiveui · v0.5.0

    macro_rules! settable_prop
    

    A SettableProperty from getters: the path of prop! and the setter set_<last getter> of the object that owns the last property.

    settable_prop!(View => name_text) reads with name_text(), observes NameText and writes with set_name_text(value); settable_prop!(Person => address.street) writes with address().set_street(value). The steps take as "Name" as prop! does; the setter is named after the getter all the same.

    use ferroui_reactiveui::settable_prop;
    use ferroui_system::component_model::INotifyPropertyChanged;
    use ferroui_system::events::Event;
    use std::cell::RefCell;
    use std::rc::Rc;
    
    struct Person { name: RefCell<String>, changed: Event<str> }
    impl Person {
        fn name(&self) -> String { self.name.borrow().clone() }
        fn set_name(&self, value: String) { *self.name.borrow_mut() = value; self.changed.raise("Name"); }
    }
    impl INotifyPropertyChanged for Person {
        fn property_changed(&self) -> &Event<str> { &self.changed }
    }
    
    let property = settable_prop!(Person => name);
    let person = Rc::new(Person { name: RefCell::new(String::new()), changed: Event::new() });
    property.set(&person, "Ada".to_owned());
    assert_eq!(property.get(&person), "Ada");
    assert_eq!(property.path().path(), "Name");
    

    View source

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.