summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--examples/multi_window/src/main.rs10
-rw-r--r--glutin/src/multi_window/state.rs8
-rw-r--r--src/multi_window/application.rs79
-rw-r--r--winit/src/multi_window/state.rs9
4 files changed, 81 insertions, 25 deletions
diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs
index b9f0514c..18536bdf 100644
--- a/examples/multi_window/src/main.rs
+++ b/examples/multi_window/src/main.rs
@@ -57,9 +57,9 @@ enum WindowMessage {
}
impl Application for Example {
+ type Executor = executor::Default;
type Message = Message;
type Theme = Theme;
- type Executor = executor::Default;
type Flags = ();
fn new(_flags: ()) -> (Self, Command<Message>) {
@@ -251,10 +251,6 @@ impl Application for Example {
})
}
- fn close_requested(&self, window: window::Id) -> Self::Message {
- Message::Window(window, WindowMessage::CloseWindow)
- }
-
fn view(&self, window_id: window::Id) -> Element<Message> {
if let Some(window) = self.windows.get(&window_id) {
let focus = window.focus;
@@ -342,6 +338,10 @@ impl Application for Example {
.center_y()
.into()
}
+
+ fn close_requested(&self, window: window::Id) -> Self::Message {
+ Message::Window(window, WindowMessage::CloseWindow)
+ }
}
const PANE_ID_COLOR_UNFOCUSED: Color = Color::from_rgb(
diff --git a/glutin/src/multi_window/state.rs b/glutin/src/multi_window/state.rs
index 04ec5083..8ed134b2 100644
--- a/glutin/src/multi_window/state.rs
+++ b/glutin/src/multi_window/state.rs
@@ -31,8 +31,12 @@ impl<A: Application> State<A>
where
<A::Renderer as crate::Renderer>::Theme: application::StyleSheet,
{
- /// Creates a new [`State`] for the provided [`Application`] and window.
- pub fn new(application: &A, window_id: window::Id, window: &Window) -> Self {
+ /// Creates a new [`State`] for the provided [`Application`]'s window.
+ pub fn new(
+ application: &A,
+ window_id: window::Id,
+ window: &Window,
+ ) -> Self {
let title = application.title(window_id);
let scale_factor = application.scale_factor();
let theme = application.theme();
diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs
index dc1ac5b0..3f20382c 100644
--- a/src/multi_window/application.rs
+++ b/src/multi_window/application.rs
@@ -3,13 +3,62 @@ use crate::{Command, Element, Executor, Settings, Subscription};
pub use iced_native::application::{Appearance, StyleSheet};
-/// A pure version of [`Application`].
+/// An interactive cross-platform multi-window application.
///
-/// Unlike the impure version, the `view` method of this trait takes an
-/// immutable reference to `self` and returns a pure [`Element`].
+/// This trait is the main entrypoint of Iced. Once implemented, you can run
+/// your GUI application by simply calling [`run`](#method.run).
///
-/// [`Application`]: crate::Application
-/// [`Element`]: pure::Element
+/// An [`Application`] can execute asynchronous actions by returning a
+/// [`Command`] in some of its methods. For example, to spawn a new window, you
+/// can use the `iced_winit::window::spawn()` [`Command`].
+///
+/// When using an [`Application`] with the `debug` feature enabled, a debug view
+/// can be toggled by pressing `F12`.
+///
+/// ## A simple "Hello, world!"
+///
+/// If you just want to get started, here is a simple [`Application`] that
+/// says "Hello, world!":
+///
+/// ```no_run
+/// use iced::executor;
+/// use iced::multi_window::Application;
+/// use iced::window;
+/// use iced::{Command, Element, Settings, Theme};
+///
+/// pub fn main() -> iced::Result {
+/// Hello::run(Settings::default())
+/// }
+///
+/// struct Hello;
+///
+/// impl Application for Hello {
+/// type Executor = executor::Default;
+/// type Message = ();
+/// type Theme = Theme;
+/// type Flags = ();
+///
+/// fn new(_flags: ()) -> (Hello, Command<Self::Message>) {
+/// (Hello, Command::none())
+/// }
+///
+/// fn title(&self, window: window::Id) -> String {
+/// String::from("A cool application")
+/// }
+///
+/// fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
+/// Command::none()
+/// }
+///
+/// fn view(&self, window: window::Id) -> Element<Self::Message> {
+/// "Hello, world!".into()
+/// }
+///
+/// fn close_requested(&self, window: window::Id) -> Self::Message {
+/// ()
+/// }
+/// }
+/// ```
pub trait Application: Sized {
/// The [`Executor`] that will run commands and subscriptions.
///
@@ -157,16 +206,6 @@ where
type Renderer = crate::Renderer<A::Theme>;
type Message = A::Message;
- fn new(flags: Self::Flags) -> (Self, Command<A::Message>) {
- let (app, command) = A::new(flags);
-
- (Instance(app), command)
- }
-
- fn title(&self, window: window::Id) -> String {
- self.0.title(window)
- }
-
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
self.0.update(message)
}
@@ -178,6 +217,16 @@ where
self.0.view(window)
}
+ fn new(flags: Self::Flags) -> (Self, Command<A::Message>) {
+ let (app, command) = A::new(flags);
+
+ (Instance(app), command)
+ }
+
+ fn title(&self, window: window::Id) -> String {
+ self.0.title(window)
+ }
+
fn theme(&self) -> A::Theme {
self.0.theme()
}
diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs
index 7a598b98..2c2a4693 100644
--- a/winit/src/multi_window/state.rs
+++ b/winit/src/multi_window/state.rs
@@ -29,8 +29,12 @@ impl<A: Application> State<A>
where
<A::Renderer as crate::Renderer>::Theme: application::StyleSheet,
{
- /// Creates a new [`State`] for the provided [`Application`] and window.
- pub fn new(application: &A, window_id: window::Id, window: &Window) -> Self {
+ /// Creates a new [`State`] for the provided [`Application`]'s window.
+ pub fn new(
+ application: &A,
+ window_id: window::Id,
+ window: &Window,
+ ) -> Self {
let title = application.title(window_id);
let scale_factor = application.scale_factor();
let theme = application.theme();
@@ -191,7 +195,6 @@ where
if self.title != new_title {
window.set_title(&new_title);
-
self.title = new_title;
}