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§

source

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

source

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 the fixed_time_step field
  • xy - The on screen coord of the mouse cursor
  • held_keys - Any keyboards keys that are being pressed down
Returns

SceneUpdateResult

  • In normal function this is will be Nothing
  • To close this scene return Pop
  • To open a child scene return Push
source

fn resuming(&mut self, result: Option<SR>)

Called when a child scene is closing

Arguments
  • result - Optional data from child scene

Provided Methods§

source

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 key
  • held_keys - Any other keys that are being pressed down
source

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 key
  • held_keys - Any other keys that are being pressed down
source

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 cursor
  • button - The pressed mouse button
  • held_keys - Any keyboards keys that are being pressed down
source

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 cursor
  • button - The pressed mouse button
  • held_keys - Any keyboards keys that are being pressed down
source

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 cursor
  • y_diff - The distance scrolled vertically
  • x_diff - The distance scrolled horizontally
  • held_keys - Any keyboards keys that are being pressed down
source

fn is_dialog(&self) -> bool

Return true if this scene doesn’t fill the screen or is transparent If this returns false the previous fullscreen scene will render as well

Implementors§