From 2c103f8654943c773b6de3c70eb2927e92219422 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Thu, 27 Oct 2022 11:48:42 -0700 Subject: Constrain padding to inner & outer sizes --- core/src/padding.rs | 14 ++++++++++++++ core/src/size.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'core') diff --git a/core/src/padding.rs b/core/src/padding.rs index 22467d6b..64c95c89 100644 --- a/core/src/padding.rs +++ b/core/src/padding.rs @@ -1,3 +1,5 @@ +use crate::Size; + /// An amount of space to pad for each side of a box /// /// You can leverage the `From` trait to build [`Padding`] conveniently: @@ -71,6 +73,18 @@ impl Padding { pub fn horizontal(self) -> u16 { self.left + self.right } + + /// Constrains the padding to fit between the inner & outer [`Size`] + pub fn constrain(self, inner: Size, outer: Size) -> Self { + let available = (outer - inner).max(Size::ZERO); + + Padding { + top: self.top.min((available.height / 2.0) as u16), + right: self.right.min((available.width / 2.0) as u16), + bottom: self.bottom.min((available.height / 2.0) as u16), + left: self.left.min((available.width / 2.0) as u16), + } + } } impl std::convert::From for Padding { diff --git a/core/src/size.rs b/core/src/size.rs index 2db33a88..31f3171b 100644 --- a/core/src/size.rs +++ b/core/src/size.rs @@ -34,6 +34,22 @@ impl Size { height: self.height + padding.vertical() as f32, } } + + /// Returns the minimum of each component of this size and another + pub fn min(self, other: Self) -> Self { + Size { + width: self.width.min(other.width), + height: self.height.min(other.height), + } + } + + /// Returns the maximum of each component of this size and another + pub fn max(self, other: Self) -> Self { + Size { + width: self.width.max(other.width), + height: self.height.max(other.height), + } + } } impl From<[f32; 2]> for Size { @@ -68,3 +84,14 @@ impl From for Vector { Vector::new(size.width, size.height) } } + +impl std::ops::Sub for Size { + type Output = Size; + + fn sub(self, rhs: Self) -> Self::Output { + Size { + width: self.width - rhs.width, + height: self.height - rhs.height, + } + } +} -- cgit From 7476663069572adec25161b46c26570f864f736f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 8 Nov 2022 03:56:05 +0100 Subject: Rename `Padding::constrain` to `fit` --- core/src/padding.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/src/padding.rs b/core/src/padding.rs index 64c95c89..ad5d1f0f 100644 --- a/core/src/padding.rs +++ b/core/src/padding.rs @@ -74,8 +74,8 @@ impl Padding { self.left + self.right } - /// Constrains the padding to fit between the inner & outer [`Size`] - pub fn constrain(self, inner: Size, outer: Size) -> Self { + /// Fits the [`Padding`] between the provided `inner` and `outer` [`Size`]. + pub fn fit(self, inner: Size, outer: Size) -> Self { let available = (outer - inner).max(Size::ZERO); Padding { -- cgit From 24d031b51c85507199b0e33e44c5a871882f6b32 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 8 Nov 2022 04:11:06 +0100 Subject: Cast to `u16` first then divide by `2` in `Padding::fit` --- core/src/padding.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/src/padding.rs b/core/src/padding.rs index ad5d1f0f..8d701f80 100644 --- a/core/src/padding.rs +++ b/core/src/padding.rs @@ -79,10 +79,10 @@ impl Padding { let available = (outer - inner).max(Size::ZERO); Padding { - top: self.top.min((available.height / 2.0) as u16), - right: self.right.min((available.width / 2.0) as u16), - bottom: self.bottom.min((available.height / 2.0) as u16), - left: self.left.min((available.width / 2.0) as u16), + top: self.top.min((available.height as u16) / 2), + right: self.right.min((available.width as u16) / 2), + bottom: self.bottom.min((available.height as u16) / 2), + left: self.left.min((available.width as u16) / 2), } } } -- cgit From 04087b2a867520cfc43a648fa9e93cee2a6daf3c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 8 Nov 2022 04:11:45 +0100 Subject: Remove redundant `std::convert` namespace in `padding` --- core/src/padding.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/src/padding.rs b/core/src/padding.rs index 8d701f80..140ad8ee 100644 --- a/core/src/padding.rs +++ b/core/src/padding.rs @@ -87,7 +87,7 @@ impl Padding { } } -impl std::convert::From for Padding { +impl From for Padding { fn from(p: u16) -> Self { Padding { top: p, @@ -98,7 +98,7 @@ impl std::convert::From for Padding { } } -impl std::convert::From<[u16; 2]> for Padding { +impl From<[u16; 2]> for Padding { fn from(p: [u16; 2]) -> Self { Padding { top: p[0], @@ -109,7 +109,7 @@ impl std::convert::From<[u16; 2]> for Padding { } } -impl std::convert::From<[u16; 4]> for Padding { +impl From<[u16; 4]> for Padding { fn from(p: [u16; 4]) -> Self { Padding { top: p[0], -- cgit From b0e8bafb6c51666e8b15531001263097ae7d7c0e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 10 Nov 2022 01:20:11 +0100 Subject: Bump versions :tada: --- core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/Cargo.toml b/core/Cargo.toml index c9c7686e..9f6e830a 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_core" -version = "0.5.0" +version = "0.6.0" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "The essential concepts of Iced" -- cgit From a6298ba12c038d5eaddca9327abb385aa72a82e9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 10 Nov 2022 18:14:40 +0100 Subject: Fix outdated links in documentation --- core/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/src/lib.rs b/core/src/lib.rs index 03ba8cca..383b4f73 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -7,7 +7,7 @@ //! ![The foundations of the Iced ecosystem](https://github.com/iced-rs/iced/blob/0525d76ff94e828b7b21634fa94a747022001c83/docs/graphs/foundations.png?raw=true) //! //! [Iced]: https://github.com/iced-rs/iced -//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native +//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native //! [`iced_web`]: https://github.com/iced-rs/iced_web #![doc( html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" -- cgit From 23299a555f8b7e908a6a14915307792a7cf97b9a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 10 Nov 2022 18:15:10 +0100 Subject: Bump versions :tada: --- core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/Cargo.toml b/core/Cargo.toml index 9f6e830a..6fd0a38c 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_core" -version = "0.6.0" +version = "0.6.1" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "The essential concepts of Iced" -- cgit From 0249640213120e039462f5fc12c677f15ecbc7cc Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Wed, 16 Nov 2022 16:35:56 +0100 Subject: feat: Add Color::into_rgb8 --- core/src/color.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'core') diff --git a/core/src/color.rs b/core/src/color.rs index 212c1214..e578eda4 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -89,6 +89,19 @@ impl Color { } } + /// Converts the [`Color`] into its RGBA8 equivalent. + #[must_use] + #[allow(clippy::cast_sign_loss)] + #[allow(clippy::cast_possible_truncation)] + pub fn into_rgba8(self) -> [u8; 4] { + [ + (self.r * 255.0).round() as u8, + (self.g * 255.0).round() as u8, + (self.b * 255.0).round() as u8, + (self.a * 255.0).round() as u8, + ] + } + /// Converts the [`Color`] into its linear values. pub fn into_linear(self) -> [f32; 4] { // As described in: -- cgit From c0ca1807d42b0ec58887df9926ff53a587104723 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 6 Dec 2022 04:34:42 +0100 Subject: Fix macro hygiene of `color!` --- core/src/color.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/src/color.rs b/core/src/color.rs index e578eda4..2a4d43f4 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -161,24 +161,26 @@ impl From<[f32; 4]> for Color { #[macro_export] macro_rules! color { ($r:expr, $g:expr, $b:expr) => { - Color::from_rgb8($r, $g, $b) + $crate::Color::from_rgb8($r, $g, $b) }; ($r:expr, $g:expr, $b:expr, $a:expr) => { - Color::from_rgba8($r, $g, $b, $a) + $crate::Color::from_rgba8($r, $g, $b, $a) }; ($hex:expr) => {{ let hex = $hex as u32; let r = (hex & 0xff0000) >> 16; let g = (hex & 0xff00) >> 8; let b = (hex & 0xff); - Color::from_rgb8(r as u8, g as u8, b as u8) + + $crate::Color::from_rgb8(r as u8, g as u8, b as u8) }}; ($hex:expr, $a:expr) => {{ let hex = $hex as u32; let r = (hex & 0xff0000) >> 16; let g = (hex & 0xff00) >> 8; let b = (hex & 0xff); - Color::from_rgba8(r as u8, g as u8, b as u8, $a) + + $crate::Color::from_rgba8(r as u8, g as u8, b as u8, $a) }}; } -- cgit From 2d58a2c03325a77893461194bd601b312a0097ca Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 6 Dec 2022 04:40:32 +0100 Subject: Remove unnecessary `clippy` directives in `Color` --- core/src/color.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'core') diff --git a/core/src/color.rs b/core/src/color.rs index 2a4d43f4..fe0a1856 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -91,8 +91,6 @@ impl Color { /// Converts the [`Color`] into its RGBA8 equivalent. #[must_use] - #[allow(clippy::cast_sign_loss)] - #[allow(clippy::cast_possible_truncation)] pub fn into_rgba8(self) -> [u8; 4] { [ (self.r * 255.0).round() as u8, -- cgit From 4c61f12768cdbe728b1dd4a074e36fb6a69534ab Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 7 Dec 2022 04:38:00 +0100 Subject: Bump versions :tada: --- core/Cargo.toml | 2 +- core/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/Cargo.toml b/core/Cargo.toml index 6fd0a38c..c401f30a 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_core" -version = "0.6.1" +version = "0.6.2" authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "The essential concepts of Iced" diff --git a/core/src/lib.rs b/core/src/lib.rs index 383b4f73..f95d61f6 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -7,7 +7,7 @@ //! ![The foundations of the Iced ecosystem](https://github.com/iced-rs/iced/blob/0525d76ff94e828b7b21634fa94a747022001c83/docs/graphs/foundations.png?raw=true) //! //! [Iced]: https://github.com/iced-rs/iced -//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native +//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native //! [`iced_web`]: https://github.com/iced-rs/iced_web #![doc( html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" -- cgit