iced_runtime/multi_window/program.rs
1//! Build interactive programs using The Elm Architecture.
2use crate::Task;
3use crate::core::text;
4use crate::core::window;
5use crate::core::{Element, Renderer};
6
7/// The core of a user interface for a multi-window application following The Elm Architecture.
8pub trait Program: Sized {
9 /// The graphics backend to use to draw the [`Program`].
10 type Renderer: Renderer + text::Renderer;
11
12 /// The type of __messages__ your [`Program`] will produce.
13 type Message: std::fmt::Debug + Send;
14
15 /// The theme used to draw the [`Program`].
16 type Theme;
17
18 /// Handles a __message__ and updates the state of the [`Program`].
19 ///
20 /// This is where you define your __update logic__. All the __messages__,
21 /// produced by either user interactions or commands, will be handled by
22 /// this method.
23 ///
24 /// Any [`Task`] returned will be executed immediately in the background by the
25 /// runtime.
26 fn update(&mut self, message: Self::Message) -> Task<Self::Message>;
27
28 /// Returns the widgets to display in the [`Program`] for the `window`.
29 ///
30 /// These widgets can produce __messages__ based on user interaction.
31 fn view(
32 &self,
33 window: window::Id,
34 ) -> Element<'_, Self::Message, Self::Theme, Self::Renderer>;
35}