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§
Sourcefn update(
&mut self,
timing: &Timing,
mouse: &MouseData,
held_keys: &FxHashSet<KeyCode>,
window: &Window,
) -> SceneUpdateResult<SR, SN>
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 thefixed_time_step
fieldxy
- The on screen coord of the mouse cursorheld_keys
- Any keyboards keys that are being pressed down
§Returns
Provided Methods§
fn id(&self) -> u32
Sourcefn render(
&self,
graphics: &mut Graphics<'_>,
mouse: &MouseData,
held_keys: &FxHashSet<KeyCode>,
)
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
Sourcefn on_key_down(
&mut self,
key: KeyCode,
mouse: &MouseData,
held_keys: &FxHashSet<KeyCode>,
)
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 keymouse
- position, held state of mouseheld_keys
- Any other keys that are being pressed down
Sourcefn on_key_up(
&mut self,
key: KeyCode,
mouse: &MouseData,
held_keys: &FxHashSet<KeyCode>,
)
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 keymouse
- position, held state of mouseheld_keys
- Any other keys that are being pressed down
Sourcefn on_mouse_down(
&mut self,
mouse: &MouseData,
mouse_button: MouseButton,
held_keys: &FxHashSet<KeyCode>,
)
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 mousemouse_button
= which button was pressedheld_keys
- Any keyboards keys that are being pressed down
Sourcefn on_mouse_up(
&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>, )
Called when a mouse button has been released
[on_mouse_click] will also be called after
§Arguments
mouse
- position, held state of mousemouse_button
= which button was releasedheld_keys
- Any keyboards keys that are being pressed down
Sourcefn on_mouse_click(
&mut self,
down_at: Coord,
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>, )
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 clickedmouse
- position, held state of mousemouse_button
= which button was clickedheld_keys
- Any keyboards keys that are being pressed down
Sourcefn on_mouse_drag(&mut self, mouse: &MouseData, held_keys: &FxHashSet<KeyCode>)
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 mouseheld_keys
- Any keyboards keys that are being pressed down
Sourcefn on_scroll(
&mut self,
mouse: &MouseData,
x_diff: isize,
y_diff: isize,
held_keys: &FxHashSet<KeyCode>,
)
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 cursory_diff
- The distance scrolled verticallyx_diff
- The distance scrolled horizontallyheld_keys
- Any keyboards keys that are being pressed down