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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//! Test example for pivot with shapes only (no text).
//!
//! This helps isolate pivot behavior from text rendering issues.
use guido::prelude::*;
use std::time::Duration;
#[tokio::main]
async fn main() {
App::new().run(|app| {
let angle = create_signal(0.0_f32);
// Animation service - updates the angle signal continuously
let start_time = std::time::Instant::now();
let angle_w = angle.writer();
create_task(move |ctx| async move {
while ctx.is_running() {
let elapsed = start_time.elapsed().as_secs_f32();
let new_angle = (elapsed * 45.0) % 360.0; // 45 degrees per second
angle_w.set(new_angle);
tokio::time::sleep(Duration::from_millis(16)).await;
}
});
app.add_surface(
SurfaceConfig::new()
.width(900)
.height(550)
.anchor(Anchor::TOP | Anchor::LEFT)
.background_color(Color::rgb(0.1, 0.1, 0.15)),
move || {
container()
.layout(Flex::column().spacing(40.0).center())
.padding(40.0)
.children([
// Row 1: Different origins with same rotation
container()
.layout(Flex::row().spacing(80.0).center())
.children([
// Default origin (center)
container()
.width(100.0)
.height(80.0)
.background(Color::rgba(0.3, 0.5, 0.8, 0.8))
.corners(8.0)
.rotate(20.0),
// Top-left origin
container()
.width(100.0)
.height(80.0)
.background(Color::rgba(0.8, 0.5, 0.3, 0.8))
.corners(8.0)
.pivot(Pivot::TOP_LEFT)
.rotate(20.0),
// Top-right origin
container()
.width(100.0)
.height(80.0)
.background(Color::rgba(0.5, 0.8, 0.3, 0.8))
.corners(8.0)
.pivot(Pivot::TOP_RIGHT)
.rotate(20.0),
// Bottom-left origin
container()
.width(100.0)
.height(80.0)
.background(Color::rgba(0.8, 0.3, 0.8, 0.8))
.corners(8.0)
.pivot(Pivot::BOTTOM_LEFT)
.rotate(20.0),
// Bottom-right origin
container()
.width(100.0)
.height(80.0)
.background(Color::rgba(0.3, 0.8, 0.8, 0.8))
.corners(8.0)
.pivot(Pivot::BOTTOM_RIGHT)
.rotate(20.0),
]),
// Row 2: Scale with different origins
container()
.layout(Flex::row().spacing(80.0).center())
.children([
// Default origin (center) - scale
container()
.width(80.0)
.height(60.0)
.background(Color::rgba(0.6, 0.3, 0.3, 0.8))
.corners(6.0)
.scale(1.3),
// Top-left origin - scale
container()
.width(80.0)
.height(60.0)
.background(Color::rgba(0.3, 0.6, 0.3, 0.8))
.corners(6.0)
.pivot(Pivot::TOP_LEFT)
.scale(1.3),
// Bottom-right origin - scale
container()
.width(80.0)
.height(60.0)
.background(Color::rgba(0.3, 0.3, 0.6, 0.8))
.corners(6.0)
.pivot(Pivot::BOTTOM_RIGHT)
.scale(1.3),
]),
// Row 3: Animated rotation with different origins
container()
.layout(Flex::row().spacing(80.0).center())
.children([
// Center origin - animated
container()
.width(80.0)
.height(60.0)
.background(Color::rgba(0.7, 0.5, 0.2, 0.8))
.corners(6.0)
.rotate(move || angle.get()),
// Top-left origin - animated
container()
.width(80.0)
.height(60.0)
.background(Color::rgba(0.2, 0.5, 0.7, 0.8))
.corners(6.0)
.pivot(Pivot::TOP_LEFT)
.rotate(move || angle.get()),
// Custom origin (25%, 75%) - animated
container()
.width(80.0)
.height(60.0)
.background(Color::rgba(0.5, 0.7, 0.2, 0.8))
.corners(6.0)
.pivot(Pivot::percent(25.0, 75.0))
.rotate(move || angle.get()),
]),
// Row 4: Nested containers with different origins
container()
.layout(Flex::row().spacing(80.0).center())
.children([
// Parent rotated at center, child inside
container()
.width(120.0)
.height(100.0)
.background(Color::rgba(0.4, 0.4, 0.6, 0.5))
.corners(10.0)
.layout(Flex::column().center())
.rotate(15.0)
.child(
container()
.width(60.0)
.height(40.0)
.background(Color::rgba(0.6, 0.6, 0.8, 0.9))
.corners(4.0),
),
// Parent rotated at top-left, child inside
container()
.width(120.0)
.height(100.0)
.background(Color::rgba(0.6, 0.4, 0.4, 0.5))
.corners(10.0)
.layout(Flex::column().center())
.pivot(Pivot::TOP_LEFT)
.rotate(15.0)
.child(
container()
.width(60.0)
.height(40.0)
.background(Color::rgba(0.8, 0.6, 0.6, 0.9))
.corners(4.0),
),
]),
])
},
);
});
}