question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FlowLayoutAlgorithm.Generate() should take into account the spacing after the current element

See original GitHub issue

Currently, FlowLayoutAlgorithm considers that there is enough space for the current item if it fits:

https://github.com/microsoft/microsoft-ui-xaml/blob/1ced221991d3abd51875d24d69221afa878b6c5a/dev/Repeater/FlowLayoutAlgorithm.cpp#L324 However, it doesn’t add minItemSpacing for that current item.

This is a problem because UniformGridLayout computes the number of items per line with the assumption that they all include that spacing:

https://github.com/microsoft/microsoft-ui-xaml/blob/1ced221991d3abd51875d24d69221afa878b6c5a/dev/Repeater/UniformGridLayout.cpp#L142

So, we can have a weird visual bug in the following scenario.

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Create an ItemsRepeater with: Layout = UniformGridLayout { Orientation = Orientation.Vertical, MinItemWidth = 100, MinItemHeight = 40, MinRowSpacing = 10, MinColumnSpacing = 10 };
  2. Resize the window.Height to be exactly 490
  3. Scroll forward until the first line is no longer visible.
  4. You should obtain something similar to this:

image

In this example, the FlowLayoutAlgorithm allows the item “♯9” to be in the first line because:

double remainingSpace = Minor(availableSize) - (MinorStart(previousElementBounds) + MinorSize(previousElementBounds) + minItemSpacing + Minor(desiredSize));
// 0 = 490 - (450 + 40 + 10 + 40);

Which means that it generates 10 lines.

However, UniformGridLayout computes 9 lines:

const int itemsPerLine = Minor(availableSize) / GetMinorSizeWithSpacing(context));
// 9 = 490 / (40 + 10)

Expected behavior

If we change remainingSpace to substract an additional minItemSpacing, then there will only be 9 lines and the weird bug will not occur:

image

If we want to allow 10 lines in this scenario, UniformGridLayout needs to be update everywhere in how it computes the number of items per line…

Update: This bug seems to only occur when Orientation == Vertical. And the suggested fix should only be applied in that case (otherwise, it causes the bug to occur when Horizontal).

Version Info Master branch on GitHub (as of the creation of this issue).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
KPixelcommented, Jul 5, 2020

I’ve created issue #2834 for the new bug.

Regarding this issue, do you see value in where I thought the bug was? (The difference between how FlowLayoutAlgorithm computes the items in a line and how UniformGridLayout computes the number of items per line). It seemed to make sense that if the spacing is large enough, the discrepancy between these two algos could cause glitches… But maybe I’m missing something.

1reaction
KPixelcommented, Jul 2, 2020

@chingucoding I will try to put together a sample app later today.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use FlowLayout
The FlowLayout class puts components in a row, sized at their preferred size. If the horizontal space in the container is too small...
Read more >
java - I Need To Know How To Add Space In A FlowLayout
By default a the content pane of the frame uses a BorderLayout. Check our the BorderLayout API. You can specify the gap size...
Read more >
NSCollectionViewFlowLayout
The flow layout builds its grid dynamically, using the item size and spacing information to place items sequentially into rows (for a vertically...
Read more >
How can I extend FlowLayout so components are sized to ...
I'm writing a GUI in Java using Swing. FlowLayout sizes objects to their preferred sizes. If the width of the container is exceeded,...
Read more >
Flow Layout Alignment - Swift Talk - objc.io
Once the current line is full, we have to position the line relative to the previous one, taking into account that the line's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found