Re: implementing a container??



On Sun, 2003-04-27 at 22:32, Jim Crafton wrote:

If you want to do anything at all complex, generally implementing 
a new container is right; if you use a GtkFixed, it's going to be
inefficient, and it's pretty much impossible to get positioning
that depends on the size of the children widgets right.

Implementing a container isn't that hard ... the only virtual methods
you need to implement are, I think, size_request(), size_allocate(), 
forall(), and remove(). 
 

(child_type() and add() are theoretically needed as well, but as your
widget is just being used in your framework, I doubt you'll need them.)
 

Are there any good examples to look at?

I don't have a great example at hand. GtkTable might be good to look at;
it isn't terribly simple, but it a self-contained container widget
whose sole purpose is to arrange multiple children. 

You can ignore everything dealing with child properties - they are
intended for GUI builders.

Also is there anything you need to do to prevent the the main window 
from being locked ot a minimum size?

I noticed that when a re-positioned a child widget with
gtk_fixed_move or gtk_widget_set_size_request() that the minimum width/height of the main window 
would be affected, preventing the user from resizing it less than the child current pos.

If you implement your own widget, you can report any desired size you
want.

If you use a GtkFixed, you can simple gtk_widget_set_size_request() of
the GtkFixed to 1x1 if you want.

Note also that you can control the min/max/etc size of a GtkWindow
at a detailed level with gtk_window_set_geometry_hints().

When implementing the methods for the container how do you move the> 
widget (other than the above mentioned gtk_fixed_move or gtk_widget_set_size_request )? 

Very sketchily, what you do is record the new position, and call
gtk_widget_queue_resize (child), then in your size_allocate()
implementation you loop over all your children, and call 
gtk_widget_size_allocate() on each child with its new position.

Regards, 
                                          Owen





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