diff options
author | 2024-03-19 22:09:36 +0900 | |
---|---|---|
committer | 2024-03-19 22:09:36 +0900 | |
commit | f3a1c785b2743e9c48c3d28df0c6772ce579d7c8 (patch) | |
tree | 1b39799f45878d89b4f9e2f9bea8fa8a7ed07150 /core | |
parent | c9453cd55d84f0dd2ad0050208863d036c98843f (diff) | |
parent | 8ce16aba6204cb5c02a709cdf79c309f7b7e0196 (diff) | |
download | iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.tar.gz iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.tar.bz2 iced-f3a1c785b2743e9c48c3d28df0c6772ce579d7c8.zip |
Merge branch 'iced-rs:master' into viewer_content_fit
Diffstat (limited to '')
-rw-r--r-- | core/src/angle.rs | 24 | ||||
-rw-r--r-- | core/src/size.rs | 29 | ||||
-rw-r--r-- | core/src/theme.rs | 6 | ||||
-rw-r--r-- | core/src/theme/palette.rs | 15 | ||||
-rw-r--r-- | core/src/window/redraw_request.rs | 2 |
5 files changed, 62 insertions, 14 deletions
diff --git a/core/src/angle.rs b/core/src/angle.rs index 30ddad83..dc3c0e93 100644 --- a/core/src/angle.rs +++ b/core/src/angle.rs @@ -7,6 +7,18 @@ use std::ops::{Add, AddAssign, Div, Mul, RangeInclusive, Sub, SubAssign}; #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] pub struct Degrees(pub f32); +impl PartialEq<f32> for Degrees { + fn eq(&self, other: &f32) -> bool { + self.0.eq(other) + } +} + +impl PartialOrd<f32> for Degrees { + fn partial_cmp(&self, other: &f32) -> Option<std::cmp::Ordering> { + self.0.partial_cmp(other) + } +} + /// Radians #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] pub struct Radians(pub f32); @@ -140,3 +152,15 @@ impl Div for Radians { Self(self.0 / rhs.0) } } + +impl PartialEq<f32> for Radians { + fn eq(&self, other: &f32) -> bool { + self.0.eq(other) + } +} + +impl PartialOrd<f32> for Radians { + fn partial_cmp(&self, other: &f32) -> Option<std::cmp::Ordering> { + self.0.partial_cmp(other) + } +} diff --git a/core/src/size.rs b/core/src/size.rs index 90e50d13..267fc90e 100644 --- a/core/src/size.rs +++ b/core/src/size.rs @@ -53,20 +53,20 @@ impl Size { } } -impl From<[f32; 2]> for Size { - fn from([width, height]: [f32; 2]) -> Self { +impl<T> From<[T; 2]> for Size<T> { + fn from([width, height]: [T; 2]) -> Self { Size { width, height } } } -impl From<[u16; 2]> for Size { - fn from([width, height]: [u16; 2]) -> Self { - Size::new(width.into(), height.into()) +impl<T> From<(T, T)> for Size<T> { + fn from((width, height): (T, T)) -> Self { + Self { width, height } } } -impl From<Vector<f32>> for Size { - fn from(vector: Vector<f32>) -> Self { +impl<T> From<Vector<T>> for Size<T> { + fn from(vector: Vector<T>) -> Self { Size { width: vector.x, height: vector.y, @@ -74,20 +74,23 @@ impl From<Vector<f32>> for Size { } } -impl From<Size> for [f32; 2] { - fn from(size: Size) -> [f32; 2] { +impl<T> From<Size<T>> for [T; 2] { + fn from(size: Size<T>) -> Self { [size.width, size.height] } } -impl From<Size> for Vector<f32> { - fn from(size: Size) -> Self { +impl<T> From<Size<T>> for Vector<T> { + fn from(size: Size<T>) -> Self { Vector::new(size.width, size.height) } } -impl std::ops::Sub for Size { - type Output = Size; +impl<T> std::ops::Sub for Size<T> +where + T: std::ops::Sub<Output = T>, +{ + type Output = Size<T>; fn sub(self, rhs: Self) -> Self::Output { Size { diff --git a/core/src/theme.rs b/core/src/theme.rs index 21ba2a37..948aaf83 100644 --- a/core/src/theme.rs +++ b/core/src/theme.rs @@ -52,6 +52,8 @@ pub enum Theme { Nightfly, /// The built-in Oxocarbon variant. Oxocarbon, + /// The built-in Ferra variant: + Ferra, /// A [`Theme`] that uses a [`Custom`] palette. Custom(Arc<Custom>), } @@ -80,6 +82,7 @@ impl Theme { Self::Moonfly, Self::Nightfly, Self::Oxocarbon, + Self::Ferra, ]; /// Creates a new custom [`Theme`] from the given [`Palette`]. @@ -121,6 +124,7 @@ impl Theme { Self::Moonfly => Palette::MOONFLY, Self::Nightfly => Palette::NIGHTFLY, Self::Oxocarbon => Palette::OXOCARBON, + Self::Ferra => Palette::FERRA, Self::Custom(custom) => custom.palette, } } @@ -151,6 +155,7 @@ impl Theme { Self::Moonfly => &palette::EXTENDED_MOONFLY, Self::Nightfly => &palette::EXTENDED_NIGHTFLY, Self::Oxocarbon => &palette::EXTENDED_OXOCARBON, + Self::Ferra => &palette::EXTENDED_FERRA, Self::Custom(custom) => &custom.extended, } } @@ -180,6 +185,7 @@ impl fmt::Display for Theme { Self::Moonfly => write!(f, "Moonfly"), Self::Nightfly => write!(f, "Nightfly"), Self::Oxocarbon => write!(f, "Oxocarbon"), + Self::Ferra => write!(f, "Ferra"), Self::Custom(custom) => custom.fmt(f), } } diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index 985a54a8..ca91c248 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -276,6 +276,17 @@ impl Palette { success: color!(0x00c15a), danger: color!(0xf62d0f), }; + + /// The built-in [Ferra] variant of a [`Palette`]. + /// + /// [Ferra]: https://github.com/casperstorm/ferra + pub const FERRA: Self = Self { + background: color!(0x2b292d), + text: color!(0xfecdb2), + primary: color!(0xd1d1e0), + success: color!(0xb1b695), + danger: color!(0xe06b75), + }; } /// An extended set of colors generated from a [`Palette`]. @@ -379,6 +390,10 @@ pub static EXTENDED_NIGHTFLY: Lazy<Extended> = pub static EXTENDED_OXOCARBON: Lazy<Extended> = Lazy::new(|| Extended::generate(Palette::OXOCARBON)); +/// The built-in Ferra variant of an [`Extended`] palette. +pub static EXTENDED_FERRA: Lazy<Extended> = + Lazy::new(|| Extended::generate(Palette::FERRA)); + impl Extended { /// Generates an [`Extended`] palette from a simple [`Palette`]. pub fn generate(palette: Palette) -> Self { diff --git a/core/src/window/redraw_request.rs b/core/src/window/redraw_request.rs index 8a59e83c..b0c000d6 100644 --- a/core/src/window/redraw_request.rs +++ b/core/src/window/redraw_request.rs @@ -13,7 +13,7 @@ pub enum RedrawRequest { #[cfg(test)] mod tests { use super::*; - use crate::time::{Duration, Instant}; + use crate::time::Duration; #[test] fn ordering() { |