Skip to main content

ScreenStack

Struct ScreenStack 

Source
pub struct ScreenStack<G: GameData> { /* private fields */ }
Expand description

The stack of open screens. Only the top screen is updated; drawing starts at the top-most opaque screen and goes up through the overlays above it.

Implementations§

Source§

impl<G: GameData> ScreenStack<G>

Source

pub fn new(root: Box<dyn Screen<G>>) -> Self

A stack holding just root.

Source

pub fn guard_actions(&mut self, on: bool)

Turns the guard on or off: while it is on, a screen that declares its actions (Screen::actions) is handed only those (FrameInput::declared), and the others are logged (undeclared). So a test of a screen that reacts to an action it didn’t declare fails. The test Harness turns it on; a game never needs to.

Source

pub fn undeclared(&self) -> &[(&'static str, G::Action)]

Every action held back from a screen that doesn’t declare it while the guard was on, oldest first, with the screen’s name. A player pressing a key the screen has no use for lands here too: it says why a screen didn’t react, not that it is wrong.

Source

pub fn is_empty(&self) -> bool

Whether no screen is open (the game should quit).

Source

pub fn names(&self) -> Vec<&'static str>

Names of the open screens, bottom first.

Source

pub fn top_name(&self) -> Option<&'static str>

Name of the top screen.

Source

pub fn top_actions(&self) -> Option<Vec<G::Action>>

The actions the top screen declares it reacts to (Screen::actions), if it declares them.

Source

pub fn push(&mut self, screen: Box<dyn Screen<G>>)

Puts screen on top, to build a stack: the screen below is not told (Screen::covered); apply_in with Transition::Push tells it.

Source

pub fn find<T: Any>(&self) -> Option<&T>

The top-most screen of type T (one that opts in with Screen::as_any).

Source

pub fn state_hash(&self) -> Option<StateHash>

The top-most screen’s Screen::state_hash that has one.

Source

pub fn find_mut<T: Any>(&mut self) -> Option<&mut T>

The top-most screen of type T, mutable (Screen::as_any_mut).

Source

pub fn update( &mut self, ctx: &mut Ctx<G>, input: &FrameInput<G::Action>, ) -> bool

Updates the top screen and applies its transition (apply_in). Returns true if the game should quit (Transition::Quit, or the last screen popped). Does nothing and returns true on an empty stack.

Source

pub fn apply_in(&mut self, ctx: &mut Ctx<G>, transition: Transition<G>) -> bool

Applies a transition as if the top screen had returned it, telling the screens it covers and uncovers: a push calls the old top’s Screen::covered; a pop calls the new top’s Screen::uncovered with what the screen popped with, then applies the transition that returns, and so on. A replace tells nobody. A screen that leaves (a pop or a replace) takes its sounds with it (AudioQueue::start_sound). Returns true if the game should quit.

Source

pub fn apply(&mut self, transition: Transition<G>) -> bool

Applies a transition as if the top screen had returned it, to the stack alone: no screen is told it is covered or uncovered, and a value popped with is dropped (apply_in tells them). Returns true if the game should quit.

Source

pub fn draw(&self, ctx: &Ctx<G>, buf: &mut GlyphBuffer)

Draws the top-most opaque screen and every overlay above it, bottom up. If every screen is an overlay, all are drawn.

Source

pub fn debug_draw(&self, ctx: &Ctx<G>, out: &mut Gizmos)

Asks every screen draw draws for its debug view’s gizmos (Screen::debug_draw), bottom up, so an overlay’s come after those of the screen under it.

Trait Implementations§

Source§

impl<G: GameData> Default for ScreenStack<G>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<G> !RefUnwindSafe for ScreenStack<G>

§

impl<G> !Send for ScreenStack<G>

§

impl<G> !Sync for ScreenStack<G>

§

impl<G> !UnwindSafe for ScreenStack<G>

§

impl<G> Freeze for ScreenStack<G>

§

impl<G> Unpin for ScreenStack<G>
where <G as GameData>::Action: Unpin,

§

impl<G> UnsafeUnpin for ScreenStack<G>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.