diff options
author | 2023-08-15 17:05:46 +0800 | |
---|---|---|
committer | 2024-01-31 19:21:10 +0100 | |
commit | c077e107f2eea618ea644652707254a402527de3 (patch) | |
tree | dff9d70f26d834c2cc4f4b886bc81bc3d84a8e4d /examples/loading_spinners | |
parent | 8ed3490280a4dd8a1d4e3cd421b1785725f65865 (diff) | |
download | iced-c077e107f2eea618ea644652707254a402527de3.tar.gz iced-c077e107f2eea618ea644652707254a402527de3.tar.bz2 iced-c077e107f2eea618ea644652707254a402527de3.zip |
Use `Radians` in arc and ellipse types
Diffstat (limited to 'examples/loading_spinners')
-rw-r--r-- | examples/loading_spinners/src/circular.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/examples/loading_spinners/src/circular.rs b/examples/loading_spinners/src/circular.rs index 8598b20a..2f2172f3 100644 --- a/examples/loading_spinners/src/circular.rs +++ b/examples/loading_spinners/src/circular.rs @@ -8,6 +8,7 @@ use iced::mouse; use iced::time::Instant; use iced::widget::canvas; use iced::window::{self, RedrawRequest}; +use iced::Radians; use iced::{ Background, Color, Element, Event, Length, Rectangle, Renderer, Size, Vector, @@ -18,8 +19,8 @@ use super::easing::{self, Easing}; use std::f32::consts::PI; use std::time::Duration; -const MIN_RADIANS: f32 = PI / 8.0; -const WRAP_RADIANS: f32 = 2.0 * PI - PI / 4.0; +const MIN_ANGLE: Radians = Radians(PI / 8.0); +const WRAP_ANGLE: Radians = Radians(2.0 * PI - PI / 4.0); const BASE_ROTATION_SPEED: u32 = u32::MAX / 80; #[allow(missing_debug_implementations)] @@ -139,7 +140,7 @@ impl Animation { progress: 0.0, rotation: rotation.wrapping_add( BASE_ROTATION_SPEED.wrapping_add( - ((WRAP_RADIANS / (2.0 * PI)) * u32::MAX as f32) as u32, + ((WRAP_ANGLE.0 / (2.0 * PI)) * u32::MAX as f32) as u32, ), ), last: now, @@ -318,7 +319,7 @@ where let mut builder = canvas::path::Builder::new(); - let start = state.animation.rotation() * 2.0 * PI; + let start = iced::Radians(state.animation.rotation() * 2.0 * PI); match state.animation { Animation::Expanding { progress, .. } => { @@ -327,8 +328,8 @@ where radius: track_radius, start_angle: start, end_angle: start - + MIN_RADIANS - + WRAP_RADIANS * (self.easing.y_at_x(progress)), + + MIN_ANGLE + + WRAP_ANGLE * (self.easing.y_at_x(progress)), }); } Animation::Contracting { progress, .. } => { @@ -336,8 +337,8 @@ where center: frame.center(), radius: track_radius, start_angle: start - + WRAP_RADIANS * (self.easing.y_at_x(progress)), - end_angle: start + MIN_RADIANS + WRAP_RADIANS, + + WRAP_ANGLE * (self.easing.y_at_x(progress)), + end_angle: start + MIN_ANGLE + WRAP_ANGLE, }); } } |