diff --git a/crates/components/src/network_image.rs b/crates/components/src/network_image.rs index 5f926e5af..3456f2eaa 100644 --- a/crates/components/src/network_image.rs +++ b/crates/components/src/network_image.rs @@ -33,7 +33,7 @@ pub struct NetworkImageProps { /// Information about the image. pub alt: Option, - pub aspect_ratio: Option + pub aspect_ratio: Option, } /// Image status. diff --git a/crates/core/src/elements/image.rs b/crates/core/src/elements/image.rs index aab4d628b..c93097579 100644 --- a/crates/core/src/elements/image.rs +++ b/crates/core/src/elements/image.rs @@ -1,7 +1,10 @@ use freya_engine::prelude::*; use freya_native_core::real_dom::NodeImmutable; use freya_node_state::{ - AspectRatio, ReferencesState, StyleState, TransformState + AspectRatio, + ReferencesState, + StyleState, + TransformState, }; use super::utils::ElementUtils; @@ -37,19 +40,19 @@ impl ElementUtils for ImageElement { let ratio = match node_transform.aspect_ratio { AspectRatio::Max => width_ratio.max(height_ratio), AspectRatio::Min => width_ratio.min(height_ratio), - AspectRatio::None => 1.0 + AspectRatio::None => 1.0, }; let width = pic.width() as f32 * ratio; let height = pic.height() as f32 * ratio; - let rect = Rect::new(area.min_x(), area.min_y() , area.min_x() + width, area.min_y() + height); - canvas.draw_image_rect( - pic, - None, - rect, - &paint + let rect = Rect::new( + area.min_x(), + area.min_y(), + area.min_x() + width, + area.min_y() + height, ); + canvas.draw_image_rect(pic, None, rect, &paint); } }; diff --git a/crates/hooks/src/use_animation.rs b/crates/hooks/src/use_animation.rs index f9e3f17eb..2f8906f70 100644 --- a/crates/hooks/src/use_animation.rs +++ b/crates/hooks/src/use_animation.rs @@ -779,12 +779,9 @@ pub fn use_animation( use_memo(move || { let context = context.read(); - if *has_run_yet.peek() - { + if *has_run_yet.peek() { match context.conf.on_deps_change { - OnDepsChange::Finish => { - animation.finish() - } + OnDepsChange::Finish => animation.finish(), OnDepsChange::Rerun => { let last_direction = *animation.last_direction.peek(); animation.run(last_direction); @@ -828,12 +825,9 @@ where use_memo(move || { let context = context.read(); - if *has_run_yet.peek() - { + if *has_run_yet.peek() { match context.conf.on_deps_change { - OnDepsChange::Finish => { - animation.finish() - } + OnDepsChange::Finish => animation.finish(), OnDepsChange::Rerun => { animation.run(*animation.last_direction.peek()); } diff --git a/crates/state/src/transform.rs b/crates/state/src/transform.rs index 531d028c3..cd83f9b1d 100644 --- a/crates/state/src/transform.rs +++ b/crates/state/src/transform.rs @@ -20,7 +20,11 @@ use freya_native_core::{ use freya_native_core_macro::partial_derive_state; use crate::{ - AspectRatio, CustomAttributeValues, Parse, ParseAttribute, ParseError + AspectRatio, + CustomAttributeValues, + Parse, + ParseAttribute, + ParseError, }; #[derive(Default, Clone, Debug, Component, PartialEq)] @@ -28,7 +32,7 @@ pub struct TransformState { pub node_id: NodeId, pub opacities: Vec, pub rotations: Vec<(NodeId, f32)>, - pub aspect_ratio: AspectRatio + pub aspect_ratio: AspectRatio, } impl ParseAttribute for TransformState { @@ -79,7 +83,7 @@ impl State for TransformState { NodeMaskBuilder::new().with_attrs(AttributeMaskBuilder::Some(&[ AttributeName::Rotate, AttributeName::Opacity, - AttributeName::AspectRatio + AttributeName::AspectRatio, ])); fn update<'a>( diff --git a/crates/state/src/values/aspect_ratio.rs b/crates/state/src/values/aspect_ratio.rs index 80db3bebb..3cfffec42 100644 --- a/crates/state/src/values/aspect_ratio.rs +++ b/crates/state/src/values/aspect_ratio.rs @@ -1,20 +1,23 @@ -use crate::{Parse, ParseError}; - -#[derive(Default, Clone, Debug, PartialEq)] -pub enum AspectRatio { - Min, - Max, - #[default] - None -} - -impl Parse for AspectRatio { - fn parse(value: &str) -> Result { - match value { - "min" => Ok(Self::Min), - "max" => Ok(Self::Max), - "none" => Ok(Self::None), - _ => Err(ParseError) - } - } -} \ No newline at end of file +use crate::{ + Parse, + ParseError, +}; + +#[derive(Default, Clone, Debug, PartialEq)] +pub enum AspectRatio { + Min, + Max, + #[default] + None, +} + +impl Parse for AspectRatio { + fn parse(value: &str) -> Result { + match value { + "min" => Ok(Self::Min), + "max" => Ok(Self::Max), + "none" => Ok(Self::None), + _ => Err(ParseError), + } + } +} diff --git a/crates/state/src/values/mod.rs b/crates/state/src/values/mod.rs index c2a2aa546..05d4b82a4 100644 --- a/crates/state/src/values/mod.rs +++ b/crates/state/src/values/mod.rs @@ -1,5 +1,6 @@ mod accessibility; mod alignment; +mod aspect_ratio; mod border; mod color; mod content; @@ -18,8 +19,8 @@ mod shadow; mod size; mod text_height; mod text_shadow; -mod aspect_ratio; +pub use aspect_ratio::*; pub use border::*; pub use color::*; pub use corner_radius::*; @@ -33,4 +34,3 @@ pub use overflow::*; pub use shadow::*; pub use size::*; pub use text_height::*; -pub use aspect_ratio::*; diff --git a/examples/images_slideshow.rs b/examples/images_slideshow.rs index 3e3d7616e..f1cb3e83d 100644 --- a/examples/images_slideshow.rs +++ b/examples/images_slideshow.rs @@ -15,12 +15,11 @@ fn Card(selected: ReadOnlySignal, children: Element) -> Element { let animations = use_animation(move |conf| { conf.on_deps_change(OnDepsChange::Rerun); conf.auto_start(true); - let (from, to) = if selected() { - (1.0, 3.0) - } else { - (3.0, 1.0) - }; - AnimNum::new(from, to).time(250).ease(Ease::Out).function(Function::Expo) + let (from, to) = if selected() { (1.0, 3.0) } else { (3.0, 1.0) }; + AnimNum::new(from, to) + .time(250) + .ease(Ease::Out) + .function(Function::Expo) }); let width = animations.get().read().read(); @@ -54,7 +53,7 @@ fn app() -> Element { spacing: "5", width: "100%", padding: "5", - + for (i, url) in [ "https://images.dog.ceo/breeds/dachshund/dachshund-2033796_640.jpg", "https://images.dog.ceo/breeds/cavapoo/doggo4.jpg",