From 782c080bd098dd56e74a3c8adabf09bf5dae047b Mon Sep 17 00:00:00 2001 From: lupd <93457935+lupd@users.noreply.github.com> Date: Wed, 8 Mar 2023 12:55:52 -0500 Subject: Use correct package name in checkbox example docs --- examples/checkbox/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/checkbox/README.md b/examples/checkbox/README.md index b7f85684..76e6764c 100644 --- a/examples/checkbox/README.md +++ b/examples/checkbox/README.md @@ -6,7 +6,7 @@ The __[`main`]__ file contains all the code of the example. You can run it with `cargo run`: ``` -cargo run --package pick_list +cargo run --package checkbox ``` [`main`]: src/main.rs -- cgit From 1816c985fad2ead8dc1e7b62dc8e4bafeed856b2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 14 Mar 2023 11:11:17 +0100 Subject: Fix `clippy` lints for Rust 1.68 --- core/src/font.rs | 9 ++------- core/src/mouse/interaction.rs | 9 ++------- examples/pick_list/src/main.rs | 9 ++------- examples/todos/src/main.rs | 11 ++++------- graphics/src/primitive.rs | 9 ++------- graphics/src/widget/canvas/cache.rs | 7 ++----- graphics/src/widget/canvas/stroke.rs | 18 ++++-------------- 7 files changed, 18 insertions(+), 54 deletions(-) diff --git a/core/src/font.rs b/core/src/font.rs index 3f9ad2b5..d8c34e5a 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -1,10 +1,11 @@ /// A font. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Default)] pub enum Font { /// The default font. /// /// This is normally a font configured in a renderer or loaded from the /// system. + #[default] Default, /// An external font. @@ -16,9 +17,3 @@ pub enum Font { bytes: &'static [u8], }, } - -impl Default for Font { - fn default() -> Font { - Font::Default - } -} diff --git a/core/src/mouse/interaction.rs b/core/src/mouse/interaction.rs index 664147a7..57da93fe 100644 --- a/core/src/mouse/interaction.rs +++ b/core/src/mouse/interaction.rs @@ -1,7 +1,8 @@ /// The interaction of a mouse cursor. -#[derive(Debug, Eq, PartialEq, Clone, Copy, PartialOrd, Ord)] +#[derive(Debug, Eq, PartialEq, Clone, Copy, PartialOrd, Ord, Default)] #[allow(missing_docs)] pub enum Interaction { + #[default] Idle, Pointer, Grab, @@ -12,9 +13,3 @@ pub enum Interaction { ResizingHorizontally, ResizingVertically, } - -impl Default for Interaction { - fn default() -> Interaction { - Interaction::Idle - } -} diff --git a/examples/pick_list/src/main.rs b/examples/pick_list/src/main.rs index 62a4ef88..21200621 100644 --- a/examples/pick_list/src/main.rs +++ b/examples/pick_list/src/main.rs @@ -61,8 +61,9 @@ impl Sandbox for Example { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum Language { + #[default] Rust, Elm, Ruby, @@ -84,12 +85,6 @@ impl Language { ]; } -impl Default for Language { - fn default() -> Language { - Language::Rust - } -} - impl std::fmt::Display for Language { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 6a87f58c..6361667e 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -435,19 +435,16 @@ fn view_controls(tasks: &[Task], current_filter: Filter) -> Element { .into() } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, +)] pub enum Filter { + #[default] All, Active, Completed, } -impl Default for Filter { - fn default() -> Self { - Filter::All - } -} - impl Filter { fn matches(&self, task: &Task) -> bool { match self { diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 5a163a2f..cef422a2 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -9,9 +9,10 @@ use crate::triangle; use std::sync::Arc; /// A rendering primitive. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub enum Primitive { /// An empty primitive + #[default] None, /// A group of primitives Group { @@ -117,9 +118,3 @@ pub enum Primitive { cache: Arc, }, } - -impl Default for Primitive { - fn default() -> Primitive { - Primitive::None - } -} diff --git a/graphics/src/widget/canvas/cache.rs b/graphics/src/widget/canvas/cache.rs index 52217bbb..678b0f92 100644 --- a/graphics/src/widget/canvas/cache.rs +++ b/graphics/src/widget/canvas/cache.rs @@ -4,7 +4,9 @@ use crate::Primitive; use iced_native::Size; use std::{cell::RefCell, sync::Arc}; +#[derive(Default)] enum State { + #[default] Empty, Filled { bounds: Size, @@ -12,11 +14,6 @@ enum State { }, } -impl Default for State { - fn default() -> Self { - State::Empty - } -} /// A simple cache that stores generated [`Geometry`] to avoid recomputation. /// /// A [`Cache`] will not redraw its geometry unless the dimensions of its layer diff --git a/graphics/src/widget/canvas/stroke.rs b/graphics/src/widget/canvas/stroke.rs index 4c19251d..49f5701c 100644 --- a/graphics/src/widget/canvas/stroke.rs +++ b/graphics/src/widget/canvas/stroke.rs @@ -59,9 +59,10 @@ impl<'a> Default for Stroke<'a> { } /// The shape used at the end of open subpaths when they are stroked. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Default)] pub enum LineCap { /// The stroke for each sub-path does not extend beyond its two endpoints. + #[default] Butt, /// At the end of each sub-path, the shape representing the stroke will be /// extended by a square. @@ -71,12 +72,6 @@ pub enum LineCap { Round, } -impl Default for LineCap { - fn default() -> LineCap { - LineCap::Butt - } -} - impl From for lyon::tessellation::LineCap { fn from(line_cap: LineCap) -> lyon::tessellation::LineCap { match line_cap { @@ -89,9 +84,10 @@ impl From for lyon::tessellation::LineCap { /// The shape used at the corners of paths or basic shapes when they are /// stroked. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Default)] pub enum LineJoin { /// A sharp corner. + #[default] Miter, /// A round corner. Round, @@ -99,12 +95,6 @@ pub enum LineJoin { Bevel, } -impl Default for LineJoin { - fn default() -> LineJoin { - LineJoin::Miter - } -} - impl From for lyon::tessellation::LineJoin { fn from(line_join: LineJoin) -> lyon::tessellation::LineJoin { match line_join { -- cgit From ed7b61380473c7c88c25b5d4d17112b844a9364d Mon Sep 17 00:00:00 2001 From: Casper Storm Date: Thu, 23 Feb 2023 14:33:53 +0100 Subject: Added macOS platform specific options --- src/window.rs | 2 +- src/window/settings.rs | 18 +++++++++++++++++- src/window/settings/macos.rs | 20 ++++++++++++++++++++ src/window/settings/other.rs | 9 +++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/window/settings/macos.rs create mode 100644 src/window/settings/other.rs diff --git a/src/window.rs b/src/window.rs index 5a199580..aba4bce8 100644 --- a/src/window.rs +++ b/src/window.rs @@ -6,6 +6,6 @@ pub mod icon; pub use icon::Icon; pub use position::Position; -pub use settings::Settings; +pub use settings::{PlatformSpecific, Settings}; pub use crate::runtime::window::*; diff --git a/src/window/settings.rs b/src/window/settings.rs index 24d0f4f9..a039e213 100644 --- a/src/window/settings.rs +++ b/src/window/settings.rs @@ -1,5 +1,15 @@ use crate::window::{Icon, Position}; +#[cfg(target_os = "macos")] +#[path = "settings/macos.rs"] +mod platform; + +#[cfg(not(target_os = "macos"))] +#[path = "settings/other.rs"] +mod platform; + +pub use platform::PlatformSpecific; + /// The window settings of an application. #[derive(Debug, Clone)] pub struct Settings { @@ -32,6 +42,9 @@ pub struct Settings { /// The icon of the window. pub icon: Option, + + /// Platform specific settings. + pub platform_specific: platform::PlatformSpecific, } impl Default for Settings { @@ -47,6 +60,7 @@ impl Default for Settings { transparent: false, always_on_top: false, icon: None, + platform_specific: Default::default(), } } } @@ -64,7 +78,9 @@ impl From for iced_winit::settings::Window { transparent: settings.transparent, always_on_top: settings.always_on_top, icon: settings.icon.map(Icon::into), - platform_specific: Default::default(), + platform_specific: iced_winit::settings::PlatformSpecific::from( + settings.platform_specific, + ), } } } diff --git a/src/window/settings/macos.rs b/src/window/settings/macos.rs new file mode 100644 index 00000000..c08020cf --- /dev/null +++ b/src/window/settings/macos.rs @@ -0,0 +1,20 @@ +/// The platform specific window settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct PlatformSpecific { + /// Hides the window title. + pub title_hidden: bool, + /// Makes the titlebar transparent and allows the content to appear behind it. + pub titlebar_transparent: bool, + /// Makes the window content appear behind the titlebar. + pub fullsize_content_view: bool, +} + +impl From for iced_winit::settings::PlatformSpecific { + fn from(platform_specific: PlatformSpecific) -> Self { + Self { + title_hidden: platform_specific.title_hidden, + titlebar_transparent: platform_specific.titlebar_transparent, + fullsize_content_view: platform_specific.fullsize_content_view, + } + } +} diff --git a/src/window/settings/other.rs b/src/window/settings/other.rs new file mode 100644 index 00000000..943d9f0d --- /dev/null +++ b/src/window/settings/other.rs @@ -0,0 +1,9 @@ +/// The platform specific window settings of an application. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct PlatformSpecific; + +impl From for iced_winit::settings::PlatformSpecific { + fn from(_: PlatformSpecific) -> Self { + Default::default() + } +} -- cgit From 4405a3d483286faf962930ca3b294b34f86bd2f4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 14 Mar 2023 11:22:06 +0100 Subject: Re-export `settings::PlatformSpecific` from `iced_winit` directly --- src/window/settings.rs | 16 +++------------- src/window/settings/macos.rs | 20 -------------------- src/window/settings/other.rs | 9 --------- 3 files changed, 3 insertions(+), 42 deletions(-) delete mode 100644 src/window/settings/macos.rs delete mode 100644 src/window/settings/other.rs diff --git a/src/window/settings.rs b/src/window/settings.rs index a039e213..3c8da62f 100644 --- a/src/window/settings.rs +++ b/src/window/settings.rs @@ -1,14 +1,6 @@ use crate::window::{Icon, Position}; -#[cfg(target_os = "macos")] -#[path = "settings/macos.rs"] -mod platform; - -#[cfg(not(target_os = "macos"))] -#[path = "settings/other.rs"] -mod platform; - -pub use platform::PlatformSpecific; +pub use iced_winit::settings::PlatformSpecific; /// The window settings of an application. #[derive(Debug, Clone)] @@ -44,7 +36,7 @@ pub struct Settings { pub icon: Option, /// Platform specific settings. - pub platform_specific: platform::PlatformSpecific, + pub platform_specific: PlatformSpecific, } impl Default for Settings { @@ -78,9 +70,7 @@ impl From for iced_winit::settings::Window { transparent: settings.transparent, always_on_top: settings.always_on_top, icon: settings.icon.map(Icon::into), - platform_specific: iced_winit::settings::PlatformSpecific::from( - settings.platform_specific, - ), + platform_specific: settings.platform_specific, } } } diff --git a/src/window/settings/macos.rs b/src/window/settings/macos.rs deleted file mode 100644 index c08020cf..00000000 --- a/src/window/settings/macos.rs +++ /dev/null @@ -1,20 +0,0 @@ -/// The platform specific window settings of an application. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -pub struct PlatformSpecific { - /// Hides the window title. - pub title_hidden: bool, - /// Makes the titlebar transparent and allows the content to appear behind it. - pub titlebar_transparent: bool, - /// Makes the window content appear behind the titlebar. - pub fullsize_content_view: bool, -} - -impl From for iced_winit::settings::PlatformSpecific { - fn from(platform_specific: PlatformSpecific) -> Self { - Self { - title_hidden: platform_specific.title_hidden, - titlebar_transparent: platform_specific.titlebar_transparent, - fullsize_content_view: platform_specific.fullsize_content_view, - } - } -} diff --git a/src/window/settings/other.rs b/src/window/settings/other.rs deleted file mode 100644 index 943d9f0d..00000000 --- a/src/window/settings/other.rs +++ /dev/null @@ -1,9 +0,0 @@ -/// The platform specific window settings of an application. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -pub struct PlatformSpecific; - -impl From for iced_winit::settings::PlatformSpecific { - fn from(_: PlatformSpecific) -> Self { - Default::default() - } -} -- cgit