Re: Q: Resizing Fixeds




[ This didn't get through first time ]

Kenneth Albanowski <kjahds@kjahds.com> writes:

> On 5 Feb 1999, Owen Taylor wrote:
> 
> > "configure_event" is, like all event signals, RUN_LAST. That
> > means that you get the event before GtkWindow does, so at
> > that point, window->allocation has not yet been set.
> > 
> > Either use event->height/width instead, or 
> > connect to size_allocate instead. 
> 
> Logical. Unfortunately, there's still a lag. I've tried both of these:
> 
>   $w->signal_connect("configure_event" => sub {
>        my($widget,$e) = @_;
>        if ($e->{width} > 0 and $e->{height} > 0) {
>            $g->set_usize($e->{width}, $e->{height});
>        }
>    });
>  
>     $w->signal_connect("size_allocate" => sub {
>         $g->set_usize($_[1]->[2], $_[1]->[3]); # width, height
>     });
> 
> In both cases, the resizing of the glarea ($g) lags on step behind the
> resizing/configuring of the window ($w). It looks like the set_usize is
> being put on a queue, and not removed until the next time around, somehow. 

Hmmm, the following program works as expected for me. There
are a few sophistications in there to get the minimum size
to behave in a more natural way, but they won't affect
what you are looking at.

The allocate callback does get called twice, because 
gtk_widget_set_usize queues a resize and the configure
event will also cause a resize to happen, but both
of them occur with the correct size. Assuming that
the GLArea doesn't do too much work in "size_allocate",
or alternatively, checks first if the size actually
changed, this should be pretty harmless.

Regards,
                                        Owen


=======
#include <gtk/gtk.h>

static gboolean
configure (GtkWidget *widget, GdkEventConfigure *event, GtkWidget *darea)
{
  gtk_widget_set_usize (darea, event->width, event->height);
}

static void
allocate (GtkWidget *widget, gpointer data)
{
  g_print ("New allocation %d x %d\n",
	   widget->allocation.width, widget->allocation.height);
}

int main (int argc, char **argv)
{
  GtkWidget *fixed, *darea, *window;
  
  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  
  /* Start our window a bit bigger than it's minimum size */
  gtk_window_set_default_size (GTK_WINDOW (window), 100, 100);

  fixed = gtk_fixed_new ();
  gtk_container_add (GTK_CONTAINER (window), fixed);

  /* We set a usize on the fixed, because otherwise the requested
   * size (and minimum size) will be determined by the size
   * of darea, so the user won't be able to shrink the window
   * back down */
  gtk_widget_set_usize (fixed, 40, 40);

  darea = gtk_drawing_area_new ();
  
  gtk_fixed_put (GTK_FIXED (fixed), darea, 0, 0);

  gtk_signal_connect (GTK_OBJECT (window), "configure_event",
		      GTK_SIGNAL_FUNC (configure), darea);
  gtk_signal_connect (GTK_OBJECT (darea), "size_allocate",
		      GTK_SIGNAL_FUNC (allocate), NULL);

  gtk_widget_show_all (window);
  
  gtk_main();

  return 0;
}



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