[Y-devel] Widget size negotiation

Mark Thomas mark at www.y-windows.org
Wed Feb 25 22:36:00 GMT 2004


Jason Cwik wrote:
> For those of you who are working on size negotiation/layouts, you might
> want to peruse how Java does it.

There are two schools of thought on automatic widget layout (as far as I 
can tell), and Y uses the same as Qt and GTK+ (which is different from 
how Java does it).  They are both essentially equivalent though.

I do mention how layouts work in the project report, but it is a 
confusing subject and is hard to explain, simply because of the number 
of ifs, buts, maybes and howevers.

Widgets specify their minimum, preferred and maximum sizes.  The maximum 
size is the size the widget can most make use of before it's just 
padding itself.  A widget should be able to cope with being any size 
(including 0x0), though if it is less than its minimum size it is ok for 
it to not be able to show all data (labels should add elipses [...], etc.)

Layout widgets derive their minimum, preferred and maximum sizes from 
their children.  If they have no children then these sizes are all 0.

Now, there are three situations when we need to configure a tree of widgets:

   1) upon creation
      solution is to use the preferred size of all widgets
   2) upon resizing of the top-most widget of a tree
      control proceeds down the tree; at each level, the layout assigns
      each widget its preferred size.  If the total size is greater than
      the space it has, then it reduces widget sizes proportionally until
      they reach their minima.  If the total size is less than the
      available space, then it increases them in whatever way it chooses
      (either preferring those with larger maxima, or using a stretch
      value).
   3) upon changing the minimum, preferred or maximum size of a
      child widget:
      control proceeds *up* the tree, with each widget requesting a
      reconfigure from its parents.  On the way up, each widget
      recalculates its min, pref and max sizes based on the new
      value.  When the top of the tree is reached, control proceeds
      back down the tree as in  part (2)

Some widgets, e.g. desktops, do not care about the size of their 
children when calculating their own size.  They should "sever" this 
propogation when it gets to them, making their children effectively
tops of their own little trees.

This should be how it is implemented in the current implementation.
I believe it behaves like GTK+ and Qt.

Regards,

   Mark.
-- 
|| Mark Thomas
|| www.y-windows.org
||
||



More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved