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

Conditionally display GTK objects in declerative style? #173

Open
simvux opened this issue Jun 17, 2019 · 2 comments
Open

Conditionally display GTK objects in declerative style? #173

simvux opened this issue Jun 17, 2019 · 2 comments

Comments

@simvux
Copy link

simvux commented Jun 17, 2019

Let's say I have this view

view! {
  gtk::Window {
    
  }
}

And i want to append a GTK object based on what it's in my model, how would i do it? I'd like to do something similar to this.

view! {
  gtk::Window {
    model.active_box
  }
}

where model.active_box is of type gtk::Box that gets swapped at runtime

or something like

view! {
  gtk::Window {
    match model.active_box {
        This -> gtk::Box {}
        That -> gtk::Box {}
    }
  }
}

where model.active_box is an enum.
Coming from Elm, this would feels like the natural way to do things in declerative style.

@antoyo
Copy link
Owner

antoyo commented Jun 17, 2019

Good idea.
I wonder if this could be generalized to support loops, but I guess this is where it becomes more complicated and might require a virtual "DOM" which does not seem to be the case for a match.

@simvux
Copy link
Author

simvux commented Jun 18, 2019

Ah okay, wasn't sure if this was something that was implemented or not. If anyone's looking to do what the title of this issue describes, check out the "widget-list.rs" example and observe how you can dynamically switch widgets in your update function using the .add_widget and .remove_widget methods.

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

No branches or pull requests

2 participants