diff options
author | 2022-04-01 17:39:08 -0300 | |
---|---|---|
committer | 2023-01-09 11:27:04 -0800 | |
commit | b896e41c6e03f1447419194ce41d15fb0db39d96 (patch) | |
tree | bf2717e9a880a0f78e0151890d0c9a27525bdb06 /winit/src/multi_window.rs | |
parent | 287306e1ebec610c31e37782320fe00d20a6c9ac (diff) | |
download | iced-b896e41c6e03f1447419194ce41d15fb0db39d96.tar.gz iced-b896e41c6e03f1447419194ce41d15fb0db39d96.tar.bz2 iced-b896e41c6e03f1447419194ce41d15fb0db39d96.zip |
Unify `Application` and `Program`
Instead of creating a separate `multi_window::Program`, the new
`multi_window::Application` unifies both traits
Diffstat (limited to '')
-rw-r--r-- | winit/src/multi_window.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs index 4ea7383a..b519e471 100644 --- a/winit/src/multi_window.rs +++ b/winit/src/multi_window.rs @@ -9,15 +9,14 @@ use crate::mouse; use crate::renderer; use crate::widget::operation; use crate::{ - Command, Debug, Error, Executor, Proxy, Runtime, Settings, Size, - Subscription, + Command, Debug, Element, Error, Executor, Proxy, Renderer, Runtime, + Settings, Size, Subscription, }; use iced_futures::futures; use iced_futures::futures::channel::mpsc; use iced_graphics::compositor; use iced_graphics::window; -use iced_native::program::Program; use iced_native::user_interface::{self, UserInterface}; pub use iced_native::application::{Appearance, StyleSheet}; @@ -35,13 +34,34 @@ use std::mem::ManuallyDrop; /// /// When using an [`Application`] with the `debug` feature enabled, a debug view /// can be toggled by pressing `F12`. -pub trait Application: Program +pub trait Application: Sized where <Self::Renderer as crate::Renderer>::Theme: StyleSheet, { /// The data needed to initialize your [`Application`]. type Flags; + /// The graphics backend to use to draw the [`Program`]. + type Renderer: Renderer; + + /// The type of __messages__ your [`Program`] will produce. + type Message: std::fmt::Debug + Send; + + /// Handles a __message__ and updates the state of the [`Program`]. + /// + /// This is where you define your __update logic__. All the __messages__, + /// produced by either user interactions or commands, will be handled by + /// this method. + /// + /// Any [`Command`] returned will be executed immediately in the + /// background by shells. + fn update(&mut self, message: Self::Message) -> Command<Self::Message>; + + /// Returns the widgets to display in the [`Program`]. + /// + /// These widgets can produce __messages__ based on user interaction. + fn view(&self) -> Element<'_, Self::Message, Self::Renderer>; + /// Initializes the [`Application`] with the flags provided to /// [`run`] as part of the [`Settings`]. /// |