From 42c423b4a89613c4e1c552c891c1391a34837122 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Sat, 15 Jul 2023 10:04:25 -0700 Subject: Add viewport to Widget::on_event --- runtime/src/user_interface.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'runtime/src') diff --git a/runtime/src/user_interface.rs b/runtime/src/user_interface.rs index 619423fd..e31ea98f 100644 --- a/runtime/src/user_interface.rs +++ b/runtime/src/user_interface.rs @@ -284,6 +284,8 @@ where (cursor, vec![event::Status::Ignored; events.len()]) }; + let viewport = Rectangle::with_size(self.bounds); + let _ = ManuallyDrop::into_inner(manual_overlay); let event_statuses = events @@ -305,6 +307,7 @@ where renderer, clipboard, &mut shell, + &viewport, ); if matches!(event_status, event::Status::Captured) { -- cgit From 2a05ef9601bca560e68f9a16ff1875cfed33e0ea Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Mon, 24 Jul 2023 09:26:24 -0700 Subject: Don't clip raw overlay bounds User interface wraps the overlay in `overlay::Nested`. Clipping here w/ the base Nested overlay always clipped at (0, 0) position instead of the correct position of the child overlay. It's clipped properly already within `Nested::draw`. --- runtime/src/user_interface.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/user_interface.rs b/runtime/src/user_interface.rs index e31ea98f..8a936b98 100644 --- a/runtime/src/user_interface.rs +++ b/runtime/src/user_interface.rs @@ -513,17 +513,13 @@ where renderer, ); - let overlay_bounds = layout.bounds(); - - renderer.with_layer(overlay_bounds, |renderer| { - overlay.draw( - renderer, - theme, - style, - Layout::new(layout), - cursor, - ); - }); + overlay.draw( + renderer, + theme, + style, + Layout::new(layout), + cursor, + ); if cursor .position() -- cgit From 126aef88e7647c4690055b4c96aee46ecadcf60e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 28 Jul 2023 19:48:39 +0200 Subject: Bump versions :tada: --- runtime/src/lib.rs | 4 ++-- runtime/src/user_interface.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 4bbf9687..59c70ff7 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -23,8 +23,8 @@ //! - Build a new renderer, see the [renderer] module. //! - Build a custom widget, start at the [`Widget`] trait. //! -//! [`iced_core`]: https://github.com/iced-rs/iced/tree/0.9/core -//! [`iced_winit`]: https://github.com/iced-rs/iced/tree/0.9/winit +//! [`iced_core`]: https://github.com/iced-rs/iced/tree/0.10/core +//! [`iced_winit`]: https://github.com/iced-rs/iced/tree/0.10/winit //! [`druid`]: https://github.com/xi-editor/druid //! [`raw-window-handle`]: https://github.com/rust-windowing/raw-window-handle //! [renderer]: crate::renderer diff --git a/runtime/src/user_interface.rs b/runtime/src/user_interface.rs index 8a936b98..5e910eab 100644 --- a/runtime/src/user_interface.rs +++ b/runtime/src/user_interface.rs @@ -19,7 +19,7 @@ use crate::overlay; /// The [`integration`] example uses a [`UserInterface`] to integrate Iced in an /// existing graphical application. /// -/// [`integration`]: https://github.com/iced-rs/iced/tree/0.9/examples/integration +/// [`integration`]: https://github.com/iced-rs/iced/tree/0.10/examples/integration #[allow(missing_debug_implementations)] pub struct UserInterface<'a, Message, Renderer> { root: Element<'a, Message, Renderer>, -- cgit From 8ed06dc356e0296f0b800d4d6b92998bd4444cc6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 26 Aug 2023 01:34:42 +0200 Subject: Fix `clippy` lints for Rust 1.72 --- runtime/src/user_interface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/src') diff --git a/runtime/src/user_interface.rs b/runtime/src/user_interface.rs index 5e910eab..e529c004 100644 --- a/runtime/src/user_interface.rs +++ b/runtime/src/user_interface.rs @@ -291,7 +291,7 @@ where let event_statuses = events .iter() .cloned() - .zip(overlay_statuses.into_iter()) + .zip(overlay_statuses) .map(|(event, overlay_status)| { if matches!(overlay_status, event::Status::Captured) { return overlay_status; -- cgit From ed3454301e663a7cb7d73cd56b57b188f4d14a2f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 30 Aug 2023 04:31:21 +0200 Subject: Implement explicit text caching in the widget state tree --- runtime/src/user_interface.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/user_interface.rs b/runtime/src/user_interface.rs index e529c004..a730102c 100644 --- a/runtime/src/user_interface.rs +++ b/runtime/src/user_interface.rs @@ -95,8 +95,11 @@ where let Cache { mut state } = cache; state.diff(root.as_widget()); - let base = - renderer.layout(&root, &layout::Limits::new(Size::ZERO, bounds)); + let base = root.as_widget().layout( + &state, + renderer, + &layout::Limits::new(Size::ZERO, bounds), + ); UserInterface { root, @@ -226,8 +229,9 @@ where if shell.is_layout_invalid() { let _ = ManuallyDrop::into_inner(manual_overlay); - self.base = renderer.layout( - &self.root, + self.base = self.root.as_widget().layout( + &self.state, + renderer, &layout::Limits::new(Size::ZERO, self.bounds), ); @@ -325,8 +329,9 @@ where } shell.revalidate_layout(|| { - self.base = renderer.layout( - &self.root, + self.base = self.root.as_widget().layout( + &self.state, + renderer, &layout::Limits::new(Size::ZERO, self.bounds), ); -- cgit From a026e917d3364e58fd827995261158d8cb356ce9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 30 Aug 2023 06:36:24 +0200 Subject: Make `widget::Tree` mutable in `Widget::layout` --- runtime/src/user_interface.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/user_interface.rs b/runtime/src/user_interface.rs index a730102c..b684fbde 100644 --- a/runtime/src/user_interface.rs +++ b/runtime/src/user_interface.rs @@ -96,7 +96,7 @@ where state.diff(root.as_widget()); let base = root.as_widget().layout( - &state, + &mut state, renderer, &layout::Limits::new(Size::ZERO, bounds), ); @@ -230,7 +230,7 @@ where let _ = ManuallyDrop::into_inner(manual_overlay); self.base = self.root.as_widget().layout( - &self.state, + &mut self.state, renderer, &layout::Limits::new(Size::ZERO, self.bounds), ); @@ -330,7 +330,7 @@ where shell.revalidate_layout(|| { self.base = self.root.as_widget().layout( - &self.state, + &mut self.state, renderer, &layout::Limits::new(Size::ZERO, self.bounds), ); -- cgit From 08a031cbe5913c249efa7fc82556d5d95f981c4c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 7 Sep 2023 02:45:15 +0200 Subject: Introduce `keyboard::on_key_press` and `on_key_release` Also rename `subscription::events*` to `event::listen*`. --- runtime/src/window.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 5219fbfd..41816967 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -10,7 +10,8 @@ use crate::command::{self, Command}; use crate::core::time::Instant; use crate::core::window::{Event, Icon, Level, Mode, UserAttention}; use crate::core::Size; -use crate::futures::subscription::{self, Subscription}; +use crate::futures::event; +use crate::futures::Subscription; /// Subscribes to the frames of the window of the running application. /// @@ -21,7 +22,7 @@ use crate::futures::subscription::{self, Subscription}; /// In any case, this [`Subscription`] is useful to smoothly draw application-driven /// animations without missing any frames. pub fn frames() -> Subscription { - subscription::raw_events(|event, _status| match event { + event::listen_raw(|event, _status| match event { iced_core::Event::Window(Event::RedrawRequested(at)) => Some(at), _ => None, }) -- cgit From 89d9f1d7d2202029028a487df1dd11b0665a7517 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Sat, 9 Sep 2023 12:24:47 +0200 Subject: Fix majority of unresolved documentation links --- runtime/src/lib.rs | 25 +------------------------ runtime/src/overlay/nested.rs | 4 +++- runtime/src/program/state.rs | 2 +- runtime/src/user_interface.rs | 4 ++-- 4 files changed, 7 insertions(+), 28 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 59c70ff7..dc631d47 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -2,32 +2,9 @@ //! //! ![The native path of the Iced ecosystem](https://github.com/iced-rs/iced/raw/improvement/update-ecosystem-and-roadmap/docs/graphs/native.png) //! -//! `iced_native` takes [`iced_core`] and builds a native runtime on top of it, -//! featuring: -//! -//! - A custom layout engine, greatly inspired by [`druid`] -//! - Event handling for all the built-in widgets -//! - A renderer-agnostic API -//! -//! To achieve this, it introduces a couple of reusable interfaces: -//! -//! - A [`Widget`] trait, which is used to implement new widgets: from layout -//! requirements to event and drawing logic. -//! - A bunch of `Renderer` traits, meant to keep the crate renderer-agnostic. -//! -//! # Usage -//! The strategy to use this crate depends on your particular use case. If you -//! want to: -//! - Implement a custom shell or integrate it in your own system, check out the -//! [`UserInterface`] type. -//! - Build a new renderer, see the [renderer] module. -//! - Build a custom widget, start at the [`Widget`] trait. +//! `iced_runtime` takes [`iced_core`] and builds a native runtime on top of it. //! //! [`iced_core`]: https://github.com/iced-rs/iced/tree/0.10/core -//! [`iced_winit`]: https://github.com/iced-rs/iced/tree/0.10/winit -//! [`druid`]: https://github.com/xi-editor/druid -//! [`raw-window-handle`]: https://github.com/rust-windowing/raw-window-handle -//! [renderer]: crate::renderer #![doc( html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" )] diff --git a/runtime/src/overlay/nested.rs b/runtime/src/overlay/nested.rs index b729f769..21b6f7c1 100644 --- a/runtime/src/overlay/nested.rs +++ b/runtime/src/overlay/nested.rs @@ -6,7 +6,7 @@ use crate::core::renderer; use crate::core::widget; use crate::core::{Clipboard, Event, Layout, Point, Rectangle, Shell, Size}; -/// An [`Overlay`] container that displays nested overlays +/// An overlay container that displays nested overlays #[allow(missing_debug_implementations)] pub struct Nested<'a, Message, Renderer> { overlay: overlay::Element<'a, Message, Renderer>, @@ -27,6 +27,8 @@ where } /// Returns the layout [`Node`] of the [`Nested`] overlay. + /// + /// [`Node`]: layout::Node pub fn layout( &mut self, renderer: &Renderer, diff --git a/runtime/src/program/state.rs b/runtime/src/program/state.rs index 35df6078..9aa2d550 100644 --- a/runtime/src/program/state.rs +++ b/runtime/src/program/state.rs @@ -175,7 +175,7 @@ where (uncaptured_events, command) } - /// Applies [`widget::Operation`]s to the [`State`] + /// Applies [`Operation`]s to the [`State`] pub fn operate( &mut self, renderer: &mut P::Renderer, diff --git a/runtime/src/user_interface.rs b/runtime/src/user_interface.rs index e529c004..165a85ae 100644 --- a/runtime/src/user_interface.rs +++ b/runtime/src/user_interface.rs @@ -356,7 +356,7 @@ where /// It returns the current [`mouse::Interaction`]. You should update the /// icon of the mouse cursor accordingly in your system. /// - /// [`Renderer`]: crate::Renderer + /// [`Renderer`]: crate::core::Renderer /// /// # Example /// We can finally draw our [counter](index.html#usage) by @@ -619,7 +619,7 @@ pub enum State { /// The [`UserInterface`] is up-to-date and can be reused without /// rebuilding. Updated { - /// The [`Instant`] when a redraw should be performed. + /// The [`window::RedrawRequest`] when a redraw should be performed. redraw_request: Option, }, } -- cgit From f60884f6f8639f75258c264bf4a15591351ef05b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 9 Sep 2023 20:58:45 +0200 Subject: Deny `broken_intradoc_links` and verify documentation in CI --- runtime/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index dc631d47..c3261cca 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -8,6 +8,7 @@ #![doc( html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" )] +#![forbid(unsafe_code, rust_2018_idioms)] #![deny( missing_debug_implementations, missing_docs, @@ -16,9 +17,9 @@ clippy::from_over_into, clippy::needless_borrow, clippy::new_without_default, - clippy::useless_conversion + clippy::useless_conversion, + rustdoc::broken_intra_doc_links )] -#![forbid(unsafe_code, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] pub mod clipboard; pub mod command; -- cgit From c6554d990770b941b5003d6ef40af3f9dedcd052 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 19 Sep 2023 01:50:05 -0400 Subject: Chore: Apply clippy docs keyword quoting Add quotes a number of doc strings like `sRGB` --- runtime/src/window/screenshot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/src') diff --git a/runtime/src/window/screenshot.rs b/runtime/src/window/screenshot.rs index c84286b6..21e04718 100644 --- a/runtime/src/window/screenshot.rs +++ b/runtime/src/window/screenshot.rs @@ -6,7 +6,7 @@ use std::sync::Arc; /// Data of a screenshot, captured with `window::screenshot()`. /// -/// The `bytes` of this screenshot will always be ordered as `RGBA` in the sRGB color space. +/// The `bytes` of this screenshot will always be ordered as `RGBA` in the `sRGB` color space. #[derive(Clone)] pub struct Screenshot { /// The bytes of the [`Screenshot`]. -- cgit From efd0ff6ded4e647e5fad0964555dbed541a075d7 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 19 Sep 2023 01:52:25 -0400 Subject: Chore: Apply some minor clippy fixes * Use `.elapsed()` for duration * Use direct iteration without calling `.iter()` and the like * order fields in the `Text` struct creation as declared --- runtime/src/debug/basic.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/debug/basic.rs b/runtime/src/debug/basic.rs index 32f725a1..4c994a2f 100644 --- a/runtime/src/debug/basic.rs +++ b/runtime/src/debug/basic.rs @@ -75,7 +75,7 @@ impl Debug { } pub fn startup_finished(&mut self) { - self.startup_duration = time::Instant::now() - self.startup_start; + self.startup_duration = self.startup_start.elapsed(); } pub fn update_started(&mut self) { @@ -83,8 +83,7 @@ impl Debug { } pub fn update_finished(&mut self) { - self.update_durations - .push(time::Instant::now() - self.update_start); + self.update_durations.push(self.update_start.elapsed()); } pub fn view_started(&mut self) { @@ -92,8 +91,7 @@ impl Debug { } pub fn view_finished(&mut self) { - self.view_durations - .push(time::Instant::now() - self.view_start); + self.view_durations.push(self.view_start.elapsed()); } pub fn layout_started(&mut self) { @@ -101,8 +99,7 @@ impl Debug { } pub fn layout_finished(&mut self) { - self.layout_durations - .push(time::Instant::now() - self.layout_start); + self.layout_durations.push(self.layout_start.elapsed()); } pub fn event_processing_started(&mut self) { @@ -110,8 +107,7 @@ impl Debug { } pub fn event_processing_finished(&mut self) { - self.event_durations - .push(time::Instant::now() - self.event_start); + self.event_durations.push(self.event_start.elapsed()); } pub fn draw_started(&mut self) { @@ -119,8 +115,7 @@ impl Debug { } pub fn draw_finished(&mut self) { - self.draw_durations - .push(time::Instant::now() - self.draw_start); + self.draw_durations.push(self.draw_start.elapsed()); } pub fn render_started(&mut self) { @@ -128,8 +123,7 @@ impl Debug { } pub fn render_finished(&mut self) { - self.render_durations - .push(time::Instant::now() - self.render_start); + self.render_durations.push(self.render_start.elapsed()); } pub fn log_message(&mut self, message: &Message) { -- cgit From 34f07b60273d6cfe13834af54cd0e24d34569387 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 04:11:52 +0200 Subject: Fix `clippy::semicolon_if_nothing_returned` --- runtime/src/overlay/nested.rs | 2 +- runtime/src/program/state.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/overlay/nested.rs b/runtime/src/overlay/nested.rs index 21b6f7c1..062ccc72 100644 --- a/runtime/src/overlay/nested.rs +++ b/runtime/src/overlay/nested.rs @@ -164,7 +164,7 @@ where } } - recurse(&mut self.overlay, layout, renderer, operation) + recurse(&mut self.overlay, layout, renderer, operation); } /// Processes a runtime [`Event`]. diff --git a/runtime/src/program/state.rs b/runtime/src/program/state.rs index 9aa2d550..6f8f4063 100644 --- a/runtime/src/program/state.rs +++ b/runtime/src/program/state.rs @@ -200,7 +200,7 @@ where match operation.finish() { operation::Outcome::None => {} operation::Outcome::Some(message) => { - self.queued_messages.push(message) + self.queued_messages.push(message); } operation::Outcome::Chain(next) => { current_operation = Some(next); -- cgit From f137d71e8fb926e784680d56d1cfa6817c3710a1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 16:40:03 +0200 Subject: Centralize `clippy` lints in `.cargo/config.toml` --- runtime/src/lib.rs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index c3261cca..29e94d65 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -13,11 +13,6 @@ missing_debug_implementations, missing_docs, unused_results, - clippy::extra_unused_lifetimes, - clippy::from_over_into, - clippy::needless_borrow, - clippy::new_without_default, - clippy::useless_conversion, rustdoc::broken_intra_doc_links )] #![cfg_attr(docsrs, feature(doc_auto_cfg))] -- cgit From e0233ebc3ce4791d094c52eeef81cce78b9bc578 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 3 Aug 2023 10:19:28 -0700 Subject: Fix `Command::perform` to return a `Command` This seems like clearly the correct thing to do here. If the type bound on `Command` isn't specified, it makes no difference, since the generic is inferred in a way that works with either definition. But this is important if `Command` is aliased with a concrete type. --- runtime/src/command.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/command.rs b/runtime/src/command.rs index cd4c51ff..b74097bd 100644 --- a/runtime/src/command.rs +++ b/runtime/src/command.rs @@ -40,9 +40,9 @@ impl Command { /// Creates a [`Command`] that performs the action of the given future. pub fn perform( - future: impl Future + 'static + MaybeSend, - f: impl FnOnce(T) -> A + 'static + MaybeSend, - ) -> Command { + future: impl Future + 'static + MaybeSend, + f: impl FnOnce(A) -> T + 'static + MaybeSend, + ) -> Command { use iced_futures::futures::FutureExt; Command::single(Action::Future(Box::pin(future.map(f)))) -- cgit From 25006b9c6f2ae909d86871d3a13631d518c07158 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 21 Nov 2023 14:41:22 +0100 Subject: Fix `Overlay` composition Translations were not easily composable. --- runtime/src/overlay/nested.rs | 18 +++++++++++++----- runtime/src/user_interface.rs | 30 +++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 12 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/overlay/nested.rs b/runtime/src/overlay/nested.rs index 062ccc72..b7cfc918 100644 --- a/runtime/src/overlay/nested.rs +++ b/runtime/src/overlay/nested.rs @@ -4,7 +4,9 @@ use crate::core::mouse; use crate::core::overlay; use crate::core::renderer; use crate::core::widget; -use crate::core::{Clipboard, Event, Layout, Point, Rectangle, Shell, Size}; +use crate::core::{ + Clipboard, Event, Layout, Point, Rectangle, Shell, Size, Vector, +}; /// An overlay container that displays nested overlays #[allow(missing_debug_implementations)] @@ -34,18 +36,18 @@ where renderer: &Renderer, bounds: Size, position: Point, + translation: Vector, ) -> layout::Node { fn recurse( element: &mut overlay::Element<'_, Message, Renderer>, renderer: &Renderer, bounds: Size, position: Point, + translation: Vector, ) -> layout::Node where Renderer: renderer::Renderer, { - let translation = position - Point::ORIGIN; - let node = element.layout(renderer, bounds, translation); if let Some(mut nested) = @@ -55,7 +57,13 @@ where node.size(), vec![ node, - recurse(&mut nested, renderer, bounds, position), + recurse( + &mut nested, + renderer, + bounds, + position, + translation, + ), ], ) } else { @@ -63,7 +71,7 @@ where } } - recurse(&mut self.overlay, renderer, bounds, position) + recurse(&mut self.overlay, renderer, bounds, position, translation) } /// Draws the [`Nested`] overlay using the associated `Renderer`. diff --git a/runtime/src/user_interface.rs b/runtime/src/user_interface.rs index dae9e0ac..3594ac18 100644 --- a/runtime/src/user_interface.rs +++ b/runtime/src/user_interface.rs @@ -5,7 +5,9 @@ use crate::core::mouse; use crate::core::renderer; use crate::core::widget; use crate::core::window; -use crate::core::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size}; +use crate::core::{ + Clipboard, Element, Layout, Point, Rectangle, Shell, Size, Vector, +}; use crate::overlay; /// A set of interactive graphical elements with a specific [`Layout`]. @@ -199,7 +201,8 @@ where let bounds = self.bounds; let mut overlay = manual_overlay.as_mut().unwrap(); - let mut layout = overlay.layout(renderer, bounds, Point::ORIGIN); + let mut layout = + overlay.layout(renderer, bounds, Point::ORIGIN, Vector::ZERO); let mut event_statuses = Vec::new(); for event in events.iter().cloned() { @@ -253,8 +256,12 @@ where overlay = manual_overlay.as_mut().unwrap(); shell.revalidate_layout(|| { - layout = - overlay.layout(renderer, bounds, Point::ORIGIN); + layout = overlay.layout( + renderer, + bounds, + Point::ORIGIN, + Vector::ZERO, + ); }); } @@ -448,7 +455,12 @@ where .map(overlay::Nested::new) { let overlay_layout = self.overlay.take().unwrap_or_else(|| { - overlay.layout(renderer, self.bounds, Point::ORIGIN) + overlay.layout( + renderer, + self.bounds, + Point::ORIGIN, + Vector::ZERO, + ) }); let cursor = if cursor @@ -566,8 +578,12 @@ where .map(overlay::Nested::new) { if self.overlay.is_none() { - self.overlay = - Some(overlay.layout(renderer, self.bounds, Point::ORIGIN)); + self.overlay = Some(overlay.layout( + renderer, + self.bounds, + Point::ORIGIN, + Vector::ZERO, + )); } overlay.operate( -- cgit From a1439071d691be8096ce956df90d1553fe5b3694 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 21 Nov 2023 18:53:31 +0100 Subject: Remove unused `position` argument in `overlay::Nested` --- runtime/src/overlay/nested.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/overlay/nested.rs b/runtime/src/overlay/nested.rs index b7cfc918..4256efb7 100644 --- a/runtime/src/overlay/nested.rs +++ b/runtime/src/overlay/nested.rs @@ -35,14 +35,13 @@ where &mut self, renderer: &Renderer, bounds: Size, - position: Point, + _position: Point, translation: Vector, ) -> layout::Node { fn recurse( element: &mut overlay::Element<'_, Message, Renderer>, renderer: &Renderer, bounds: Size, - position: Point, translation: Vector, ) -> layout::Node where @@ -57,13 +56,7 @@ where node.size(), vec![ node, - recurse( - &mut nested, - renderer, - bounds, - position, - translation, - ), + recurse(&mut nested, renderer, bounds, translation), ], ) } else { @@ -71,7 +64,7 @@ where } } - recurse(&mut self.overlay, renderer, bounds, position, translation) + recurse(&mut self.overlay, renderer, bounds, translation) } /// Draws the [`Nested`] overlay using the associated `Renderer`. -- cgit From 3b7d479534d9114ed12bb5d9ccd910e85d5c13c7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 29 Nov 2023 00:12:48 +0100 Subject: Implement `Command::run` for executing a `Stream` to completion --- runtime/src/command.rs | 14 +++++++++++++- runtime/src/command/action.rs | 9 ++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/command.rs b/runtime/src/command.rs index b74097bd..b942f3ce 100644 --- a/runtime/src/command.rs +++ b/runtime/src/command.rs @@ -4,8 +4,10 @@ mod action; pub use action::Action; use crate::core::widget; +use crate::futures::futures; use crate::futures::MaybeSend; +use futures::Stream; use std::fmt; use std::future::Future; @@ -43,11 +45,21 @@ impl Command { future: impl Future + 'static + MaybeSend, f: impl FnOnce(A) -> T + 'static + MaybeSend, ) -> Command { - use iced_futures::futures::FutureExt; + use futures::FutureExt; Command::single(Action::Future(Box::pin(future.map(f)))) } + /// Creates a [`Command`] that runs the given stream to completion. + pub fn run( + stream: impl Stream + 'static + MaybeSend, + f: impl Fn(A) -> T + 'static + MaybeSend, + ) -> Command { + use futures::StreamExt; + + Command::single(Action::Stream(Box::pin(stream.map(f)))) + } + /// Creates a [`Command`] that performs the actions of all the given /// commands. /// diff --git a/runtime/src/command/action.rs b/runtime/src/command/action.rs index 6c74f0ef..6551e233 100644 --- a/runtime/src/command/action.rs +++ b/runtime/src/command/action.rs @@ -18,6 +18,11 @@ pub enum Action { /// [`Future`]: iced_futures::BoxFuture Future(iced_futures::BoxFuture), + /// Run a [`Stream`] to completion. + /// + /// [`Stream`]: iced_futures::BoxStream + Stream(iced_futures::BoxStream), + /// Run a clipboard action. Clipboard(clipboard::Action), @@ -52,10 +57,11 @@ impl Action { A: 'static, T: 'static, { - use iced_futures::futures::FutureExt; + use iced_futures::futures::{FutureExt, StreamExt}; match self { Self::Future(future) => Action::Future(Box::pin(future.map(f))), + Self::Stream(stream) => Action::Stream(Box::pin(stream.map(f))), Self::Clipboard(action) => Action::Clipboard(action.map(f)), Self::Window(window) => Action::Window(window.map(f)), Self::System(system) => Action::System(system.map(f)), @@ -74,6 +80,7 @@ impl fmt::Debug for Action { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Future(_) => write!(f, "Action::Future"), + Self::Stream(_) => write!(f, "Action::Stream"), Self::Clipboard(action) => { write!(f, "Action::Clipboard({action:?})") } -- cgit From a761448858521d11dc646e2ef5217e9e06628932 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 29 Nov 2023 00:14:27 +0100 Subject: Implement `command::channel` helper It is analogous to `subscription::channel`. --- runtime/src/command.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'runtime/src') diff --git a/runtime/src/command.rs b/runtime/src/command.rs index b942f3ce..f70da915 100644 --- a/runtime/src/command.rs +++ b/runtime/src/command.rs @@ -7,6 +7,7 @@ use crate::core::widget; use crate::futures::futures; use crate::futures::MaybeSend; +use futures::channel::mpsc; use futures::Stream; use std::fmt; use std::future::Future; @@ -118,3 +119,23 @@ impl fmt::Debug for Command { command.fmt(f) } } + +/// Creates a [`Command`] that produces the `Message`s published from a [`Future`] +/// to an [`mpsc::Sender`] with the given bounds. +pub fn channel( + size: usize, + f: impl FnOnce(mpsc::Sender) -> Fut + MaybeSend + 'static, +) -> Command +where + Fut: Future + MaybeSend + 'static, + Message: 'static + MaybeSend, +{ + use futures::future; + use futures::stream::{self, StreamExt}; + + let (sender, receiver) = mpsc::channel(size); + + let runner = stream::once(f(sender)).filter_map(|_| future::ready(None)); + + Command::single(Action::Stream(Box::pin(stream::select(receiver, runner)))) +} -- cgit