grid layouts

93 views
Skip to first unread message

John Asmuth

unread,
May 11, 2012, 10:18:04 AM5/11/12
to go-...@googlegroups.com
Been working on a grid layout similar to java's GridBagLayout, and (surprise surprise) it's totally non-trivial!

I'd like some help figuring out the best way to do it. The basic problem is:

Given a set of widgets with
 - known min, max and preferred sizes, 
 - their desired (x, y) positions, 
 - the number of rows an columns each widget wants to take, and
 - a fixed size to put everything in,
figure out the x positions of the beginning of each column, and the y positions of the beginning of each row.

This will allow us to set the bounding box of each widget.

Also important to be able to report a min, max and preferred size to the parent container, but first things first.

Right now uik/layouts.Grid will look at the widgets preferred size and (x, y) position (ignoring multiple col/row issues), and compact everything towards the top-left as much as possible while respecting the criteria.

I'm not sure of the best way to handle how much goes in each column or row when a widget spans multiples, or how to nicely give extra room in a col or row when the grid is larger than the "preferred" size.

Help?

Kyle Lemons

unread,
May 11, 2012, 11:09:04 PM5/11/12
to go-...@googlegroups.com
I highly recommend the approach taken by the new CSS flexible box model.  In particular, set everything to its preferred size, and then repeatedly allocate free space, freezing items that hit their min or max size.  You could do similar things with GridBag, though I think flexible box is much nicer and easier to reason about :)
Reply all
Reply to author
Forward
0 new messages