gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 227Rust 7TOML 3CSS 1307 Sutichaykuna

⎇ 0.4.x examples/common/image.rs Rust · 18 siq'ikuna · 699 B Ñawpa willay Pi imata llamkarqan ch'uya

Refactor `LayoutTree` + add examples of custom trees (#564) d4374b93f · Nico Burns ·

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}