pub trait UserInterface: Game {
type Message;
type Renderer: Renderer;
// Required methods
fn react(&mut self, message: Self::Message, window: &mut Window);
fn layout(
&mut self,
window: &Window,
) -> Element<'_, Self::Message, Self::Renderer>;
// Provided methods
fn configuration() -> <Self::Renderer as Renderer>::Configuration { ... }
fn run(window_settings: WindowSettings) -> Result<()>
where Self: 'static + Sized { ... }
}Expand description
Required Associated Types§
Sourcetype Message
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 {
ButtonPressed,
CheckboxToggled(bool),
SliderChanged(f32),
// ...
}Sourcetype Renderer: Renderer
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.
Required Methods§
Sourcefn react(&mut self, message: Self::Message, window: &mut Window)
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.
Sourcefn layout(
&mut self,
window: &Window,
) -> Element<'_, Self::Message, Self::Renderer>
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.
Provided Methods§
Sourcefn configuration() -> <Self::Renderer as Renderer>::Configuration
fn configuration() -> <Self::Renderer as Renderer>::Configuration
Builds the renderer configuration for the user interface.
By default, it returns Default::default().
Sourcefn run(window_settings: WindowSettings) -> Result<()>where
Self: 'static + Sized,
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.