Skip to main content

GraphicsFlow

Trait GraphicsFlow 

Source
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

  1. on_init() is called once when the flow is created; configure context (camera, clear color, etc.)
  2. on_window_events() and on_device_events() are called for each winit input event
  3. on_update() is called every frame
  4. on_tick() is called every tick_duration_millis
  5. on_click() is called when an object with this flow’s ID is clicked
  6. on_custom_events() is called for custom application events
  7. on_render() is called each frame and specifies how to render self

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn on_device_events( &mut self, _ctx: &Context, _state: &mut S, _event: &DeviceEvent, ) -> Out<S, E>

Handle raw device events (keyboard, mouse hardware input).

Source

fn on_window_events( &mut self, _ctx: &Context, _state: &mut S, _event: &WindowEvent, ) -> Out<S, E>

Handle window events (keyboard, mouse, window resizing, etc.).

Source

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.

Source

fn on_render<'pass>(&self) -> Render<'_, 'pass>

Return renderable objects for this flow.

Called each frame. Collect your objects into a Render and return it. The engine will batch and render all flows’ renders in optimal order.

Trait Implementations§

Source§

impl<State, Event> Debug for dyn GraphicsFlow<State, Event> + 'static

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Implementors§