[][src]Trait coffee::ui::UserInterface

pub trait UserInterface: Game {
    type Message;
    type Renderer: Renderer;
    fn react(&mut self, message: Self::Message, window: &mut Window);
fn layout(
        &mut self,
        window: &Window
    ) -> Element<Self::Message, Self::Renderer>; fn configuration() -> <Self::Renderer as Renderer>::Configuration { ... }
fn run(window_settings: WindowSettings) -> Result<()>
        Self: 'static + Sized
, { ... } }

The user interface of your game.

Implementors of this trait must also implement Game and should hold all the state of the user interface.

Be sure to read the introduction of the ui module first! It will help you understand the purpose of this trait.

Associated Types

type Message

The type of messages handled by the user interface.

Messages are produced by user interactions. The runtime feeds these messages to the react method, which updates the state of the game depending on the user interaction.

The Message type should normally be an enumeration of different user interactions. For example:

enum Message {
    // ...

type Renderer: Renderer

The renderer used to draw the user interface.

If you just want to use the built-in widgets in Coffee, you should use the built-in Renderer type here.

If you want to write your own renderer, you will need to implement the core::Renderer trait.

Loading content...

Required methods

fn react(&mut self, message: Self::Message, window: &mut Window)

Reacts to a Message, updating game state as needed.

This method is analogous to Game::interact, but it processes a Message instead of Game::Input.

The logic of your user interface should live here.

fn layout(&mut self, window: &Window) -> Element<Self::Message, Self::Renderer>

Produces the layout of the user interface.

It returns an Element containing the different widgets that comprise the user interface.

This method is called on every frame. The produced layout is rendered and used by the runtime to allow user interaction.

Loading content...

Provided methods

fn configuration() -> <Self::Renderer as Renderer>::Configuration

Builds the renderer configuration for the user interface.

By default, it returns Default::default().

fn run(window_settings: WindowSettings) -> Result<()> where
    Self: 'static + Sized

Runs the Game with a user interface.

Call this method instead of Game::run once you have implemented the UserInterface.

Loading content...


Loading content...