Trait pixels_graphics_lib::scenes::Scene
source · pub trait Scene<SR: Clone + PartialEq + Debug, SN: Clone + PartialEq + Debug> {
// Required methods
fn render(&self, graphics: &mut Graphics<'_>, mouse_xy: Coord);
fn update(
&mut self,
timing: &Timing,
mouse_xy: Coord,
held_keys: &Vec<&KeyCode>
) -> SceneUpdateResult<SR, SN>;
fn resuming(&mut self, result: Option<SR>);
// Provided methods
fn on_key_down(
&mut self,
key: KeyCode,
mouse_xy: Coord,
held_keys: &Vec<&KeyCode>
) { ... }
fn on_key_up(
&mut self,
key: KeyCode,
mouse_xy: Coord,
held_keys: &Vec<&KeyCode>
) { ... }
fn on_mouse_down(
&mut self,
xy: Coord,
button: MouseButton,
held_keys: &Vec<&KeyCode>
) { ... }
fn on_mouse_up(
&mut self,
xy: Coord,
button: MouseButton,
held_keys: &Vec<&KeyCode>
) { ... }
fn on_scroll(
&mut self,
xy: Coord,
x_diff: isize,
y_diff: isize,
held_keys: &Vec<&KeyCode>
) { ... }
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§
sourcefn render(&self, graphics: &mut Graphics<'_>, mouse_xy: Coord)
fn render(&self, graphics: &mut Graphics<'_>, mouse_xy: Coord)
Render scene contents using graphics
If this is a fullscreen scene it should draw a color over the whole screen otherwise
you may see rendering issues (use graphics.clear(Color)
).
Note
mouse_xy will be -1,-1 if this screen is in the background and a non full screen scene is active
sourcefn update(
&mut self,
timing: &Timing,
mouse_xy: Coord,
held_keys: &Vec<&KeyCode>
) -> SceneUpdateResult<SR, SN>
fn update( &mut self, timing: &Timing, mouse_xy: Coord, held_keys: &Vec<&KeyCode> ) -> SceneUpdateResult<SR, SN>
During this method the scene should update animations and anything else that relies on time or on held keys
Arguments
timing
- Deltas and other timing info, generally you should use thefixed_time_step
fieldxy
- The on screen coord of the mouse cursorheld_keys
- Any keyboards keys that are being pressed down
Returns
Provided Methods§
sourcefn on_key_down(
&mut self,
key: KeyCode,
mouse_xy: Coord,
held_keys: &Vec<&KeyCode>
)
fn on_key_down( &mut self, key: KeyCode, mouse_xy: Coord, held_keys: &Vec<&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: &Vec<&KeyCode>
)
fn on_key_up( &mut self, key: KeyCode, mouse_xy: Coord, held_keys: &Vec<&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: &Vec<&KeyCode>
)
fn on_mouse_down( &mut self, xy: Coord, button: MouseButton, held_keys: &Vec<&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: &Vec<&KeyCode>
)
fn on_mouse_up( &mut self, xy: Coord, button: MouseButton, held_keys: &Vec<&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: &Vec<&KeyCode>
)
fn on_scroll( &mut self, xy: Coord, x_diff: isize, y_diff: isize, held_keys: &Vec<&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