这是indexloc提供的服务,不要输入任何密码
Skip to content

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

@ThePuzzlemaker

Description

@ThePuzzlemaker

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions