From 020fb3c37794fcfa2670c3c0ada949aee95855a0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 3 Sep 2023 01:01:33 +0200 Subject: Fix `iced_wgpu` device selection on Wasm --- core/src/window/redraw_request.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/src/window/redraw_request.rs b/core/src/window/redraw_request.rs index 3b4f0fd3..8a59e83c 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 std::time::{Duration, Instant}; + use crate::time::{Duration, Instant}; #[test] fn ordering() { -- cgit From f468e25d0c67a01ee79d892f6e8ba9be019f06c7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 4 Sep 2023 12:58:41 +0200 Subject: Use workspace dependencies and package inheritance We are also taking this as a chance to synchronize the versions of all the crates! Because of this, we will skip the `0.11` version. --- core/Cargo.toml | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'core') diff --git a/core/Cargo.toml b/core/Cargo.toml index 8bb37309..8859e91e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,24 +1,26 @@ [package] name = "iced_core" -version = "0.10.0" -authors = ["Héctor Ramón Jiménez "] -edition = "2021" -description = "The essential concepts of Iced" -license = "MIT" -repository = "https://github.com/iced-rs/iced" +description = "The essential ideas of iced" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +categories.workspace = true +keywords.workspace = true [dependencies] -bitflags = "1.2" -thiserror = "1" -log = "0.4.17" -twox-hash = { version = "1.5", default-features = false } +bitflags.workspace = true +log.workspace = true +thiserror.workspace = true +twox-hash.workspace = true -[dependencies.palette] -version = "0.7" -optional = true +palette.workspace = true +palette.optional = true [target.'cfg(target_arch = "wasm32")'.dependencies] -instant = "0.1" +instant.workspace = true [dev-dependencies] approx = "0.5" -- cgit From d2294737c2e28b3b3050d7bf820bbca09896b00e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Sep 2023 01:58:52 +0200 Subject: Use `Radians` as a number directly in `gradient` example --- core/Cargo.toml | 1 + core/src/angle.rs | 45 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/Cargo.toml b/core/Cargo.toml index 8859e91e..7acb7511 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -15,6 +15,7 @@ bitflags.workspace = true log.workspace = true thiserror.workspace = true twox-hash.workspace = true +num-traits.workspace = true palette.workspace = true palette.optional = true diff --git a/core/src/angle.rs b/core/src/angle.rs index 75a57c76..91fc2ba7 100644 --- a/core/src/angle.rs +++ b/core/src/angle.rs @@ -1,17 +1,56 @@ use crate::{Point, Rectangle, Vector}; + use std::f32::consts::PI; +use std::ops::RangeInclusive; -#[derive(Debug, Copy, Clone, PartialEq)] /// Degrees +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] pub struct Degrees(pub f32); -#[derive(Debug, Copy, Clone, PartialEq)] /// Radians +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] pub struct Radians(pub f32); +impl Radians { + /// The range of radians of a circle. + pub const RANGE: RangeInclusive = Radians(0.0)..=Radians(2.0 * PI); +} + impl From for Radians { fn from(degrees: Degrees) -> Self { - Radians(degrees.0 * PI / 180.0) + Self(degrees.0 * PI / 180.0) + } +} + +impl From for Radians { + fn from(radians: f32) -> Self { + Self(radians) + } +} + +impl From for Radians { + fn from(radians: u8) -> Self { + Self(f32::from(radians)) + } +} + +impl From for f64 { + fn from(radians: Radians) -> Self { + Self::from(radians.0) + } +} + +impl num_traits::FromPrimitive for Radians { + fn from_i64(n: i64) -> Option { + Some(Self(n as f32)) + } + + fn from_u64(n: u64) -> Option { + Some(Self(n as f32)) + } + + fn from_f64(n: f64) -> Option { + Some(Self(n as f32)) } } -- cgit From 90cbab18b95a2a90a6a527280a6ca461203ea1b3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 8 Sep 2023 02:36:17 +0200 Subject: Fine-tune `Radians::to_distance` An angle of 0 radians will "point" to the top-center of a `Rectangle` and then increase clockwise. --- core/src/angle.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/src/angle.rs b/core/src/angle.rs index 91fc2ba7..c8f3f013 100644 --- a/core/src/angle.rs +++ b/core/src/angle.rs @@ -1,6 +1,6 @@ use crate::{Point, Rectangle, Vector}; -use std::f32::consts::PI; +use std::f32::consts::{FRAC_PI_2, PI}; use std::ops::RangeInclusive; /// Degrees @@ -57,15 +57,16 @@ impl num_traits::FromPrimitive for Radians { impl Radians { /// Calculates the line in which the [`Angle`] intercepts the `bounds`. pub fn to_distance(&self, bounds: &Rectangle) -> (Point, Point) { - let v1 = Vector::new(f32::cos(self.0), f32::sin(self.0)); + let angle = self.0 - FRAC_PI_2; + let r = Vector::new(f32::cos(angle), f32::sin(angle)); - let distance_to_rect = f32::min( - f32::abs((bounds.y - bounds.center().y) / v1.y), - f32::abs(((bounds.x + bounds.width) - bounds.center().x) / v1.x), + let distance_to_rect = f32::max( + f32::abs(r.x * bounds.width / 2.0), + f32::abs(r.y * bounds.height / 2.0), ); - let start = bounds.center() + v1 * distance_to_rect; - let end = bounds.center() - v1 * distance_to_rect; + let start = bounds.center() - r * distance_to_rect; + let end = bounds.center() + r * distance_to_rect; (start, end) } -- cgit From 89d9f1d7d2202029028a487df1dd11b0665a7517 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Sat, 9 Sep 2023 12:24:47 +0200 Subject: Fix majority of unresolved documentation links --- core/src/angle.rs | 2 +- core/src/gradient.rs | 2 +- core/src/shell.rs | 4 ++-- core/src/window/icon.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/src/angle.rs b/core/src/angle.rs index c8f3f013..102b69cf 100644 --- a/core/src/angle.rs +++ b/core/src/angle.rs @@ -55,7 +55,7 @@ impl num_traits::FromPrimitive for Radians { } impl Radians { - /// Calculates the line in which the [`Angle`] intercepts the `bounds`. + /// Calculates the line in which the angle intercepts the `bounds`. pub fn to_distance(&self, bounds: &Rectangle) -> (Point, Point) { let angle = self.0 - FRAC_PI_2; let r = Vector::new(f32::cos(angle), f32::sin(angle)); diff --git a/core/src/gradient.rs b/core/src/gradient.rs index e19622fb..576c9e4d 100644 --- a/core/src/gradient.rs +++ b/core/src/gradient.rs @@ -9,7 +9,7 @@ use std::cmp::Ordering; /// /// For a gradient which can be used as a fill on a canvas, see [`iced_graphics::Gradient`]. pub enum Gradient { - /// A linear gradient interpolates colors along a direction at a specific [`Angle`]. + /// A linear gradient interpolates colors along a direction at a specific angle. Linear(Linear), } diff --git a/core/src/shell.rs b/core/src/shell.rs index 74a5c616..246c937a 100644 --- a/core/src/shell.rs +++ b/core/src/shell.rs @@ -35,7 +35,7 @@ impl<'a, Message> Shell<'a, Message> { self.messages.push(message); } - /// Requests a new frame to be drawn at the given [`Instant`]. + /// Requests a new frame to be drawn. pub fn request_redraw(&mut self, request: window::RedrawRequest) { match self.redraw_request { None => { @@ -48,7 +48,7 @@ impl<'a, Message> Shell<'a, Message> { } } - /// Returns the requested [`Instant`] a redraw should happen, if any. + /// Returns the request a redraw should happen, if any. pub fn redraw_request(&self) -> Option { self.redraw_request } diff --git a/core/src/window/icon.rs b/core/src/window/icon.rs index 31868ecf..2fc48e3b 100644 --- a/core/src/window/icon.rs +++ b/core/src/window/icon.rs @@ -49,7 +49,7 @@ impl Icon { } #[derive(Debug, thiserror::Error)] -/// An error produced when using [`Icon::from_rgba`] with invalid arguments. +/// An error produced when using [`from_rgba`] with invalid arguments. pub enum Error { /// Produced when the length of the `rgba` argument isn't divisible by 4, thus `rgba` can't be /// safely interpreted as 32bpp RGBA pixels. -- cgit From f60884f6f8639f75258c264bf4a15591351ef05b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 9 Sep 2023 20:58:45 +0200 Subject: Deny `broken_intradoc_links` and verify documentation in CI --- core/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/src/lib.rs b/core/src/lib.rs index c1c8424b..1bfba7bd 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -9,6 +9,7 @@ #![doc( html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg" )] +#![forbid(unsafe_code, rust_2018_idioms)] #![deny( missing_debug_implementations, missing_docs, @@ -17,9 +18,9 @@ clippy::from_over_into, clippy::needless_borrow, clippy::new_without_default, - clippy::useless_conversion + clippy::useless_conversion, + rustdoc::broken_intra_doc_links )] -#![forbid(unsafe_code, rust_2018_idioms)] #![allow(clippy::inherent_to_string, clippy::type_complexity)] pub mod alignment; pub mod clipboard; -- cgit From 419d9374b79b39293ba9a17967c2356d29377d8f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 9 Sep 2023 21:08:23 +0200 Subject: Fix outstanding broken intradoc links --- core/src/gradient.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'core') diff --git a/core/src/gradient.rs b/core/src/gradient.rs index 576c9e4d..4a0d5ea0 100644 --- a/core/src/gradient.rs +++ b/core/src/gradient.rs @@ -6,8 +6,6 @@ use std::cmp::Ordering; #[derive(Debug, Clone, Copy, PartialEq)] /// A fill which transitions colors progressively along a direction, either linearly, radially (TBD), /// or conically (TBD). -/// -/// For a gradient which can be used as a fill on a canvas, see [`iced_graphics::Gradient`]. pub enum Gradient { /// A linear gradient interpolates colors along a direction at a specific angle. Linear(Linear), -- cgit