I want to implement a flow layout in a given graphical toolkit and I am having some problems doing it.
I have a given rect - that I will henceforth refer to as container - whose sides have an aspect ratio of 1:n or n:1 (width/height rounded down to an integer). n is always a multiple of 1 so valid values may be 1:4, 3:1, 7:1 etc. but never something like 3:4. I have a number of squares - which I will refer to as elements - that need to be laid out on the container. I can freely resize the elements as long as I always adhere to the following constraints:
* The elements or even parts of them never go beyond the bounds of the container
* The elements do not overlap each other
* The elements always have the same size
Now, my question is ... with x elements and a given aspect ratio of n:1, how many rows and columns are needed to accommodate these elements? And of course how the formula looks like
Here are a few examples:
Aspect ratio | elements | rows | col |
--------------------------------------------
1:1 | 4 | 2 | 2 |
2:1 | 4 | 2 | 1 | though only one rows is used
1:2 | 6 | 4 | 2 | two indexes remain vacant
1:1 | 8 | 3 | 3 | one index remains vacant
3:1 | 7 | 6 | 2 |
1:3 | 12 | 2 | 6 |
I hope you get what I mean. It's not that easy to verbalize.
Thanks in advance
momesana



