Re: gtk_container_new_child (was Re: Wrapping Box Container)



On Tue, 2010-08-31 at 18:32 -0400, Havoc Pennington wrote:
> Hi,
> 
> On Mon, Aug 30, 2010 at 9:51 PM, Havoc Pennington <hp pobox com> wrote:
> > With my proposed padding cleanup though that issue goes away:
> >
> > child = g_object_new(TYPE_MYCHILD, "padding", 5, "h-align",
> > GTK_ALIGN_FILL_HORIZONTAL, NULL);
> > insert_child(layout, child, 2, GTK_WRAP_BOX_PACK_Y_EXPAND);
> >
> 
> Really great would be:
> 
> gtk_container_add_with_properties(layout, child,
>                                                   "position", 2,
>                                                   "y-expand", TRUE,
>                                                   "padding", 5,
>                                                   "h-align",
> GTK_ALIGN_FILL_HORIZONTAL,
>                                                   NULL);
> 
> which would work if we made gtk_container_set() and friends fall back
> to props on the child if not finding a child prop on the container.
> Kind of magic, but also really handy and results in very readable
> code.

I like this idea alot and as its a trivial patch I might write one
up tonight or tomorrow ...

> 
> The patch is kind of a pain because gtkcontainer.c relies on weird
> gobject internals (seriously, #include <gobject/gobjectnotifyqueue.c>
> ?) and stealing part of g_object_set() with public GObject API
> basically isn't possible. However, either a bit of a hack in here or a
> quick API addition to libgobject would make this a simple feature to
> accomplish.
> 
> EVEN MORE AWESOME would be:
> 
> child = gtk_container_new_child(layout, MY_TYPE_WHATEVER,
>                                                   "position", 2,
>                                                   "y-expand", TRUE,
>                                                   "padding", 5,
>                                                   "h-align",
> GTK_ALIGN_FILL_HORIZONTAL,
>                                                   NULL);
> 
> sweet! even construct-only properties could be set here.

I can see how that can reduce some lines of code when building
UIs directly with code (not GtkBuilder)... although I think it
would be best to avoid as it throws property and packing property
names into the same namespace (so if ever packing properties and 
object properties share the same name, this api will be a little
ambiguous as to which will be assigned, or one or the other 
would be prioritized...).

Thoughts ?

Cheers,
       -Tristan





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