euv_engine/entity/trait.rs
1use crate::*;
2
3/// The base trait for all entity components.
4///
5/// Components encapsulate behavior that can be attached to an `Entity`.
6/// The engine calls lifecycle methods at appropriate times during the scheduler loop.
7pub trait Component {
8 /// Called once when the component is first added to an active entity
9 /// in a scene.
10 fn on_start(&mut self);
11
12 /// Called every fixed timestep with the elapsed time since the last update.
13 ///
14 /// # Arguments
15 ///
16 /// - `f64` - The delta time in seconds.
17 fn on_update(&mut self, delta_time: f64);
18
19 /// Called every render frame to draw the component onto the canvas.
20 ///
21 /// # Arguments
22 ///
23 /// - `&CanvasRenderingContext2d` - The canvas 2D rendering context.
24 /// - `&Transform2D` - The world-space transform of the owning entity.
25 fn on_render(&self, context: &CanvasRenderingContext2d, transform: &Transform2D);
26
27 /// Called once when the component is being removed or the entity is destroyed.
28 fn on_destroy(&mut self);
29
30 /// Returns the name of this component type for debugging and identification.
31 ///
32 /// # Returns
33 ///
34 /// - `&str` - The component name.
35 fn name(&self) -> &str;
36}