⎇ dde8c6aa4a2faa6faea600e24ecf2ce67923c37e
examples/common/image.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Refactor `LayoutTree` + add examples of custom trees (#564)
1use taffy::geometry::Size;
2
3pub struct ImageContext {
4 pub width: f32,
5 pub height: f32,
6}
7
8pub fn image_measure_function(
9 known_dimensions: taffy::geometry::Size<Option<f32>>,
10 image_context: &ImageContext,
11) -> taffy::geometry::Size<f32> {
12 match (known_dimensions.width, known_dimensions.height) {
13 (Some(width), Some(height)) => Size { width, height },
14 (Some(width), None) => Size { width, height: (width / image_context.width) * image_context.height },
15 (None, Some(height)) => Size { width: (height / image_context.height) * image_context.width, height },
16 (None, None) => Size { width: image_context.width, height: image_context.height },
17 }
18}