Unify Application and Program
Instead of creating a separate `multi_window::Program`, the new `multi_window::Application` unifies both traits
This commit is contained in:
parent
287306e1eb
commit
b896e41c6e
2 changed files with 36 additions and 22 deletions
|
|
@ -132,7 +132,7 @@ pub trait Application: Sized {
|
||||||
..crate::renderer::Settings::from_env()
|
..crate::renderer::Settings::from_env()
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(crate::runtime::application::run::<
|
Ok(crate::runtime::multi_window::run::<
|
||||||
Instance<Self>,
|
Instance<Self>,
|
||||||
Self::Executor,
|
Self::Executor,
|
||||||
crate::renderer::window::Compositor<Self::Theme>,
|
crate::renderer::window::Compositor<Self::Theme>,
|
||||||
|
|
@ -142,27 +142,13 @@ pub trait Application: Sized {
|
||||||
|
|
||||||
struct Instance<A: Application>(A);
|
struct Instance<A: Application>(A);
|
||||||
|
|
||||||
impl<A> iced_winit::Program for Instance<A>
|
impl<A> crate::runtime::multi_window::Application for Instance<A>
|
||||||
where
|
|
||||||
A: Application,
|
|
||||||
{
|
|
||||||
type Renderer = crate::Renderer<A::Theme>;
|
|
||||||
type Message = A::Message;
|
|
||||||
|
|
||||||
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
|
|
||||||
self.0.update(message)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self) -> Element<'_, Self::Message, Self::Renderer> {
|
|
||||||
self.0.view()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<A> crate::runtime::Application for Instance<A>
|
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
{
|
{
|
||||||
type Flags = A::Flags;
|
type Flags = A::Flags;
|
||||||
|
type Renderer = crate::Renderer<A::Theme>;
|
||||||
|
type Message = A::Message;
|
||||||
|
|
||||||
fn new(flags: Self::Flags) -> (Self, Command<A::Message>) {
|
fn new(flags: Self::Flags) -> (Self, Command<A::Message>) {
|
||||||
let (app, command) = A::new(flags);
|
let (app, command) = A::new(flags);
|
||||||
|
|
@ -174,6 +160,14 @@ where
|
||||||
self.0.title()
|
self.0.title()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
|
||||||
|
self.0.update(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> Element<'_, Self::Message, Self::Renderer> {
|
||||||
|
self.0.view()
|
||||||
|
}
|
||||||
|
|
||||||
fn theme(&self) -> A::Theme {
|
fn theme(&self) -> A::Theme {
|
||||||
self.0.theme()
|
self.0.theme()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,14 @@ use crate::mouse;
|
||||||
use crate::renderer;
|
use crate::renderer;
|
||||||
use crate::widget::operation;
|
use crate::widget::operation;
|
||||||
use crate::{
|
use crate::{
|
||||||
Command, Debug, Error, Executor, Proxy, Runtime, Settings, Size,
|
Command, Debug, Element, Error, Executor, Proxy, Renderer, Runtime,
|
||||||
Subscription,
|
Settings, Size, Subscription,
|
||||||
};
|
};
|
||||||
|
|
||||||
use iced_futures::futures;
|
use iced_futures::futures;
|
||||||
use iced_futures::futures::channel::mpsc;
|
use iced_futures::futures::channel::mpsc;
|
||||||
use iced_graphics::compositor;
|
use iced_graphics::compositor;
|
||||||
use iced_graphics::window;
|
use iced_graphics::window;
|
||||||
use iced_native::program::Program;
|
|
||||||
use iced_native::user_interface::{self, UserInterface};
|
use iced_native::user_interface::{self, UserInterface};
|
||||||
|
|
||||||
pub use iced_native::application::{Appearance, StyleSheet};
|
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
|
/// When using an [`Application`] with the `debug` feature enabled, a debug view
|
||||||
/// can be toggled by pressing `F12`.
|
/// can be toggled by pressing `F12`.
|
||||||
pub trait Application: Program
|
pub trait Application: Sized
|
||||||
where
|
where
|
||||||
<Self::Renderer as crate::Renderer>::Theme: StyleSheet,
|
<Self::Renderer as crate::Renderer>::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
/// The data needed to initialize your [`Application`].
|
/// The data needed to initialize your [`Application`].
|
||||||
type Flags;
|
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
|
/// Initializes the [`Application`] with the flags provided to
|
||||||
/// [`run`] as part of the [`Settings`].
|
/// [`run`] as part of the [`Settings`].
|
||||||
///
|
///
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue