Skip to content

Growing element with flex-grow: 1 breaks layouting of other items #658

Closed
@ShawnCZek

Description

@ShawnCZek

Hi,

This issue originates from our discussion regarding the complexity of large data sets: #653.

I noticed a bug with flexbox layouting in RmlUi in one of our documents. When one of the elements may grow and only that element specifies the flex property with the value of auto (or sets flex-grow to 1), the layouting yields unexpected results.

I am using the latest version of the library, 5.1. This problem is also reproducible on master.

Reproduction

I have created a separate branch with a sample. This was mainly designed to showcase the performance issues investigated in the discussion linked above, but it can also be used for this case: https://github.com/ShawnCZek/RmlUi/tree/sample_player_list.

The biggest culprits are the following styles:

#contents {
    display: flex;
    flex-direction: column;
}

#players {
    flex: auto;
}

Expected Result

The linked branch contains an HTML sample, too. The styling is not 1:1 due to differences within browsers, but RmlUi should show a similar result to Mozilla Firefox/Google Chrome. I am attaching such a comparison:

Comparison of the player list sample between RmlUi and Firefox

The input is overflowing, and the margin between the top text and the player list table is off.

Workarounds

There are possible workarounds that might help investigate this case.

Workaround n.1

If one of the other items sets a minimum height (or width for the row direction), it no longer stretches so unexpectedly:

#contents > div:first-child {
    min-height: 30dp;
}

This minimum size must be set directly for the item. If it is a property of its child(ren), the output is broken once again.

Workaround n.2

Other elements set the flex property:

#contents > div:first-child, #contents > div:last-child {
    flex: 1;
}

Elements no longer move up and down. However, the margin is ignored, and the last element completely overflows the body.

Metadata

Metadata

Assignees

No one assigned

    Labels

    layoutLayout engine issues and enhancements

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions