Baseline alignment ideas



One of the main layout features we're badly missing atm is baseline
alignment. I spent some time looking at this recently but I bumped
into some problems. I'd like to bring this up for discussion in the
hope that we might figure out a solution to my problems.

First, let me define what i mean by baseline layout and the API I
expect it to have. Every widget has a single baseline, which is
an offset from the top of the allocation to the baseline.
Some layouts (such as e.g. multi-line text) have multiple possible
baselines, but this is outside of the common gtk+ api and each
widget gets to decide which one to use, via some per-widget API.

We add a new GtkAlign element, GTK_ALIGN_BASELINE, which when not
supported does the same as CENTER, but in containers that support
baseline alignment we align all the children with BASELINE up so
that they all have the baseline at the same y coord. Additionally
we need a single setting for the container itself that decides how
to align the whole group of baseline aligned widgets (i.e. do we
put the baseline alignment widgets at the bottom or at the top?

An example hbox layout could look like with baseline at botttom:

+-----------------------------------------------+
|+-------+                                      |
|| START |                                      |
|+-------+                                      |
|                                     +--------+|
|                   +-------+         | CENTER ||
|          +-------+|       |         +--------+|
|          |--BASE-||-BASE--|+-------+          |
|          |       |+-------+|  END  |          |
|          +-------+         +-------+          |
+-----------------------------------------------+

Now, back to the problem. Consider implementing size request/allocation
for the container above. We can start with the min width, asking each
child for min width and summing that. Then we ask for min height for
that width and for the baseline at that width. We can thus simply
calculate the min and natural size requests and their corresponding
baseline.

The problem comes later, when we get the final size allocation for the
container. Its easy to distribute the widths, but if the final height
is not the same as the min/natural request, how do we distribute the
height among the baseline aligned children such that the total height
after we baseline align them fits in the assigned height?

Since the baseline position depends (non-linearly) on the exact height
we assign to the child, and the total size depends on the baselines
this seems circular, and I can't see any way to calculate this other
than in some iterative fashion.

For instance, if you have two children with the baseline at the top,
then all extra space can be assigned to each child. However, if one
has the baseline att the bottom you need to give each half the extra
height.

I don't really see any way to solve this generically. But maybe we can
somehow limit our baseline support so that this works? For instance,
we could always request the naural size for baseline aligned widgets
and never grow them? Would that be enough in practical use? I dunno...

Ideas wanted...




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]