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

Layout incorrect when parent container max size is set but size is auto #884

@rossleonardy

Description

@rossleonardy

taffy version

Tested on 0.9.1

Platform

Testing examples from the taffy repo on OS X

What you did

I adjusted the measure example as follows

To test a grid container with max width set, but width set to auto:

    let root = taffy.new_with_children(
        Style {
            display: Display::Grid,
            grid_template_rows: vec![fr(1.0)],
            max_size: Size { width: length(200.), height: auto() },
            size: Size { width: auto(), height: auto() },
            ..Default::default()
        },
        &[text_node, text_node],
    )?;

To test a flex container with max width set, but width set to auto:

    let root = taffy.new_with_children(
        Style {
            display: Display::Grid,
            grid_template_rows: vec![fr(1.0)],
            max_size: Size { width: length(200.), height: auto() },
            size: Size { width: auto(), height: auto() },
            ..Default::default()
        },
        &[text_node, text_node],
    )?;

What went wrong

Both grid layout and flex layout seemed to behave incorrectly when max-width is set, but width is unset on the parent container.

  1. Grid layout seems to ignore the constraint and give the children 100% of the space as if max size.width is unset:
Image
  1. Flex layout seems to give children the correct width, but incorrectly uses the results of the measure function and gives the wrong height:
Image

Both of these layouts work as expected in html on google chrome

Additional information

Looked into this because of #21769 bevyengine/bevy#21769 reported to bevy

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