Trait pixels_graphics_lib::scenes::Scene
source · pub trait Scene<SR: Clone + PartialEq + Debug, SN: Clone + PartialEq + Debug> {
// Required method
fn update(
&mut self,
timing: &Timing,
mouse_xy: Coord,
held_keys: &[KeyCode]
) -> SceneUpdateResult<SR, SN>;
// Provided methods
fn render(
&self,
graphics: &mut Graphics<'_>,
mouse_xy: Coord,
held_keys: &[KeyCode]
) { ... }
fn on_key_down(
&mut self,
key: KeyCode,
mouse_xy: Coord,
held_keys: &[KeyCode]
) { ... }
fn on_key_up(
&mut self,
key: KeyCode,
mouse_xy: Coord,
held_keys: &[KeyCode]
) { ... }
fn on_mouse_down(
&mut self,
xy: Coord,
button: MouseButton,
held_keys: &[KeyCode]
) { ... }
fn on_mouse_up(
&mut self,
xy: Coord,
button: MouseButton,
held_keys: &[KeyCode]
) { ... }
fn on_scroll(
&mut self,
xy: Coord,
x_diff: isize,
y_diff: isize,
held_keys: &[KeyCode]
) { ... }
fn resuming(&mut self, result: Option<SR>) { ... }
fn is_dialog(&self) -> bool { ... }
}
Expand description
Scenes represent a mode/feature of a programs UI For example in an image editor you could have the main menu, editor, and save dialog as scenes and in an RPG you could have the field, battle and menu screens as scenes
Scenes can be fullscreen or smaller, such as a dialog
Common mistakes
- If you use a field to store the SceneUpdateResult and return in update() and then forget to clear it in resuming after a child returns then the child will immediately reopen
Required Methods§
fn update( &mut self, timing: &Timing, mouse_xy: Coord, held_keys: &[KeyCode] ) -> SceneUpdateResult<SR, SN>
Provided Methods§
fn render( &self, graphics: &mut Graphics<'_>, mouse_xy: Coord, held_keys: &[KeyCode] )
sourcefn on_key_down(&mut self, key: KeyCode, mouse_xy: Coord, held_keys: &[KeyCode])
fn on_key_down(&mut self, key: KeyCode, mouse_xy: Coord, held_keys: &[KeyCode])
Called when a keyboard key is being pressed down
Arguments
key
- The latest pressed keyheld_keys
- Any other keys that are being pressed down
sourcefn on_key_up(&mut self, key: KeyCode, mouse_xy: Coord, held_keys: &[KeyCode])
fn on_key_up(&mut self, key: KeyCode, mouse_xy: Coord, held_keys: &[KeyCode])
Called when a keyboard key has been released
Arguments
key
- The latest pressed keyheld_keys
- Any other keys that are being pressed down
sourcefn on_mouse_down(
&mut self,
xy: Coord,
button: MouseButton,
held_keys: &[KeyCode]
)
fn on_mouse_down( &mut self, xy: Coord, button: MouseButton, held_keys: &[KeyCode] )
Called when a mouse button has been pressed down
Arguments
xy
- The on screen coord of the cursorbutton
- The pressed mouse buttonheld_keys
- Any keyboards keys that are being pressed down
sourcefn on_mouse_up(&mut self, xy: Coord, button: MouseButton, held_keys: &[KeyCode])
fn on_mouse_up(&mut self, xy: Coord, button: MouseButton, held_keys: &[KeyCode])
Called when a mouse button has been released
Arguments
xy
- The on screen coord of the cursorbutton
- The pressed mouse buttonheld_keys
- Any keyboards keys that are being pressed down
sourcefn on_scroll(
&mut self,
xy: Coord,
x_diff: isize,
y_diff: isize,
held_keys: &[KeyCode]
)
fn on_scroll( &mut self, xy: Coord, x_diff: isize, y_diff: isize, held_keys: &[KeyCode] )
Called when the mouse scroll function has been used
Arguments
xy
- The on screen coord of the cursory_diff
- The distance scrolled verticallyx_diff
- The distance scrolled horizontallyheld_keys
- Any keyboards keys that are being pressed down