taffy icon indicating copy to clipboard operation
taffy copied to clipboard

Container sizing oddness with `min_size` and `Dimesion::percent` on root and container

Open ThePuzzlemaker opened this issue 10 months ago • 1 comments

taffy version

v0.8.3

Platform

Rust

What you did

use taffy::{AvailableSpace, Dimension, Size, Style, TaffyTree};

fn main() {
    let mut tree = TaffyTree::<()>::new();

    let root = tree
        .new_leaf(Style {
            min_size: Size {
                width: Dimension::percent(1.0),
                height: Dimension::percent(1.0),
            },
            ..Style::default()
        })
        .unwrap();

    let container = tree
        .new_leaf(Style {
            min_size: Size {
                width: Dimension::percent(1.0),
                height: Dimension::percent(1.0),
            },
            ..Style::default()
        })
        .unwrap();
    tree.add_child(root, container).unwrap();

    let child = tree
        .new_leaf(Style {
            size: Size::from_lengths(500.0, 500.0),
            ..Style::default()
        })
        .unwrap();
    tree.add_child(container, child).unwrap();

    tree.compute_layout(
        root,
        Size {
            width: AvailableSpace::Definite(1000.0),
            height: AvailableSpace::Definite(1000.0),
        },
    )
    .unwrap();

    let layout = tree.layout(container).unwrap();
    println!("container size = {:?}", layout.size);

    let layout = tree.layout(root).unwrap();
    println!("root size = {:?}", layout.size);
}

What went wrong

It produces an invalid value for the container width:

container size = Size { width: 500.0, height: 1000.0 }
root size = Size { width: 1000.0, height: 1000.0 }

I instead expected the code to produce the correct value for container size (which should be 1000x1000, as min_size is set to 100% for both the container and the root; and the available size when computing layout is 1000x1000).

ThePuzzlemaker avatar Jun 14 '25 08:06 ThePuzzlemaker

Notably this does not occur when using size, however this should ideally still work correctly and this may manifest in different ways with non-100% percentages

ThePuzzlemaker avatar Jun 14 '25 08:06 ThePuzzlemaker