简体   繁体   English

流布局面板的算法?

[英]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.在 Gui's 中有 Flow Layout Panels,它可以将面板的内容调整为一个很好的贴合度和很好的间距。 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).现在,您可以按行对齐小部件(以面板为中心,或在基线上对齐等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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