The main issue for me here is that it is not clearly defined what layout->rows and layout->flow_columns
are. Are they the number of rows/columns used by actual elements, or the number of visible rows/columns?
I assume, this very old XXX comment referred to the modulo in ED_fileselect_layout_tilepos.
This code was introduced in https://developer.blender.org/rB403b3763a8048f88f8f589167c1f70b876999795#change-ShDQCqWFZyae.