Re: changing GtkTable homogeneous expand behaviour



Tim Janik <timj gtk org> writes:

> hi owen,
> 
> currently, a homogeneous table that is allocated more
> space than it requested only fills the available area
> if one of its children is packed with the EXPAND flag.
> 
> i think that should be change, so that homogeneous tables
> always fill up the allocated space, since if the user chooses
> a homogeneous table and packs it with expand behaviour into
> its container (say a h/v box) he's probably not expecting the
> table to change size dependend on how he packs children into
> it (provided they fit of course).
> 
> the particular case i ran into is a widget that derives from
> GtkTable and allowes DnD movement of its children. for the
> case of a moving a single child, the table shrinks unexpectedly
> upon draging and grows back upon dropping.
> 
> i can't imagine a case where anyone would rely on the current
> (considerably broken) behaviour of homogeneous tables, so i'd like
> to change:
> 
> static void
> gtk_table_size_allocate_pass1 (GtkTable *table)
> {
>   [...]
> 
>   /* If we were allocated more space than we requested
>    *  then we have to expand any expandable rows and columns
>    *  to fill in the extra space.
>    */
> 
>   real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;
>   real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;
> 
>   if (table->homogeneous)
>     {
>       nexpand = 0;
>       for (col = 0; col < table->ncols; col++)
>         if (table->cols[col].expand)
>           {
>             nexpand += 1;
>             break;
>           }
> 
>       if (nexpand > 0)
>         {
>           width = real_width;
> 
>           for (col = 0; col + 1 < table->ncols; col++)
>             width -= table->cols[col].spacing;
> 
>           for (col = 0; col < table->ncols; col++)
>             {
>               extra = width / (table->ncols - col);
>               table->cols[col].allocation = MAX (1, extra);
>               width -= extra;
>             }
>         }
>     }
>   else
>   [...]
> 
> towards nexpand always being TRUE.
> 
> alternatively, we could add a property ::homogeneous_expand
> that enforces this, but i don't see any practical uses in not
> having that flag turned on.

I've only ever actually used a homogenous table once to my memory, so
I doubt this will affect a lot of people.

This change seems to have a neutral effect on the actual capabilities
involved:

 - Without the change, if you set your children to expand, you wil
   get the same behavior as after the change.
 - With the change, you can get the old behavior back by sticking
   your table in the alignment.

If doing things form scratch, I agree that the simpler "ignore expand
and fill flags for homogenous tables" would be better, but I do wonder
if it's right to change it now. 

It doesn't add functionality and it could break someone's layout.
 
> as an aside, to make derivation from GtkTable less hacky, we should
> really invoke the seperate size requisition and size allocation passes
> through a class method pointer.

Horrors, no. I think exposing the way GtkTable internally implements
it's size-request/allocation would be a serious mistake. 

That would completely prevent us from doing things like fixing the
current brokeness in calculating requests and allocations in the
presence of row-spanning children. (Bug #1261.)

Regards,
                                        Owen



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