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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//! Example demonstrating the transform system with rotation, scale, and animation.
//!
//! This example shows:
//! - Static transforms (rotate, scale)
//! - Reactive transforms that change based on signals
//! - Animated transforms with spring physics
//! - Nested transforms (parent-child composition)
//! - Custom transform origins (pivot points for rotation/scale)
use guido::prelude::*;
fn main() {
App::new().run(|app| {
// Signals for interactive transforms
let rotation = create_signal(0.0f32);
let scale_factor = create_signal(1.0f32);
let is_scaled = create_signal(false);
// Run the app with taller height to see transforms
app.add_surface(
SurfaceConfig::new()
.height(120)
.anchor(Anchor::TOP | Anchor::LEFT | Anchor::RIGHT)
.background_color(Color::rgb(0.1, 0.1, 0.15)),
move || {
container()
.layout(Flex::row().spacing(20.0).center())
.padding(16.0)
.children([
// 1. Static rotation (45 degrees)
container()
.width(60.0)
.height(60.0)
.background(Color::rgb(0.8, 0.3, 0.3))
.corners(8.0)
.rotate(45.0)
.child(
container()
.layout(Flex::column().center())
.child(text("45").font_size(12.0).color(Color::WHITE)),
),
// 2. Click to rotate (increments by 45 degrees)
container()
.width(60.0)
.height(60.0)
.background(Color::rgb(0.3, 0.6, 0.8))
.corners(8.0)
.rotate(
(move || rotation.get())
.transition(Transition::new(300.0, TimingFunction::EaseOut)),
)
.when_hovered(|s| s.lighter(0.1))
.when_pressed(|s| s.ripple())
.on_click(move || {
rotation.update(|r| *r += 45.0);
})
.child(
container().layout(Flex::column().center()).child(
text("Click").font_size(10.0).color(Color::WHITE).nowrap(),
),
),
// 3. Click to toggle scale with spring animation
container()
.width(60.0)
.height(60.0)
.background(Color::rgb(0.3, 0.8, 0.4))
.corners(8.0)
.scale(
(move || scale_factor.get())
.transition(Transition::spring(SpringConfig::BOUNCY)),
)
.when_hovered(|s| s.lighter(0.1))
.when_pressed(|s| s.ripple())
.on_click(move || {
is_scaled.update(|s| *s = !*s);
let target = if is_scaled.get() { 1.3 } else { 1.0 };
scale_factor.set(target);
})
.child(
container().layout(Flex::column().center()).child(
text("Scale").font_size(10.0).color(Color::WHITE).nowrap(),
),
),
// 4. Static scale (smaller)
container()
.width(60.0)
.height(60.0)
.background(Color::rgb(0.6, 0.4, 0.8))
.corners(8.0)
.scale(0.7)
.child(
container()
.layout(Flex::column().center())
.child(text("0.7x").font_size(12.0).color(Color::WHITE)),
),
// 5. Combined rotation + scale
container()
.width(60.0)
.height(60.0)
.background(Color::rgb(0.8, 0.6, 0.2))
.corners(8.0)
.rotate(30.0)
.scale(0.8)
.child(
container().layout(Flex::column().center()).child(
text("Both").font_size(10.0).color(Color::WHITE).nowrap(),
),
),
// 6. Rotation around top-left corner (transform origin)
container()
.width(60.0)
.height(60.0)
.background(Color::rgb(0.8, 0.5, 0.7))
.corners(8.0)
.rotate(45.0)
.pivot(Pivot::TOP_LEFT)
.child(
container()
.layout(Flex::column().center())
.child(text("TL").font_size(12.0).color(Color::WHITE)),
),
// 7. Scale from bottom-right corner (transform origin)
container()
.width(60.0)
.height(60.0)
.background(Color::rgb(0.5, 0.7, 0.8))
.corners(8.0)
.scale(0.8)
.pivot(Pivot::BOTTOM_RIGHT)
.child(
container()
.layout(Flex::column().center())
.child(text("BR").font_size(12.0).color(Color::WHITE)),
),
// 8. Interactive: click to cycle through origins
{
let origin_index = create_signal(0usize);
container()
.width(60.0)
.height(60.0)
.background(Color::rgb(0.7, 0.8, 0.5))
.corners(8.0)
.rotate(30.0)
.pivot(move || match origin_index.get() % 5 {
0 => Pivot::CENTER,
1 => Pivot::TOP_LEFT,
2 => Pivot::TOP_RIGHT,
3 => Pivot::BOTTOM_LEFT,
_ => Pivot::BOTTOM_RIGHT,
})
.when_hovered(|s| s.lighter(0.1))
.when_pressed(|s| s.ripple())
.on_click(move || origin_index.update(|i| *i += 1))
.child(container().layout(Flex::column().center()).child(
text("Cycle").font_size(10.0).color(Color::WHITE).nowrap(),
))
},
])
},
);
});
}