tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

⎇ main examples/cosmic_text/src/image.rs Rust · 18 lines · 699 B History Who touched what raw

Move cosmic-text example to it's own crate (#754) 1ad9fc113 · 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}