Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use crate::Tweenable;
use bevy_color::{Color, ColorToComponents};
use bevy_derive::{Deref, DerefMut};
use bevy_math::curve::CurveExt;
use bevy_math::curve::Ease;
use bevy_math::{Curve, Vec3, Vec4};
use bevy_sprite::Sprite;
use bevy_text::TextColor;
use bevy_transform::components::Transform;
use bevy_ui::widget::ImageNode;
#[derive(Deref, DerefMut, Clone)]
#[repr(transparent)]
pub struct TweenableColour(pub Color);
impl From<Color> for TweenableColour {
fn from(value: Color) -> Self {
Self(value)
}
}
impl Ease for TweenableColour {
fn interpolating_curve_unbounded(start: Self, end: Self) -> impl Curve<Self> {
let start = start.to_srgba().to_vec4();
let end = end.to_srgba().to_vec4();
<Vec4 as Ease>::interpolating_curve_unbounded(start, end).map(|components| {
TweenableColour::from(Color::srgba(
components.x,
components.y,
components.z,
components.w,
))
})
}
}
pub struct TweenSpriteColour;
impl Tweenable for TweenSpriteColour {
type Comp = Sprite;
type Data = TweenableColour;
fn current_value(cmp: &Self::Comp) -> Self::Data {
cmp.color.into()
}
fn update_component(cmp: &mut Self::Comp, value: Self::Data) {
cmp.color = *value;
}
}
pub struct TweenImageNodeColour;
impl Tweenable for TweenImageNodeColour {
type Comp = ImageNode;
type Data = TweenableColour;
fn current_value(cmp: &Self::Comp) -> Self::Data {
cmp.color.into()
}
fn update_component(cmp: &mut Self::Comp, value: Self::Data) {
cmp.color = *value;
}
}
pub struct TweenTextColour;
impl Tweenable for TweenTextColour {
type Comp = TextColor;
type Data = TweenableColour;
fn current_value(cmp: &Self::Comp) -> Self::Data {
cmp.0.into()
}
fn update_component(cmp: &mut Self::Comp, value: Self::Data) {
cmp.0 = *value;
}
}
pub struct TweenTransformTranslation;
impl Tweenable for TweenTransformTranslation {
type Comp = Transform;
type Data = Vec3;
fn current_value(cmp: &Self::Comp) -> Self::Data {
cmp.translation
}
fn update_component(cmp: &mut Self::Comp, value: Self::Data) {
cmp.translation = value;
}
}
pub struct TweenTransformScale;
impl Tweenable for TweenTransformScale {
type Comp = Transform;
type Data = Vec3;
fn current_value(cmp: &Self::Comp) -> Self::Data {
cmp.scale
}
fn update_component(cmp: &mut Self::Comp, value: Self::Data) {
cmp.scale = value;
}
}