linebender / xilem

An experimental Rust native UI framework
Apache License 2.0
3.5k stars 108 forks source link

Masonry: Reason about `Image` widget layout implementation #574

Open DJMcNab opened 1 week ago

DJMcNab commented 1 week ago

This is the issue from the TODO comment at: https://github.com/linebender/xilem/blob/7be4dd2a2f8bf820fc19a3af2a00600d05e4d4c7/masonry/src/widget/image.rs#L94-L97

In particular, the current layout logic entirely ignores the FillStrat. Effectively, the aspect-ratio is always auto, so the only troublesome case is if we have a minimum/maximum set which never matches the given aspect ratio.

This logic has recently (#571) been changed from the original Druid version.

The steps for this issue are: 1) Work out the correct layout logic. It might be that the current version is correct, at least whilst we can't set aspect-ratio. 2) Write a few test cases for the layout logic, and integrate them into the tests module. These could probably use screenshot tests. 3) Remove the original TODO comment.

DJMcNab commented 1 week ago

See also the CSS images model.

FillStrat could also probably be renamed. It most closely matches object-fit web property, with a couple of extra variants. I don't think the current name accurately describes what is being covered - the "image size" as compared to the layout size aren't really meaningfully different except in very rare cases (primarily because of use of sized_box). Alternatively, it could be removed entirely, to be brought back when we implement more of the CSS images model.