Trait Scene

Source
pub trait Scene<SR: Clone + PartialEq + Debug, SN: Clone + PartialEq + Debug> {
    // Required method
    fn update(
        &mut self,
        timing: &Timing,
        mouse: &MouseData,
        held_keys: &FxHashSet<KeyCode>,
        window: &Window,
    ) -> SceneUpdateResult<SR, SN>;

    // Provided methods
    fn id(&self) -> u32 { ... }
    fn render(
        &self,
        graphics: &mut Graphics<'_>,
        mouse: &MouseData,
        held_keys: &FxHashSet<KeyCode>,
    ) { ... }
    fn on_key_down(
        &mut self,
        key: KeyCode,
        mouse: &MouseData,
        held_keys: &FxHashSet<KeyCode>,
    ) { ... }
    fn on_key_up(
        &mut self,
        key: KeyCode,
        mouse: &MouseData,
        held_keys: &FxHashSet<KeyCode>,
    ) { ... }
    fn on_mouse_down(
        &mut self,
        mouse: &MouseData,
        mouse_button: MouseButton,
        held_keys: &FxHashSet<KeyCode>,
    ) { ... }
    fn on_mouse_up(
        &mut self,
        mouse: &MouseData,
        mouse_button: MouseButton,
        held_keys: &FxHashSet<KeyCode>,
    ) { ... }
    fn on_mouse_click(
        &mut self,
        down_at: Coord,
        mouse: &MouseData,
        mouse_button: MouseButton,
        held_keys: &FxHashSet<KeyCode>,
    ) { ... }
    fn on_mouse_drag(
        &mut self,
        mouse: &MouseData,
        held_keys: &FxHashSet<KeyCode>,
    ) { ... }
    fn on_scroll(
        &mut self,
        mouse: &MouseData,
        x_diff: isize,
        y_diff: isize,
        held_keys: &FxHashSet<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§

Source

fn update( &mut self, timing: &Timing, mouse: &MouseData, held_keys: &FxHashSet<KeyCode>, window: &Window, ) -> 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

Provided Methods§

Source

fn id(&self) -> u32

Source

fn render( &self, graphics: &mut Graphics<'_>, mouse: &MouseData, held_keys: &FxHashSet<KeyCode>, )

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 will be empty if this screen is in the background and a non full screen scene is active

Source

fn on_key_down( &mut self, key: KeyCode, mouse: &MouseData, held_keys: &FxHashSet<KeyCode>, )

Called when a keyboard key is being pressed down

§Arguments
  • key - The latest pressed key
  • mouse - position, held state of mouse
  • held_keys - Any other keys that are being pressed down
Source

fn on_key_up( &mut self, key: KeyCode, mouse: &MouseData, held_keys: &FxHashSet<KeyCode>, )

Called when a keyboard key has been released

§Arguments
  • key - The latest pressed key
  • mouse - position, held state of mouse
  • held_keys - Any other keys that are being pressed down
Source

fn on_mouse_down( &mut self, mouse: &MouseData, mouse_button: MouseButton, held_keys: &FxHashSet<KeyCode>, )

Called when a mouse button has been pressed down

§Arguments
  • mouse - position, held state of mouse
  • mouse_button = which button was pressed
  • held_keys - Any keyboards keys that are being pressed down
Source

fn on_mouse_up( &mut self, mouse: &MouseData, mouse_button: MouseButton, held_keys: &FxHashSet<KeyCode>, )

Called when a mouse button has been released

[on_mouse_click] will also be called after

§Arguments
  • mouse - position, held state of mouse
  • mouse_button = which button was released
  • held_keys - Any keyboards keys that are being pressed down
Source

fn on_mouse_click( &mut self, down_at: Coord, mouse: &MouseData, mouse_button: MouseButton, held_keys: &FxHashSet<KeyCode>, )

Called when a mouse button has been pressed and released

[on_mouse_up] will also be called before

§Arguments
  • down_at - position where mouse button was clicked
  • mouse - position, held state of mouse
  • mouse_button = which button was clicked
  • held_keys - Any keyboards keys that are being pressed down
Source

fn on_mouse_drag(&mut self, mouse: &MouseData, held_keys: &FxHashSet<KeyCode>)

Called when the mouse moved while any button is held down

§Arguments
  • mouse - position, held state of mouse
  • held_keys - Any keyboards keys that are being pressed down
Source

fn on_scroll( &mut self, mouse: &MouseData, x_diff: isize, y_diff: isize, held_keys: &FxHashSet<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 resuming(&mut self, result: Option<SR>)

Called when a child scene is closing

§Arguments
  • result - Optional data from child scene
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§