From 529589d7fe9278858e3f251b559a1118598a8250 Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 1 Apr 2022 17:16:15 -0300 Subject: Introduce `multi_window` from `pure` --- src/multi_window/application.rs | 196 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 src/multi_window/application.rs (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs new file mode 100644 index 00000000..db41d54a --- /dev/null +++ b/src/multi_window/application.rs @@ -0,0 +1,196 @@ +use crate::{Command, Element, Executor, Settings, Subscription}; + +pub use iced_native::application::{Appearance, StyleSheet}; + +/// A pure version of [`Application`]. +/// +/// Unlike the impure version, the `view` method of this trait takes an +/// immutable reference to `self` and returns a pure [`Element`]. +/// +/// [`Application`]: crate::Application +/// [`Element`]: pure::Element +pub trait Application: Sized { + /// The [`Executor`] that will run commands and subscriptions. + /// + /// The [default executor] can be a good starting point! + /// + /// [`Executor`]: Self::Executor + /// [default executor]: crate::executor::Default + type Executor: Executor; + + /// The type of __messages__ your [`Application`] will produce. + type Message: std::fmt::Debug + Send; + + /// The theme of your [`Application`]. + type Theme: Default + StyleSheet; + + /// The data needed to initialize your [`Application`]. + type Flags; + + /// Initializes the [`Application`] with the flags provided to + /// [`run`] as part of the [`Settings`]. + /// + /// Here is where you should return the initial state of your app. + /// + /// Additionally, you can return a [`Command`] if you need to perform some + /// async action in the background on startup. This is useful if you want to + /// load state from a file, perform an initial HTTP request, etc. + /// + /// [`run`]: Self::run + fn new(flags: Self::Flags) -> (Self, Command); + + /// Returns the current title of the [`Application`]. + /// + /// This title can be dynamic! The runtime will automatically update the + /// title of your application when necessary. + fn title(&self) -> String; + + /// Handles a __message__ and updates the state of the [`Application`]. + /// + /// 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. + fn update(&mut self, message: Self::Message) -> Command; + + /// Returns the current [`Theme`] of the [`Application`]. + /// + /// [`Theme`]: Self::Theme + fn theme(&self) -> Self::Theme { + Self::Theme::default() + } + + /// Returns the current [`Style`] of the [`Theme`]. + /// + /// [`Style`]: ::Style + /// [`Theme`]: Self::Theme + fn style(&self) -> ::Style { + ::Style::default() + } + + /// Returns the event [`Subscription`] for the current state of the + /// application. + /// + /// A [`Subscription`] will be kept alive as long as you keep returning it, + /// and the __messages__ produced will be handled by + /// [`update`](#tymethod.update). + /// + /// By default, this method returns an empty [`Subscription`]. + fn subscription(&self) -> Subscription { + Subscription::none() + } + + /// Returns the widgets to display in the [`Application`]. + /// + /// These widgets can produce __messages__ based on user interaction. + fn view(&self) -> Element<'_, Self::Message, crate::Renderer>; + + /// Returns the scale factor of the [`Application`]. + /// + /// It can be used to dynamically control the size of the UI at runtime + /// (i.e. zooming). + /// + /// For instance, a scale factor of `2.0` will make widgets twice as big, + /// while a scale factor of `0.5` will shrink them to half their size. + /// + /// By default, it returns `1.0`. + fn scale_factor(&self) -> f64 { + 1.0 + } + + /// Returns whether the [`Application`] should be terminated. + /// + /// By default, it returns `false`. + fn should_exit(&self) -> bool { + false + } + + /// Runs the [`Application`]. + /// + /// On native platforms, this method will take control of the current thread + /// until the [`Application`] exits. + /// + /// On the web platform, this method __will NOT return__ unless there is an + /// [`Error`] during startup. + /// + /// [`Error`]: crate::Error + fn run(settings: Settings) -> crate::Result + where + Self: 'static, + { + #[allow(clippy::needless_update)] + let renderer_settings = crate::renderer::Settings { + default_font: settings.default_font, + default_text_size: settings.default_text_size, + text_multithreading: settings.text_multithreading, + antialiasing: if settings.antialiasing { + Some(crate::renderer::settings::Antialiasing::MSAAx4) + } else { + None + }, + ..crate::renderer::Settings::from_env() + }; + + Ok(crate::runtime::application::run::< + Instance, + Self::Executor, + crate::renderer::window::Compositor, + >(settings.into(), renderer_settings)?) + } +} + +struct Instance(A); + +impl iced_winit::Program for Instance +where + A: Application, +{ + type Renderer = crate::Renderer; + type Message = A::Message; + + fn update(&mut self, message: Self::Message) -> Command { + self.0.update(message) + } + + fn view(&self) -> Element<'_, Self::Message, Self::Renderer> { + self.0.view() + } +} + +impl crate::runtime::Application for Instance +where + A: Application, +{ + type Flags = A::Flags; + + fn new(flags: Self::Flags) -> (Self, Command) { + let (app, command) = A::new(flags); + + (Instance(app), command) + } + + fn title(&self) -> String { + self.0.title() + } + + fn theme(&self) -> A::Theme { + self.0.theme() + } + + fn style(&self) -> ::Style { + self.0.style() + } + + fn subscription(&self) -> Subscription { + self.0.subscription() + } + + fn scale_factor(&self) -> f64 { + self.0.scale_factor() + } + + fn should_exit(&self) -> bool { + self.0.should_exit() + } +} -- cgit From b896e41c6e03f1447419194ce41d15fb0db39d96 Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 1 Apr 2022 17:39:08 -0300 Subject: Unify `Application` and `Program` Instead of creating a separate `multi_window::Program`, the new `multi_window::Application` unifies both traits --- src/multi_window/application.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index db41d54a..fa0c15b1 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -132,7 +132,7 @@ pub trait Application: Sized { ..crate::renderer::Settings::from_env() }; - Ok(crate::runtime::application::run::< + Ok(crate::runtime::multi_window::run::< Instance, Self::Executor, crate::renderer::window::Compositor, @@ -142,28 +142,14 @@ pub trait Application: Sized { struct Instance(A); -impl iced_winit::Program for Instance +impl crate::runtime::multi_window::Application for Instance where A: Application, { + type Flags = A::Flags; type Renderer = crate::Renderer; type Message = A::Message; - fn update(&mut self, message: Self::Message) -> Command { - self.0.update(message) - } - - fn view(&self) -> Element<'_, Self::Message, Self::Renderer> { - self.0.view() - } -} - -impl crate::runtime::Application for Instance -where - A: Application, -{ - type Flags = A::Flags; - fn new(flags: Self::Flags) -> (Self, Command) { let (app, command) = A::new(flags); @@ -174,6 +160,14 @@ where self.0.title() } + fn update(&mut self, message: Self::Message) -> Command { + self.0.update(message) + } + + fn view(&self) -> Element<'_, Self::Message, Self::Renderer> { + self.0.view() + } + fn theme(&self) -> A::Theme { self.0.theme() } -- cgit From ec56c0686df1a200e37af951a3a8eca562c32a5c Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 21 Jun 2022 15:59:45 -0300 Subject: Introduce opaque `window::Id` type --- src/multi_window/application.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index fa0c15b1..6b3f4676 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -1,3 +1,4 @@ +use crate::window; use crate::{Command, Element, Executor, Settings, Subscription}; pub use iced_native::application::{Appearance, StyleSheet}; @@ -45,6 +46,9 @@ pub trait Application: Sized { /// title of your application when necessary. fn title(&self) -> String; + /// TODO(derezzedex) + fn windows(&self) -> Vec<(window::Id, window::Settings)>; + /// Handles a __message__ and updates the state of the [`Application`]. /// /// This is where you define your __update logic__. All the __messages__, @@ -160,6 +164,16 @@ where self.0.title() } + fn windows(&self) -> Vec<(window::Id, iced_winit::settings::Window)> { + self.0 + .windows() + .into_iter() + .map(|(id, settings)| { + (id, iced_winit::settings::Window::from(settings)) + }) + .collect() + } + fn update(&mut self, message: Self::Message) -> Command { self.0.update(message) } -- cgit From 2fe58e12619186eb3755491db2bdaf02de297afb Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 21 Jul 2022 09:52:32 -0300 Subject: add `window::Id` to `view` --- src/multi_window/application.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index 6b3f4676..e849bf2b 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -88,7 +88,10 @@ pub trait Application: Sized { /// Returns the widgets to display in the [`Application`]. /// /// These widgets can produce __messages__ based on user interaction. - fn view(&self) -> Element<'_, Self::Message, crate::Renderer>; + fn view( + &self, + window: window::Id, + ) -> Element<'_, Self::Message, crate::Renderer>; /// Returns the scale factor of the [`Application`]. /// @@ -178,8 +181,11 @@ where self.0.update(message) } - fn view(&self) -> Element<'_, Self::Message, Self::Renderer> { - self.0.view() + fn view( + &self, + window: window::Id, + ) -> Element<'_, Self::Message, Self::Renderer> { + self.0.view(window) } fn theme(&self) -> A::Theme { -- cgit From dc86bd03733969033df7389c3d21e78ecc6291bb Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 27 Jul 2022 15:37:48 -0300 Subject: Introduce `close_requested` for `multi-window` --- src/multi_window/application.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index e849bf2b..df45ca1e 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -113,6 +113,9 @@ pub trait Application: Sized { false } + /// TODO(derezzedex) + fn close_requested(&self, window: window::Id) -> Self::Message; + /// Runs the [`Application`]. /// /// On native platforms, this method will take control of the current thread @@ -207,4 +210,8 @@ where fn should_exit(&self) -> bool { self.0.should_exit() } + + fn close_requested(&self, window: window::Id) -> Self::Message { + self.0.close_requested(window) + } } -- cgit From 5e4e410b18eb744cf70ae1f18b9ef08611f59150 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 3 Nov 2022 14:53:05 -0300 Subject: remove `windows` method (use commands instead) --- src/multi_window/application.rs | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index df45ca1e..7d559397 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -46,9 +46,6 @@ pub trait Application: Sized { /// title of your application when necessary. fn title(&self) -> String; - /// TODO(derezzedex) - fn windows(&self) -> Vec<(window::Id, window::Settings)>; - /// Handles a __message__ and updates the state of the [`Application`]. /// /// This is where you define your __update logic__. All the __messages__, @@ -170,16 +167,6 @@ where self.0.title() } - fn windows(&self) -> Vec<(window::Id, iced_winit::settings::Window)> { - self.0 - .windows() - .into_iter() - .map(|(id, settings)| { - (id, iced_winit::settings::Window::from(settings)) - }) - .collect() - } - fn update(&mut self, message: Self::Message) -> Command { self.0.update(message) } -- cgit From ec41918ec40bddaba81235372f1566da59fd09f2 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Thu, 5 Jan 2023 15:26:28 -0800 Subject: Implemented window title update functionality for multiwindow. --- src/multi_window/application.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index 7d559397..dc1ac5b0 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -44,7 +44,7 @@ pub trait Application: Sized { /// /// This title can be dynamic! The runtime will automatically update the /// title of your application when necessary. - fn title(&self) -> String; + fn title(&self, window: window::Id) -> String; /// Handles a __message__ and updates the state of the [`Application`]. /// @@ -110,7 +110,7 @@ pub trait Application: Sized { false } - /// TODO(derezzedex) + /// Requests that the [`window`] be closed. fn close_requested(&self, window: window::Id) -> Self::Message; /// Runs the [`Application`]. @@ -163,8 +163,8 @@ where (Instance(app), command) } - fn title(&self) -> String { - self.0.title() + fn title(&self, window: window::Id) -> String { + self.0.title(window) } fn update(&mut self, message: Self::Message) -> Command { -- cgit From 3e5d34f25fa07fa99f57b686bbde87d73b8ed548 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Mon, 9 Jan 2023 10:19:12 -0800 Subject: Formatting --- src/multi_window/application.rs | 79 +++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 15 deletions(-) (limited to 'src/multi_window') 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) { +/// (Hello, Command::none()) +/// } +/// +/// fn title(&self, window: window::Id) -> String { +/// String::from("A cool application") +/// } +/// +/// fn update(&mut self, _message: Self::Message) -> Command { +/// Command::none() +/// } +/// +/// fn view(&self, window: window::Id) -> Element { +/// "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; type Message = A::Message; - fn new(flags: Self::Flags) -> (Self, Command) { - 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.0.update(message) } @@ -178,6 +217,16 @@ where self.0.view(window) } + fn new(flags: Self::Flags) -> (Self, Command) { + 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() } -- cgit From 0a643287deece9234b64cc843a9f6ae3e6e4806e Mon Sep 17 00:00:00 2001 From: Bingus Date: Wed, 18 Jan 2023 17:04:11 -0800 Subject: Added window::Id to multi_window application's scale_factor --- src/multi_window/application.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index 3f20382c..3af1d8d5 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -148,7 +148,7 @@ pub trait Application: Sized { /// while a scale factor of `0.5` will shrink them to half their size. /// /// By default, it returns `1.0`. - fn scale_factor(&self) -> f64 { + fn scale_factor(&self, window: window::Id) -> f64 { 1.0 } @@ -239,8 +239,8 @@ where self.0.subscription() } - fn scale_factor(&self) -> f64 { - self.0.scale_factor() + fn scale_factor(&self, window: window::Id) -> f64 { + self.0.scale_factor(window) } fn should_exit(&self) -> bool { -- cgit From 2d427455ce8f9627da7c09eb80f38a615f0ddcb7 Mon Sep 17 00:00:00 2001 From: Bingus Date: Fri, 17 Feb 2023 11:50:52 -0800 Subject: Iced master merge (again) --- src/multi_window/application.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index 3af1d8d5..d0b515ab 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -148,6 +148,7 @@ pub trait Application: Sized { /// while a scale factor of `0.5` will shrink them to half their size. /// /// By default, it returns `1.0`. + #[allow(unused_variables)] fn scale_factor(&self, window: window::Id) -> f64 { 1.0 } -- cgit From 8ba18430800142965549077373e2a45d0a3429a1 Mon Sep 17 00:00:00 2001 From: Bingus Date: Mon, 13 Mar 2023 14:16:45 -0700 Subject: Code cleanup, clearer comments + removed some unnecessary dupe; Removed `Frames` struct return for `window::frames()` since we are just redrawing every window anyways; Interface dropping; --- src/multi_window/application.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index d0b515ab..1fb4bcd4 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -139,7 +139,7 @@ pub trait Application: Sized { window: window::Id, ) -> Element<'_, Self::Message, crate::Renderer>; - /// Returns the scale factor of the [`Application`]. + /// Returns the scale factor of the `window` of the [`Application`]. /// /// It can be used to dynamically control the size of the UI at runtime /// (i.e. zooming). @@ -160,7 +160,8 @@ pub trait Application: Sized { false } - /// Requests that the [`window`] be closed. + /// Returns the `Self::Message` that should be processed when a `window` is requested to + /// be closed. fn close_requested(&self, window: window::Id) -> Self::Message; /// Runs the [`Application`]. -- cgit From 41836dd80d0534608e7aedfbf2319c540a23de1a Mon Sep 17 00:00:00 2001 From: Bingus Date: Wed, 15 Mar 2023 18:20:38 -0700 Subject: Added per-window theme support. --- src/multi_window/application.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index 1fb4bcd4..9974128c 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -107,7 +107,8 @@ pub trait Application: Sized { /// Returns the current [`Theme`] of the [`Application`]. /// /// [`Theme`]: Self::Theme - fn theme(&self) -> Self::Theme { + #[allow(unused_variables)] + fn theme(&self, window: window::Id) -> Self::Theme { Self::Theme::default() } @@ -229,8 +230,8 @@ where self.0.title(window) } - fn theme(&self) -> A::Theme { - self.0.theme() + fn theme(&self, window: window::Id) -> A::Theme { + self.0.theme(window) } fn style(&self) -> ::Style { -- cgit From d53ccc857da4d4cda769904342aeb5a82a64f146 Mon Sep 17 00:00:00 2001 From: Bingus Date: Wed, 12 Jul 2023 19:21:05 -0700 Subject: refactored window storage; new helper window events (Destroyed, Created); clippy + fmt; --- src/multi_window/application.rs | 96 ++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 54 deletions(-) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index 9974128c..0486159e 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -1,30 +1,37 @@ use crate::window; use crate::{Command, Element, Executor, Settings, Subscription}; -pub use iced_native::application::{Appearance, StyleSheet}; +pub use crate::style::application::{Appearance, StyleSheet}; /// An interactive cross-platform multi-window application. /// /// This trait is the main entrypoint of Iced. Once implemented, you can run /// your GUI application by simply calling [`run`](#method.run). /// +/// - On native platforms, it will run in its own windows. +/// - On the web, it will take control of the `` and the `<body>` of the +/// document and display only the contents of the `window::Id::MAIN` window. +/// /// 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`]. +/// [`Command`] in some of its methods. If you do not intend to perform any +/// background work in your program, the [`Sandbox`] trait offers a simplified +/// interface. /// /// When using an [`Application`] with the `debug` feature enabled, a debug view /// can be toggled by pressing `F12`. /// +/// # Examples +/// See the `examples/multi-window` example to see this multi-window `Application` trait in action. +/// /// ## 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::{executor, window}; /// use iced::{Command, Element, Settings, Theme}; +/// use iced::multi_window::{self, Application}; /// /// pub fn main() -> iced::Result { /// Hello::run(Settings::default()) @@ -32,17 +39,17 @@ pub use iced_native::application::{Appearance, StyleSheet}; /// /// struct Hello; /// -/// impl Application for Hello { +/// impl multi_window::Application for Hello { /// type Executor = executor::Default; +/// type Flags = (); /// type Message = (); /// type Theme = Theme; -/// type Flags = (); /// /// fn new(_flags: ()) -> (Hello, Command<Self::Message>) { /// (Hello, Command::none()) /// } /// -/// fn title(&self, window: window::Id) -> String { +/// fn title(&self, _window: window::Id) -> String { /// String::from("A cool application") /// } /// @@ -50,13 +57,9 @@ pub use iced_native::application::{Appearance, StyleSheet}; /// Command::none() /// } /// -/// fn view(&self, window: window::Id) -> Element<Self::Message> { +/// 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 { @@ -89,10 +92,10 @@ pub trait Application: Sized { /// [`run`]: Self::run fn new(flags: Self::Flags) -> (Self, Command<Self::Message>); - /// Returns the current title of the [`Application`]. + /// Returns the current title of the `window` of the [`Application`]. /// /// This title can be dynamic! The runtime will automatically update the - /// title of your application when necessary. + /// title of your window when necessary. fn title(&self, window: window::Id) -> String; /// Handles a __message__ and updates the state of the [`Application`]. @@ -104,7 +107,15 @@ pub trait Application: Sized { /// Any [`Command`] returned will be executed immediately in the background. fn update(&mut self, message: Self::Message) -> Command<Self::Message>; - /// Returns the current [`Theme`] of the [`Application`]. + /// Returns the widgets to display in the `window` of the [`Application`]. + /// + /// These widgets can produce __messages__ based on user interaction. + fn view( + &self, + window: window::Id, + ) -> Element<'_, Self::Message, crate::Renderer<Self::Theme>>; + + /// Returns the current [`Theme`] of the `window` of the [`Application`]. /// /// [`Theme`]: Self::Theme #[allow(unused_variables)] @@ -112,9 +123,8 @@ pub trait Application: Sized { Self::Theme::default() } - /// Returns the current [`Style`] of the [`Theme`]. + /// Returns the current `Style` of the [`Theme`]. /// - /// [`Style`]: <Self::Theme as StyleSheet>::Style /// [`Theme`]: Self::Theme fn style(&self) -> <Self::Theme as StyleSheet>::Style { <Self::Theme as StyleSheet>::Style::default() @@ -132,14 +142,6 @@ pub trait Application: Sized { Subscription::none() } - /// Returns the widgets to display in the [`Application`]. - /// - /// These widgets can produce __messages__ based on user interaction. - fn view( - &self, - window: window::Id, - ) -> Element<'_, Self::Message, crate::Renderer<Self::Theme>>; - /// Returns the scale factor of the `window` of the [`Application`]. /// /// It can be used to dynamically control the size of the UI at runtime @@ -154,18 +156,7 @@ pub trait Application: Sized { 1.0 } - /// Returns whether the [`Application`] should be terminated. - /// - /// By default, it returns `false`. - fn should_exit(&self) -> bool { - false - } - - /// Returns the `Self::Message` that should be processed when a `window` is requested to - /// be closed. - fn close_requested(&self, window: window::Id) -> Self::Message; - - /// Runs the [`Application`]. + /// Runs the multi-window [`Application`]. /// /// On native platforms, this method will take control of the current thread /// until the [`Application`] exits. @@ -182,30 +173,28 @@ pub trait Application: Sized { let renderer_settings = crate::renderer::Settings { default_font: settings.default_font, default_text_size: settings.default_text_size, - text_multithreading: settings.text_multithreading, antialiasing: if settings.antialiasing { - Some(crate::renderer::settings::Antialiasing::MSAAx4) + Some(crate::graphics::Antialiasing::MSAAx4) } else { None }, - ..crate::renderer::Settings::from_env() + ..crate::renderer::Settings::default() }; - Ok(crate::runtime::multi_window::run::< + Ok(crate::shell::multi_window::run::< Instance<Self>, Self::Executor, - crate::renderer::window::Compositor<Self::Theme>, + crate::renderer::Compositor<Self::Theme>, >(settings.into(), renderer_settings)?) } } struct Instance<A: Application>(A); -impl<A> crate::runtime::multi_window::Application for Instance<A> +impl<A> crate::runtime::multi_window::Program for Instance<A> where A: Application, { - type Flags = A::Flags; type Renderer = crate::Renderer<A::Theme>; type Message = A::Message; @@ -219,6 +208,13 @@ where ) -> Element<'_, Self::Message, Self::Renderer> { self.0.view(window) } +} + +impl<A> crate::shell::multi_window::Application for Instance<A> +where + A: Application, +{ + type Flags = A::Flags; fn new(flags: Self::Flags) -> (Self, Command<A::Message>) { let (app, command) = A::new(flags); @@ -245,12 +241,4 @@ where fn scale_factor(&self, window: window::Id) -> f64 { self.0.scale_factor(window) } - - fn should_exit(&self) -> bool { - self.0.should_exit() - } - - fn close_requested(&self, window: window::Id) -> Self::Message { - self.0.close_requested(window) - } } -- cgit From 6740c2c5d6b24399dab1343abdfec5daf4b03c98 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez <hector@hecrj.dev> Date: Wed, 29 Nov 2023 22:46:47 +0100 Subject: Fix broken intra-doc links --- src/multi_window/application.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index 0486159e..b6f15149 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -62,6 +62,8 @@ pub use crate::style::application::{Appearance, StyleSheet}; /// } /// } /// ``` +/// +/// [`Sandbox`]: crate::Sandbox pub trait Application: Sized { /// The [`Executor`] that will run commands and subscriptions. /// -- cgit From 3b39ba7029832cab5235fb5538b46148d599daa7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez <hector@hecrj.dev> Date: Wed, 29 Nov 2023 22:52:46 +0100 Subject: Fix unused import in `multi_window::application` --- src/multi_window/application.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/multi_window') diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs index b6f15149..4a91bdf4 100644 --- a/src/multi_window/application.rs +++ b/src/multi_window/application.rs @@ -1,8 +1,7 @@ +use crate::style::application::StyleSheet; use crate::window; use crate::{Command, Element, Executor, Settings, Subscription}; -pub use crate::style::application::{Appearance, StyleSheet}; - /// An interactive cross-platform multi-window application. /// /// This trait is the main entrypoint of Iced. Once implemented, you can run -- cgit