[][src]Trait coffee::load::loading_screen::LoadingScreen

pub trait LoadingScreen {
    fn on_progress(&mut self, progress: &Progress, window: &mut Window);

    fn run<T>(&mut self, task: Task<T>, window: &mut Window) -> Result<T> { ... }
}

A loading screen keeps track of the progress of a task and provides feedback to the user.

Usage

If you have a LoadingScreen, you can use it in your Game::new method easily. Let's say we want to use the ProgressBar loading screen in our game:

use coffee::{Game, Result};
use coffee::load::{Task, Join, LoadingScreen};
use coffee::load::loading_screen::ProgressBar;
use coffee::graphics::Window;

struct MyGame {
    state: State,
    // ...
}

impl Game for MyGame {
    // ...

    fn new(window: &mut Window) -> Result<(MyGame, View, Input)> {
        let load =
            (
                Task::stage("Loading state...", State::load()),
                Task::stage("Loading assets...", View::load()),
            )
                .join();

        // Create the loading screen and use `run`
        let mut progress_bar = ProgressBar::new(window.gpu());
        let (state, view) = progress_bar.run(load, window)?;

        Ok((MyGame { state }, view, Input::new()))
    }

    // ...
}

Future plans

As of now, Coffee only ships with the ProgressBar loading screen. In the near future, the plan is to add more interesting (and configurable!) loading screens. If you make a cool loading screen or have an interesting idea and you would like to share it, feel free to create an issue or open a pull request!

Required methods

fn on_progress(&mut self, progress: &Progress, window: &mut Window)

React to task progress.

You should provide feedback to the user here. You can draw on the given Window, like in Game::draw.

Loading content...

Provided methods

fn run<T>(&mut self, task: Task<T>, window: &mut Window) -> Result<T>

Run the loading screen with a task and obtain its result.

By default, it runs the task and refreshes the window when there is progress.

Loading content...

Implementors

impl LoadingScreen for ProgressBar[src]

fn run<T>(&mut self, task: Task<T>, window: &mut Window) -> Result<T>[src]

Loading content...