From a25b1af45690bdd8e1cbb20ee3a5b1c4342de455 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 14 Jun 2024 01:47:39 +0200 Subject: Replace `Command` with a new `Task` API with chain support --- core/src/element.rs | 61 +++----------------------------------------- core/src/lib.rs | 2 ++ core/src/maybe.rs | 35 +++++++++++++++++++++++++ core/src/overlay.rs | 2 +- core/src/overlay/element.rs | 60 +++---------------------------------------- core/src/overlay/group.rs | 2 +- core/src/widget.rs | 2 +- core/src/widget/operation.rs | 12 ++++----- 8 files changed, 53 insertions(+), 123 deletions(-) create mode 100644 core/src/maybe.rs (limited to 'core') diff --git a/core/src/element.rs b/core/src/element.rs index 7d918a2e..385d8295 100644 --- a/core/src/element.rs +++ b/core/src/element.rs @@ -10,7 +10,6 @@ use crate::{ Widget, }; -use std::any::Any; use std::borrow::Borrow; /// A generic [`Widget`]. @@ -305,63 +304,9 @@ where tree: &mut Tree, layout: Layout<'_>, renderer: &Renderer, - operation: &mut dyn widget::Operation, + operation: &mut dyn widget::Operation<()>, ) { - struct MapOperation<'a, B> { - operation: &'a mut dyn widget::Operation, - } - - impl<'a, T, B> widget::Operation for MapOperation<'a, B> { - fn container( - &mut self, - id: Option<&widget::Id>, - bounds: Rectangle, - operate_on_children: &mut dyn FnMut( - &mut dyn widget::Operation, - ), - ) { - self.operation.container(id, bounds, &mut |operation| { - operate_on_children(&mut MapOperation { operation }); - }); - } - - fn focusable( - &mut self, - state: &mut dyn widget::operation::Focusable, - id: Option<&widget::Id>, - ) { - self.operation.focusable(state, id); - } - - fn scrollable( - &mut self, - state: &mut dyn widget::operation::Scrollable, - id: Option<&widget::Id>, - bounds: Rectangle, - translation: Vector, - ) { - self.operation.scrollable(state, id, bounds, translation); - } - - fn text_input( - &mut self, - state: &mut dyn widget::operation::TextInput, - id: Option<&widget::Id>, - ) { - self.operation.text_input(state, id); - } - - fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) { - self.operation.custom(state, id); - } - } - - self.widget.operate( - tree, - layout, - renderer, - &mut MapOperation { operation }, - ); + self.widget.operate(tree, layout, renderer, operation); } fn on_event( @@ -495,7 +440,7 @@ where state: &mut Tree, layout: Layout<'_>, renderer: &Renderer, - operation: &mut dyn widget::Operation, + operation: &mut dyn widget::Operation<()>, ) { self.element .widget diff --git a/core/src/lib.rs b/core/src/lib.rs index 32156441..db67219c 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -35,6 +35,7 @@ mod color; mod content_fit; mod element; mod length; +mod maybe; mod padding; mod pixels; mod point; @@ -59,6 +60,7 @@ pub use font::Font; pub use gradient::Gradient; pub use layout::Layout; pub use length::Length; +pub use maybe::{MaybeSend, MaybeSync}; pub use overlay::Overlay; pub use padding::Padding; pub use pixels::Pixels; diff --git a/core/src/maybe.rs b/core/src/maybe.rs new file mode 100644 index 00000000..c6a507c1 --- /dev/null +++ b/core/src/maybe.rs @@ -0,0 +1,35 @@ +#[cfg(not(target_arch = "wasm32"))] +mod platform { + /// An extension trait that enforces `Send` only on native platforms. + /// + /// Useful for writing cross-platform async code! + pub trait MaybeSend: Send {} + + impl MaybeSend for T where T: Send {} + + /// An extension trait that enforces `Sync` only on native platforms. + /// + /// Useful for writing cross-platform async code! + pub trait MaybeSync: Sync {} + + impl MaybeSync for T where T: Sync {} +} + +#[cfg(target_arch = "wasm32")] +mod platform { + /// An extension trait that enforces `Send` only on native platforms. + /// + /// Useful for writing cross-platform async code! + pub trait MaybeSend {} + + impl MaybeSend for T {} + + /// An extension trait that enforces `Sync` only on native platforms. + /// + /// Useful for writing cross-platform async code! + pub trait MaybeSync {} + + impl MaybeSync for T {} +} + +pub use platform::{MaybeSend, MaybeSync}; diff --git a/core/src/overlay.rs b/core/src/overlay.rs index 3a57fe16..16f867da 100644 --- a/core/src/overlay.rs +++ b/core/src/overlay.rs @@ -41,7 +41,7 @@ where &mut self, _layout: Layout<'_>, _renderer: &Renderer, - _operation: &mut dyn widget::Operation, + _operation: &mut dyn widget::Operation<()>, ) { } diff --git a/core/src/overlay/element.rs b/core/src/overlay/element.rs index 695b88b3..61e75e8a 100644 --- a/core/src/overlay/element.rs +++ b/core/src/overlay/element.rs @@ -5,9 +5,7 @@ use crate::layout; use crate::mouse; use crate::renderer; use crate::widget; -use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size, Vector}; - -use std::any::Any; +use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size}; /// A generic [`Overlay`]. #[allow(missing_debug_implementations)] @@ -94,7 +92,7 @@ where &mut self, layout: Layout<'_>, renderer: &Renderer, - operation: &mut dyn widget::Operation, + operation: &mut dyn widget::Operation<()>, ) { self.overlay.operate(layout, renderer, operation); } @@ -146,59 +144,9 @@ where &mut self, layout: Layout<'_>, renderer: &Renderer, - operation: &mut dyn widget::Operation, + operation: &mut dyn widget::Operation<()>, ) { - struct MapOperation<'a, B> { - operation: &'a mut dyn widget::Operation, - } - - impl<'a, T, B> widget::Operation for MapOperation<'a, B> { - fn container( - &mut self, - id: Option<&widget::Id>, - bounds: Rectangle, - operate_on_children: &mut dyn FnMut( - &mut dyn widget::Operation, - ), - ) { - self.operation.container(id, bounds, &mut |operation| { - operate_on_children(&mut MapOperation { operation }); - }); - } - - fn focusable( - &mut self, - state: &mut dyn widget::operation::Focusable, - id: Option<&widget::Id>, - ) { - self.operation.focusable(state, id); - } - - fn scrollable( - &mut self, - state: &mut dyn widget::operation::Scrollable, - id: Option<&widget::Id>, - bounds: Rectangle, - translation: Vector, - ) { - self.operation.scrollable(state, id, bounds, translation); - } - - fn text_input( - &mut self, - state: &mut dyn widget::operation::TextInput, - id: Option<&widget::Id>, - ) { - self.operation.text_input(state, id); - } - - fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) { - self.operation.custom(state, id); - } - } - - self.content - .operate(layout, renderer, &mut MapOperation { operation }); + self.content.operate(layout, renderer, operation); } fn on_event( diff --git a/core/src/overlay/group.rs b/core/src/overlay/group.rs index 7e4bebd0..cd12eac9 100644 --- a/core/src/overlay/group.rs +++ b/core/src/overlay/group.rs @@ -132,7 +132,7 @@ where &mut self, layout: Layout<'_>, renderer: &Renderer, - operation: &mut dyn widget::Operation, + operation: &mut dyn widget::Operation<()>, ) { operation.container(None, layout.bounds(), &mut |operation| { self.children.iter_mut().zip(layout.children()).for_each( diff --git a/core/src/widget.rs b/core/src/widget.rs index b02e3a4f..0d12deba 100644 --- a/core/src/widget.rs +++ b/core/src/widget.rs @@ -105,7 +105,7 @@ where _state: &mut Tree, _layout: Layout<'_>, _renderer: &Renderer, - _operation: &mut dyn Operation, + _operation: &mut dyn Operation<()>, ) { } diff --git a/core/src/widget/operation.rs b/core/src/widget/operation.rs index b91cf9ac..1fa924a4 100644 --- a/core/src/widget/operation.rs +++ b/core/src/widget/operation.rs @@ -8,15 +8,15 @@ pub use scrollable::Scrollable; pub use text_input::TextInput; use crate::widget::Id; -use crate::{Rectangle, Vector}; +use crate::{MaybeSend, Rectangle, Vector}; use std::any::Any; use std::fmt; -use std::rc::Rc; +use std::sync::Arc; /// A piece of logic that can traverse the widget tree of an application in /// order to query or update some widget state. -pub trait Operation { +pub trait Operation: MaybeSend { /// Operates on a widget that contains other widgets. /// /// The `operate_on_children` function can be called to return control to @@ -81,7 +81,7 @@ where /// Maps the output of an [`Operation`] using the given function. pub fn map( operation: Box>, - f: impl Fn(A) -> B + 'static, + f: impl Fn(A) -> B + Send + Sync + 'static, ) -> impl Operation where A: 'static, @@ -90,7 +90,7 @@ where #[allow(missing_debug_implementations)] struct Map { operation: Box>, - f: Rc B>, + f: Arc B + Send + Sync>, } impl Operation for Map @@ -197,7 +197,7 @@ where Map { operation, - f: Rc::new(f), + f: Arc::new(f), } } -- cgit From b328da2c71e998e539bdc65815061e88dd1e7081 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 14 Jun 2024 01:52:30 +0200 Subject: Fix `Send` requirements for Wasm targets --- core/src/widget/operation.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/src/widget/operation.rs b/core/src/widget/operation.rs index 1fa924a4..3e4ed618 100644 --- a/core/src/widget/operation.rs +++ b/core/src/widget/operation.rs @@ -8,7 +8,7 @@ pub use scrollable::Scrollable; pub use text_input::TextInput; use crate::widget::Id; -use crate::{MaybeSend, Rectangle, Vector}; +use crate::{Rectangle, Vector}; use std::any::Any; use std::fmt; @@ -16,7 +16,7 @@ use std::sync::Arc; /// A piece of logic that can traverse the widget tree of an application in /// order to query or update some widget state. -pub trait Operation: MaybeSend { +pub trait Operation: Send { /// Operates on a widget that contains other widgets. /// /// The `operate_on_children` function can be called to return control to -- cgit From 4e7cbbf98ab745351e2fb13a7c85d4ad560c21ee Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 14 Jun 2024 01:57:49 +0200 Subject: Move `Maybe*` traits back to `iced_futures` --- core/src/lib.rs | 2 -- core/src/maybe.rs | 35 ----------------------------------- 2 files changed, 37 deletions(-) delete mode 100644 core/src/maybe.rs (limited to 'core') diff --git a/core/src/lib.rs b/core/src/lib.rs index db67219c..32156441 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -35,7 +35,6 @@ mod color; mod content_fit; mod element; mod length; -mod maybe; mod padding; mod pixels; mod point; @@ -60,7 +59,6 @@ pub use font::Font; pub use gradient::Gradient; pub use layout::Layout; pub use length::Length; -pub use maybe::{MaybeSend, MaybeSync}; pub use overlay::Overlay; pub use padding::Padding; pub use pixels::Pixels; diff --git a/core/src/maybe.rs b/core/src/maybe.rs deleted file mode 100644 index c6a507c1..00000000 --- a/core/src/maybe.rs +++ /dev/null @@ -1,35 +0,0 @@ -#[cfg(not(target_arch = "wasm32"))] -mod platform { - /// An extension trait that enforces `Send` only on native platforms. - /// - /// Useful for writing cross-platform async code! - pub trait MaybeSend: Send {} - - impl MaybeSend for T where T: Send {} - - /// An extension trait that enforces `Sync` only on native platforms. - /// - /// Useful for writing cross-platform async code! - pub trait MaybeSync: Sync {} - - impl MaybeSync for T where T: Sync {} -} - -#[cfg(target_arch = "wasm32")] -mod platform { - /// An extension trait that enforces `Send` only on native platforms. - /// - /// Useful for writing cross-platform async code! - pub trait MaybeSend {} - - impl MaybeSend for T {} - - /// An extension trait that enforces `Sync` only on native platforms. - /// - /// Useful for writing cross-platform async code! - pub trait MaybeSync {} - - impl MaybeSync for T {} -} - -pub use platform::{MaybeSend, MaybeSync}; -- cgit From b21e4567dc32250c90d2ea9c78080cd8bcb66368 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 14 Jun 2024 02:23:25 +0200 Subject: Remove `parent` from `PlatformSpecific` window settings --- core/Cargo.toml | 3 --- core/src/window/settings/windows.rs | 5 ----- 2 files changed, 8 deletions(-) (limited to 'core') diff --git a/core/Cargo.toml b/core/Cargo.toml index 3c557bca..a1228909 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -33,8 +33,5 @@ web-time.workspace = true dark-light.workspace = true dark-light.optional = true -[target.'cfg(windows)'.dependencies] -raw-window-handle.workspace = true - [dev-dependencies] approx = "0.5" diff --git a/core/src/window/settings/windows.rs b/core/src/window/settings/windows.rs index d3bda259..88fe2fbd 100644 --- a/core/src/window/settings/windows.rs +++ b/core/src/window/settings/windows.rs @@ -1,12 +1,8 @@ //! Platform specific settings for Windows. -use raw_window_handle::RawWindowHandle; /// The platform specific window settings of an application. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct PlatformSpecific { - /// Parent window - pub parent: Option, - /// Drag and drop support pub drag_and_drop: bool, @@ -17,7 +13,6 @@ pub struct PlatformSpecific { impl Default for PlatformSpecific { fn default() -> Self { Self { - parent: None, drag_and_drop: true, skip_taskbar: false, } -- cgit