@@ -63,6 +63,7 @@ pub struct Image<Handle = image::Handle> {
63
63
filter_method : FilterMethod ,
64
64
rotation : Rotation ,
65
65
opacity : f32 ,
66
+ scale : f32 ,
66
67
}
67
68
68
69
impl < Handle > Image < Handle > {
@@ -76,6 +77,7 @@ impl<Handle> Image<Handle> {
76
77
filter_method : FilterMethod :: default ( ) ,
77
78
rotation : Rotation :: default ( ) ,
78
79
opacity : 1.0 ,
80
+ scale : 1.0 ,
79
81
}
80
82
}
81
83
@@ -119,6 +121,15 @@ impl<Handle> Image<Handle> {
119
121
self . opacity = opacity. into ( ) ;
120
122
self
121
123
}
124
+
125
+ /// Sets the scale of the [`Image`].
126
+ ///
127
+ /// The region of the [`Image`] drawn will be scaled from the center by the given scale factor.
128
+ /// This can be useful to create certain effects and animations, like smooth zoom in / out.
129
+ pub fn scale ( mut self , scale : impl Into < f32 > ) -> Self {
130
+ self . scale = scale. into ( ) ;
131
+ self
132
+ }
122
133
}
123
134
124
135
/// Computes the layout of an [`Image`].
@@ -173,6 +184,7 @@ pub fn draw<Renderer, Handle>(
173
184
filter_method : FilterMethod ,
174
185
rotation : Rotation ,
175
186
opacity : f32 ,
187
+ scale : f32 ,
176
188
) where
177
189
Renderer : image:: Renderer < Handle = Handle > ,
178
190
Handle : Clone ,
@@ -184,12 +196,12 @@ pub fn draw<Renderer, Handle>(
184
196
let bounds = layout. bounds ( ) ;
185
197
let adjusted_fit = content_fit. fit ( rotated_size, bounds. size ( ) ) ;
186
198
187
- let scale = Vector :: new (
199
+ let fit_scale = Vector :: new (
188
200
adjusted_fit. width / rotated_size. width ,
189
201
adjusted_fit. height / rotated_size. height ,
190
202
) ;
191
203
192
- let final_size = image_size * scale;
204
+ let final_size = image_size * fit_scale * scale;
193
205
194
206
let position = match content_fit {
195
207
ContentFit :: None => Point :: new (
@@ -276,6 +288,7 @@ where
276
288
self . filter_method ,
277
289
self . rotation ,
278
290
self . opacity ,
291
+ self . scale ,
279
292
) ;
280
293
}
281
294
}
0 commit comments