Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating child widgets? #1073

Closed
timothyhollabaugh opened this issue Jun 30, 2020 · 5 comments · Fixed by #1128
Closed

Updating child widgets? #1073

timothyhollabaugh opened this issue Jun 30, 2020 · 5 comments · Fixed by #1128

Comments

@timothyhollabaugh
Copy link

I have a custom widget that has a tree of child widgets, where the data of the child widgets is made up of both the widget's data and some of the widget's internal state. The event, lifecycle, update, layout, and paint methods all handle assembling these together.

In particular, the event method looks like this:

fn event(&mut self, ctx: &mut EventCtx, event: &Event, tools: &mut ToolTable, env: &Env) {
    let mut data = (self.state.to_owned(), tools.to_owned());

    self.widgets.event(ctx, event, &mut data, env);

    let (new_state, new_tools) = data;

    if !new_state.same(&self.state) {
        self.state = new_state;
    }

    if !new_tools.same(&new_tools) {
        *tools = new_tools;
    }
}

This works great, except that when the widget's internal state changes, the children do not get updated.

Does it make sense to add a request_update method on EventCtx? Or is there a better way to do this?

@timothyhollabaugh
Copy link
Author

I'll take a look. I changed up my UI to avoid this problem, so I'll close this issue.

@raphlinus
Copy link
Contributor

I'm going to reopen this, as I think a request_update method on EventCtx is something we really should have. I'll try to make a PR for it.

raphlinus added a commit that referenced this issue Aug 13, 2020
Fixes #1073. This version is largely for discussion, as it hasn't been
tested at all.
@cmyr
Copy link
Member

cmyr commented Aug 20, 2020

thinking about this, my first thought is that you should be responsible for calling update in your own update call? If you're a container you are responsible for forwarding all calls to children as needed.

@raphlinus
Copy link
Contributor

Yes, we discussed this on Zulip and the consensus is to just have the request_update call for the parent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants