serenity icon indicating copy to clipboard operation
serenity copied to clipboard

LibWeb: Use LayoutMode::IntrinsicSizing for sizing of grid children

Open laudenberg opened this issue 2 years ago • 2 comments

We used LayoutMode::Normal for sizing grid children which resulted in outer block level elements have zero height although their children were sized correctly. By using LayoutMode::IntrinsicSizing this is fixed and the footer of our GitHub page is now at its place.

Screenshot_20221017_181805 Screenshot_20221017_181813

laudenberg avatar Oct 17 '22 16:10 laudenberg

Hello!

One or more of the commit messages in this PR do not match the SerenityOS code submission policy, please check the lint_commits CI job for more details on which commits were flagged and why. Please do not close this PR and open another, instead modify your commit message(s) with git commit --amend and force push those changes to update this PR.

BuggieBot avatar Oct 17 '22 16:10 BuggieBot

The purpose of LayoutMode::IntrinsicSizing (which is our implementation of the intrinsic sizing concept from CSS-SIZING) is to determine one of the four intrinsic sizes (min-content width, max-content width, min-content height or max-content height) for a given box.

It's not correct to use LayoutMode::IntrinsicSizing like this. To get the intrinsic sizes of a box, use the APIs on FormattingContext:

  • calculate_min_content_width()
  • calculate_max_content_width()
  • calculate_min_content_height()
  • calculate_max_content_height()

They will set up the appropriate constraints before performing layout with LayoutMode::IntrinsicSizing. See for example FlexFormattingContext which uses these concepts extensively.

awesomekling avatar Oct 17 '22 16:10 awesomekling

@awesomekling Thanks a lot for this insight! I'm sorry I have not given the PR enough thought. My amendment now uses calculate_min_content_height() to determine the minimum contribution. This still looks only less wrong to me as the whole layout_inner() section feels a little ad-hoc. If this is too hacky to get merged it may at least serve someone with a better understanding of the grid algo (@martinfalisse) for an idea for a quick fix :^) For what it's worth it also makes the grid boxes at https://linus.dev look a little nicer:

Screenshot_20221017_205643

laudenberg avatar Oct 17 '22 19:10 laudenberg

Yeah this is obviously ad-hoc, but since it produces a much better layout than before, let's do it until we have something better :)

awesomekling avatar Oct 18 '22 10:10 awesomekling