-
Notifications
You must be signed in to change notification settings - Fork 8
Widgets
Emerald edited this page Mar 14, 2024
·
3 revisions
Widgets are any function that takes in anything, and returns a widget result: an Ok(()) or an Error.
An example of a widget could be something as simple as
fn widget(mut frame: ResMut<WidgetFrame>) -> WidgetResult {
// Do Something With frame
Ok(())
}To something as complex as
fn widget(
a: ResMut<A>,
b: ResMut<B>,
c: Res<C>,
d: Res<D>
) -> WidgetResult {
...
}They all do the same thing, take in states and modify what your program does in incremental steps!
These are how you recieve the states from the app! A Res is an immutable reference to a Resource, and RefMut is a mutable reference to a resource!
I've written the widgets using a system very similar to how bevy's systems work. By using dependency injection, we can hand the function parameters to the widget as we call it, so the compiler is able to see the system as the same function, and can be easily generated at runtime.