@thor Then you just add a row whenever you hit a square number, but you'll need to have an exception for 3 attachments if you want to keep Mastodon's default behavior.
@thor After that, you check if the number of attachments is dividable by the row number: if it is, then you'll equally split the attachments between the rows, you divide number_attachments/number_rows to get how many; if it isn't, then you have one row that has rounded_down(number_attachments/number_rows), and the rest are rounded_up(number_attachments/number_rows).
@thor
After that, you check if the number of attachments is dividable by the row number:
if it is, then you'll equally split the attachments between the rows, you divide number_attachments/number_rows to get how many;
if it isn't, then you have one row that has rounded_down(number_attachments/number_rows), and the rest are rounded_up(number_attachments/number_rows).