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