Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Add an example with mutable state #300

Open
@David-OConnor

Description

@David-OConnor

I'm not sure how to go about adding mutable shared state. I feel like this is a very common thing to want in a UI app, but I can't find it in the examples. I'm suspicious the solution involves Rc<RefCell<T>>, but am not sure how to do it. Eg:

let state = Rc::new(RefCell::new(state));  // Interior mutability to solve this?

let btn1 = Button::new_with_label("1");
btn1.connect_clicked(|_| {
    state.borrow_mut().value1 = true;
 });

let btn2 = Button::new_with_label("2");
btn2.connect_clicked(|_| {
    state.borrow_mut().value2 = true;
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions