Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jan 12, 2025
1 parent d101ed5 commit 5731974
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 51 deletions.
2 changes: 1 addition & 1 deletion crates/components/src/network_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct NetworkImageProps {
/// Information about the image.
pub alt: Option<String>,

pub aspect_ratio: Option<String>
pub aspect_ratio: Option<String>,
}

/// Image status.
Expand Down
19 changes: 11 additions & 8 deletions crates/core/src/elements/image.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
};

Expand Down
14 changes: 4 additions & 10 deletions crates/hooks/src/use_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,12 +779,9 @@ pub fn use_animation<Animated: AnimatedValue>(

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);
Expand Down Expand Up @@ -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());
}
Expand Down
10 changes: 7 additions & 3 deletions crates/state/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ 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)]
pub struct TransformState {
pub node_id: NodeId,
pub opacities: Vec<f32>,
pub rotations: Vec<(NodeId, f32)>,
pub aspect_ratio: AspectRatio
pub aspect_ratio: AspectRatio,
}

impl ParseAttribute for TransformState {
Expand Down Expand Up @@ -79,7 +83,7 @@ impl State<CustomAttributeValues> for TransformState {
NodeMaskBuilder::new().with_attrs(AttributeMaskBuilder::Some(&[
AttributeName::Rotate,
AttributeName::Opacity,
AttributeName::AspectRatio
AttributeName::AspectRatio,
]));

fn update<'a>(
Expand Down
43 changes: 23 additions & 20 deletions crates/state/src/values/aspect_ratio.rs
Original file line number Diff line number Diff line change
@@ -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<Self, ParseError> {
match value {
"min" => Ok(Self::Min),
"max" => Ok(Self::Max),
"none" => Ok(Self::None),
_ => Err(ParseError)
}
}
}
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<Self, ParseError> {
match value {
"min" => Ok(Self::Min),
"max" => Ok(Self::Max),
"none" => Ok(Self::None),
_ => Err(ParseError),
}
}
}
4 changes: 2 additions & 2 deletions crates/state/src/values/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod accessibility;
mod alignment;
mod aspect_ratio;
mod border;
mod color;
mod content;
Expand All @@ -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::*;
Expand All @@ -33,4 +34,3 @@ pub use overflow::*;
pub use shadow::*;
pub use size::*;
pub use text_height::*;
pub use aspect_ratio::*;
13 changes: 6 additions & 7 deletions examples/images_slideshow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ fn Card(selected: ReadOnlySignal<bool>, 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();
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 5731974

Please sign in to comment.