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