diff options
-rw-r--r-- | core/src/window/event.rs | 2 | ||||
-rw-r--r-- | renderer/src/backend.rs | 100 | ||||
-rw-r--r-- | runtime/src/window.rs | 22 | ||||
-rw-r--r-- | runtime/src/window/action.rs | 23 | ||||
-rw-r--r-- | widget/src/lazy/helpers.rs | 3 | ||||
-rw-r--r-- | winit/src/application.rs | 10 | ||||
-rw-r--r-- | winit/src/multi_window.rs | 14 |
7 files changed, 73 insertions, 101 deletions
diff --git a/core/src/window/event.rs b/core/src/window/event.rs index b9ee7aca..a14d127f 100644 --- a/core/src/window/event.rs +++ b/core/src/window/event.rs @@ -58,7 +58,7 @@ pub enum Event { /// for each file separately. FileHovered(PathBuf), - /// A file has beend dropped into the window. + /// A file has been dropped into the window. /// /// When the user drops multiple files at once, this event will be emitted /// for each file separately. diff --git a/renderer/src/backend.rs b/renderer/src/backend.rs deleted file mode 100644 index 3f229b52..00000000 --- a/renderer/src/backend.rs +++ /dev/null @@ -1,100 +0,0 @@ -use crate::core::text; -use crate::core::{Font, Point, Size}; -use crate::graphics::backend; - -use std::borrow::Cow; - -#[allow(clippy::large_enum_variant)] -pub enum Backend { - TinySkia(iced_tiny_skia::Backend), - #[cfg(feature = "wgpu")] - Wgpu(iced_wgpu::Backend), -} - -macro_rules! delegate { - ($backend:expr, $name:ident, $body:expr) => { - match $backend { - Self::TinySkia($name) => $body, - #[cfg(feature = "wgpu")] - Self::Wgpu($name) => $body, - } - }; -} - -impl backend::Text for Backend { - const ICON_FONT: Font = Font::with_name("Iced-Icons"); - const CHECKMARK_ICON: char = '\u{f00c}'; - const ARROW_DOWN_ICON: char = '\u{e800}'; - - fn default_font(&self) -> Font { - delegate!(self, backend, backend.default_font()) - } - - fn default_size(&self) -> f32 { - delegate!(self, backend, backend.default_size()) - } - - fn measure( - &self, - contents: &str, - size: f32, - line_height: text::LineHeight, - font: Font, - bounds: Size, - shaping: text::Shaping, - ) -> Size { - delegate!( - self, - backend, - backend.measure(contents, size, line_height, font, bounds, shaping) - ) - } - - fn hit_test( - &self, - contents: &str, - size: f32, - line_height: text::LineHeight, - font: Font, - bounds: Size, - shaping: text::Shaping, - position: Point, - nearest_only: bool, - ) -> Option<text::Hit> { - delegate!( - self, - backend, - backend.hit_test( - contents, - size, - line_height, - font, - bounds, - shaping, - position, - nearest_only, - ) - ) - } - - fn load_font(&mut self, font: Cow<'static, [u8]>) { - delegate!(self, backend, backend.load_font(font)); - } -} - -#[cfg(feature = "image")] -impl backend::Image for Backend { - fn dimensions(&self, handle: &crate::core::image::Handle) -> Size<u32> { - delegate!(self, backend, backend.dimensions(handle)) - } -} - -#[cfg(feature = "svg")] -impl backend::Svg for Backend { - fn viewport_dimensions( - &self, - handle: &crate::core::svg::Handle, - ) -> Size<u32> { - delegate!(self, backend, backend.viewport_dimensions(handle)) - } -} diff --git a/runtime/src/window.rs b/runtime/src/window.rs index f9d943f6..2136d64d 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -65,11 +65,33 @@ pub fn fetch_size<Message>( Command::single(command::Action::Window(Action::FetchSize(id, Box::new(f)))) } +/// Fetches if the window is maximized. +pub fn fetch_maximized<Message>( + id: Id, + f: impl FnOnce(bool) -> Message + 'static, +) -> Command<Message> { + Command::single(command::Action::Window(Action::FetchMaximized( + id, + Box::new(f), + ))) +} + /// Maximizes the window. pub fn maximize<Message>(id: Id, maximized: bool) -> Command<Message> { Command::single(command::Action::Window(Action::Maximize(id, maximized))) } +/// Fetches if the window is minimized. +pub fn fetch_minimized<Message>( + id: Id, + f: impl FnOnce(Option<bool>) -> Message + 'static, +) -> Command<Message> { + Command::single(command::Action::Window(Action::FetchMinimized( + id, + Box::new(f), + ))) +} + /// Minimizes the window. pub fn minimize<Message>(id: Id, minimized: bool) -> Command<Message> { Command::single(command::Action::Window(Action::Minimize(id, minimized))) diff --git a/runtime/src/window/action.rs b/runtime/src/window/action.rs index 2d98b607..8b532569 100644 --- a/runtime/src/window/action.rs +++ b/runtime/src/window/action.rs @@ -21,8 +21,19 @@ pub enum Action<T> { Resize(Id, Size), /// Fetch the current logical dimensions of the window. FetchSize(Id, Box<dyn FnOnce(Size) -> T + 'static>), + /// Fetch if the current window is maximized or not. + /// + /// ## Platform-specific + /// - **iOS / Android / Web:** Unsupported. + FetchMaximized(Id, Box<dyn FnOnce(bool) -> T + 'static>), /// Set the window to maximized or back Maximize(Id, bool), + /// Fetch if the current window is minimized or not. + /// + /// ## Platform-specific + /// - **Wayland:** Always `None`. + /// - **iOS / Android / Web:** Unsupported. + FetchMinimized(Id, Box<dyn FnOnce(Option<bool>) -> T + 'static>), /// Set the window to minimized or back Minimize(Id, bool), /// Move the window to the given logical coordinates. @@ -106,7 +117,13 @@ impl<T> Action<T> { Self::FetchSize(id, o) => { Action::FetchSize(id, Box::new(move |s| f(o(s)))) } + Self::FetchMaximized(id, o) => { + Action::FetchMaximized(id, Box::new(move |s| f(o(s)))) + } Self::Maximize(id, maximized) => Action::Maximize(id, maximized), + Self::FetchMinimized(id, o) => { + Action::FetchMinimized(id, Box::new(move |s| f(o(s)))) + } Self::Minimize(id, minimized) => Action::Minimize(id, minimized), Self::Move(id, position) => Action::Move(id, position), Self::ChangeMode(id, mode) => Action::ChangeMode(id, mode), @@ -144,9 +161,15 @@ impl<T> fmt::Debug for Action<T> { write!(f, "Action::Resize({id:?}, {size:?})") } Self::FetchSize(id, _) => write!(f, "Action::FetchSize({id:?})"), + Self::FetchMaximized(id, _) => { + write!(f, "Action::FetchMaximized({id:?})") + } Self::Maximize(id, maximized) => { write!(f, "Action::Maximize({id:?}, {maximized})") } + Self::FetchMinimized(id, _) => { + write!(f, "Action::FetchMinimized({id:?})") + } Self::Minimize(id, minimized) => { write!(f, "Action::Minimize({id:?}, {minimized}") } diff --git a/widget/src/lazy/helpers.rs b/widget/src/lazy/helpers.rs index 8ca9cb86..5dc60d52 100644 --- a/widget/src/lazy/helpers.rs +++ b/widget/src/lazy/helpers.rs @@ -6,6 +6,7 @@ use std::hash::Hash; /// Creates a new [`Lazy`] widget with the given data `Dependency` and a /// closure that can turn this data into a widget tree. +#[cfg(feature = "lazy")] pub fn lazy<'a, Message, Renderer, Dependency, View>( dependency: Dependency, view: impl Fn(&Dependency) -> View + 'a, @@ -19,6 +20,7 @@ where /// Turns an implementor of [`Component`] into an [`Element`] that can be /// embedded in any application. +#[cfg(feature = "lazy")] pub fn component<'a, C, Message, Renderer>( component: C, ) -> Element<'a, Message, Renderer> @@ -37,6 +39,7 @@ where /// The `view` closure will be provided with the current [`Size`] of /// the [`Responsive`] widget and, therefore, can be used to build the /// contents of the widget in a responsive way. +#[cfg(feature = "lazy")] pub fn responsive<'a, Message, Renderer>( f: impl Fn(Size) -> Element<'a, Message, Renderer> + 'a, ) -> Responsive<'a, Message, Renderer> diff --git a/winit/src/application.rs b/winit/src/application.rs index d9700075..35a35872 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -742,9 +742,19 @@ pub fn run_command<A, C, E>( ))) .expect("Send message to event loop"); } + window::Action::FetchMaximized(_id, callback) => { + proxy + .send_event(callback(window.is_maximized())) + .expect("Send message to event loop"); + } window::Action::Maximize(_id, maximized) => { window.set_maximized(maximized); } + window::Action::FetchMinimized(_id, callback) => { + proxy + .send_event(callback(window.is_minimized())) + .expect("Send message to event loop"); + } window::Action::Minimize(_id, minimized) => { window.set_minimized(minimized); } diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs index 84651d40..1550b94b 100644 --- a/winit/src/multi_window.rs +++ b/winit/src/multi_window.rs @@ -942,11 +942,25 @@ fn run_command<A, C, E>( .expect("Send message to event loop"); } } + window::Action::FetchMaximized(id, callback) => { + if let Some(window) = window_manager.get_mut(id) { + proxy + .send_event(callback(window.raw.is_maximized())) + .expect("Send message to event loop"); + } + } window::Action::Maximize(id, maximized) => { if let Some(window) = window_manager.get_mut(id) { window.raw.set_maximized(maximized); } } + window::Action::FetchMinimized(id, callback) => { + if let Some(window) = window_manager.get_mut(id) { + proxy + .send_event(callback(window.raw.is_minimized())) + .expect("Send message to event loop"); + } + } window::Action::Minimize(id, minimized) => { if let Some(window) = window_manager.get_mut(id) { window.raw.set_minimized(minimized); |