Re: [gtk-list] Re: Inserting in the middle of a hbox



On Tue, 26 Jan 1999, Etienne Grossmann wrote:

>   Hello,
> 
> 
> 
> Thomas Mailund Jensen <mailund@daimi.au.dk> :
> >  E>   I would like to know wether it is possible to insert elements at
> >  E> an arbirtrary (that is, not at the beginning or at the end)
> >  E> position in a hbox?
> > 
> > I don't think you can pack at arbitrary points directly, but you can
> > reorder children of a box with 
> > 
> > void       gtk_box_reorder_child       (GtkBox       *box,
> >                                         GtkWidget    *child,
> >                                         gint          position);
> 
> 
>   Thank you for the tip. I guess I can find (in the docs) a way to
> have the widget displayed only after the reordering has happened.

even for an already visible h/vbox, you can do

gtk_container_add (GTK_CONTAINER (hvbox), child);
gtk_box_reorder_child (GTK_BOX (hvbox), child, 1);

without causing any flickering because the neccessary resizes will
get queued and not be handled untill the next main loop's iteration,
i.e. at least untill after your current function is left.

> >  E>   Also, is there any way to delete an element from a hbox?
> > 
> > I can't think of one...and I don't think there is...it would probably
> > cause all kinds of problems with the packing.
> 
>   Uh, oh; do you think I could do the following instead :
> 
>   - Get back the children of the hbox,
>   - create a new hbox with only the wanted children.
> 
>   Does it sound possible (especially, the first step may not be
> permitted by gtk)?
> 
>   Sorry for asking before consulting the docs (I can't go look in the
> docs at the moment, being at work). 

that would probably be somewhat ugly as you would have to care about
preserving packing behaviour (expand, fill etc...) as well, simply
use

gtk_widget_ref (child);
gtk_container_remove (GTK_CONTAINER (hvbox), child);
/* do something else with the child */
gtk_widget_unref (child);

if you need the widget for anthing else after the removal, or if
you don't care about it anymore:

gtk_widget_destroy (child);

this will automatically remove the child from its container as well.
if you need to move the widget from one container to another, you
might also try

gtk_widget_reparent (child, new_container);

which is somewhat more efficient than 

gtk_widget_ref (child);
gtk_container_remove (GTK_CONTAINER (hvbox), child);
gtk_container_add (GTK_CONTAINER (other_hvbox), child);
gtk_widget_unref (child);

> 
> 
>   Thanks,
> 
>   Etienne
> 

---
ciaoTJ



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