pub trait GraphicsFlow<S, E: Send> {
// Provided methods
fn on_init(&mut self, _ctx: &mut Context, _state: &mut S) -> Out<S, E> { ... }
fn on_click(
&mut self,
_ctx: &Context,
_state: &mut S,
_id: PickId,
) -> Out<S, E> { ... }
fn on_update(
&mut self,
_ctx: &Context,
_state: &mut S,
_dt: Duration,
) -> Out<S, E> { ... }
fn on_tick(&mut self, _ctx: &Context, _state: &mut S) -> Out<S, E> { ... }
fn on_device_events(
&mut self,
_ctx: &Context,
_state: &mut S,
_event: &DeviceEvent,
) -> Out<S, E> { ... }
fn on_window_events(
&mut self,
_ctx: &Context,
_state: &mut S,
_event: &WindowEvent,
) -> Out<S, E> { ... }
fn on_custom_events(
&mut self,
_ctx: &Context,
_state: &mut S,
event: E,
) -> Option<E> { ... }
fn on_render<'pass>(&self) -> Render<'_, 'pass> { ... }
}Expand description
Trait for implementing a renderable scene or game state.
A GraphicsFlow manages a self-contained portion of the application:
rendering, input handling, animations, and state updates. The engine
coordinates multiple flows, passes events to them, and composes their renders.
§Lifecycle
on_init()is called once when the flow is created; configure context (camera, clear color, etc.)on_window_events()andon_device_events()are called for each winit input eventon_update()is called every frameon_tick()is called everytick_duration_millison_click()is called when an object with this flow’s ID is clickedon_custom_events()is called for custom application eventson_render()is called each frame and specifies how to renderself
Provided Methods§
Sourcefn on_init(&mut self, _ctx: &mut Context, _state: &mut S) -> Out<S, E>
fn on_init(&mut self, _ctx: &mut Context, _state: &mut S) -> Out<S, E>
Initialize the flow and configure the context.
This is the only place to modify the Context and configure things such as the default background colour or camera start position.
Sourcefn on_click(&mut self, _ctx: &Context, _state: &mut S, _id: PickId) -> Out<S, E>
fn on_click(&mut self, _ctx: &Context, _state: &mut S, _id: PickId) -> Out<S, E>
Handle a click on an object rendered by this flow.
on_click is triggered when something on the screen (rendered by self) was clicked on.
id is the ID that correlates to a specific mesh set via on_render.
It is advised to use a unique u32 id for each element that should be selectable
When the render type Custom is used then also picking has to be implemented by the caller.
See flow_ngin::pick::draw_to_pick_buffer for more information about custom picking.
picking; see [crate::pick::draw_to_pick_buffer] for details.
Sourcefn on_update(
&mut self,
_ctx: &Context,
_state: &mut S,
_dt: Duration,
) -> Out<S, E>
fn on_update( &mut self, _ctx: &Context, _state: &mut S, _dt: Duration, ) -> Out<S, E>
Update state every frame.
Called every frame with the elapsed time dt. Use for animations,
physics updates, and other per-frame logic.
Sourcefn on_tick(&mut self, _ctx: &Context, _state: &mut S) -> Out<S, E>
fn on_tick(&mut self, _ctx: &Context, _state: &mut S) -> Out<S, E>
Update state periodically.
Called every tick_duration_millis milliseconds (configurable via context).
Use for discrete game logic that doesn’t need to run every frame.
Sourcefn on_device_events(
&mut self,
_ctx: &Context,
_state: &mut S,
_event: &DeviceEvent,
) -> Out<S, E>
fn on_device_events( &mut self, _ctx: &Context, _state: &mut S, _event: &DeviceEvent, ) -> Out<S, E>
Handle raw device events (keyboard, mouse hardware input).
Sourcefn on_window_events(
&mut self,
_ctx: &Context,
_state: &mut S,
_event: &WindowEvent,
) -> Out<S, E>
fn on_window_events( &mut self, _ctx: &Context, _state: &mut S, _event: &WindowEvent, ) -> Out<S, E>
Handle window events (keyboard, mouse, window resizing, etc.).
Sourcefn on_custom_events(
&mut self,
_ctx: &Context,
_state: &mut S,
event: E,
) -> Option<E>
fn on_custom_events( &mut self, _ctx: &Context, _state: &mut S, event: E, ) -> Option<E>
Handle custom application events.
Returns the event if it was not consumed, allowing it to be passed to
the next flow. Returning None means the event was consumed.