-
Notifications
You must be signed in to change notification settings - Fork 8
States
Emerald edited this page Mar 14, 2024
·
6 revisions
States are pretty simple, it is how you take any data in and out of your widgets!
An Example of a state is
#[derive(State)]
pub struct IntState(i32);This will allow you to then insert the state into your app, and retrieve it from any function!
If you need an example of how to insert a state, all you have to do is:
App::new()?.states(IntState(0));This will register your state, allowing you to use it in any widget!
Say you need to get/modify the int in IntState
It's pretty simple! Just make a widget that takes in that state!
fn widget(int_state: ResMut<IntState>) -> WidgetResult {
int_state.0 += 1;
Ok(())
}See! Now you can modify any state within your widgets!