Re: gtk_widget_size_request v. reality
- From: "Jim George" <jimgeorge gmail com>
- To: v4r4n <console cowboy gmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: gtk_widget_size_request v. reality
- Date: Thu, 18 Jan 2007 22:01:00 -0700
On 1/18/07, v4r4n <console cowboy gmail com> wrote:
It appears that the 'size-request' signal only happens once, and is not
called when the user resizes the window. I couldn't find a 'resize' signal
definition so I'm not sure what other signals I need to set up for this to
happen all the time.
Sorry, I meant 'configure_event', not size-request. By poking around
the documentation for PyGTK (info not found in the original docs for
the C API... *grumble*), I found that configure_event gets sent when
the window changes size. It's still not perfect, there's a question I
sent to this list regarding this a few days back
OK, I'll give you an example of using an HPane, which I realize *is* a
visible split between the two sections of the container widget... it's
just a bit easier to follow. I have a function set up as a signal
handler for 'configure_event' for the main window as follows:
gboolean on_ppiw_configure_cb(GtkWidget *widget, GdkEventConfigure
*event, gpointer data)
{
window_info_t *wi;
GtkWidget *hpane;
wi = g_object_get_data(G_OBJECT(widget);
g_assert(wi != NULL);
float ratio = gtk_paned_get_position(wi->hpane) /
(float)widget->allocation.width;
gtk_paned_set_position(wi->hpane, event->width * ratio);
return FALSE;
}
window_info_t is a structure that contains pointers to each control
within the window, including the hpane separating the two sections. I
attach this to the window with g_object_set_data, so I can retrieve it
within callbacks -- this is just my approach, feel free to use any
method you like to get access to your controls.
Since the callback is linked to the main window, each time it's
resized, I find out how big the window's old size is using
widget->allocation.width, and the split ratio. Now, I set the hpane's
position using the same ratio but with the new width, obtained from
event->width (note that at this point, the window still hasn't
actually been resized). This will maintain the same ratio between the
two split sides as before.
In your case, you can emulate the functionality of the hpane using an
hbox filled with two GtkAlignments and setting the widths using
event->width * ratio for the left alignment, event->width * (1-ratio)
for the right alignment.
If the parameter was 0.3, the 1st widget would take up 30% of the parent's
width while the 2nd would take up the remaining 70%. No matter what the
user does to the window, this ratio should be constant.
In the handler, rather than computing 'ratio', you can use a constant.
I compute a ratio in my code since I use a GtkHPane that the user can
resize.
-Jim
PS, I'm quite new to GTK (been at it for only about 6 months now), so
there's probably a better way to do this that I don't know about.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]