-
Notifications
You must be signed in to change notification settings - Fork 8
Sets
A set is a way to abstract away from a massive main function! Break up all of the big systems in your code, and register everything needed with a single function!
#[set]
fn SimpleSet(app: App) -> App {
/// Do anything to the app here!
}Super simple, and makes it even simpler to add it!
App::new(100).sets(SimpleSet)You can add multiple sets in a single function, just like you can with widgets!
App::new(100).sets((SetOne, SetTwo))And that's it!
That's because set's are actually structs that implement a trait! We do this in order to improve ergonomics, and allow for custom states! So when you write the #[set] above the function, you are actually telling the function to become a struct, and have the function body as a function tied to a trait!
It's pretty simple! It's actually very similar to what you did above! Let's make a set that will register a function if and only if it's variable is set to true!
struct CustomSet {
have_state: bool
}
impl Set for CustomSet {
fn register_set(&self, app: App) -> App {
if self.have_state {
app.widget(...)
} else {
app
}
}
}Wow! That's cool