简体   繁体   中英

Algorithm for Flow Layout Panels?

In Gui's there are Flow Layout Panels which size the contents of the panel to a nice snug fit with nice spacing. Given arbitrary sized rectangles, and a container rectangle, what algorithm could be used to make all the widgets fit snug?

Thanks

There are lots of different layouting algorithms out there. Most of them are pretty simple, which is a good thing, because the complex ones often behave "strange".

Flow layouts like the one in your image usually align all widgets in one row horizontally.

Then, starting from the first widget, the widths of the widgets is summarized (including the spaces), and as soon as the widgets summarized width is larger then the panels width, a next row is started.

So you get rows of widgets and the widgets in each row will fit into your panel.

The widgets with the largest height in a row defines the height of this row.

Now you can align the widgets on a per-row basis (centered in panel, or align on a base-line and so on).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM