aks
aks

Reputation: 109

How can I make scalable GTK_IMAGE

I want to have an image displayed inside a window that would scale when the user resizes the window. I have tried using the size-allocate event like this:

static gboolean allocback(GtkWidget *w, GtkAllocation *a, char *data) {

    /* pix is a pixbuf of the full image */
    gtk_image_set_from_pixbuf(GTK_IMAGE(image), pix);
    /* scale_image just scales the pixbuf of GTK_IMAGE keeping the ratio*/
    scale_image(GTK_IMAGE(image), a->width, a->height);

    return FALSE;
}

In main:

g_signal_connect(G_OBJECT(window), "size-allocate", G_CALLBACK(allocback), NULL);

This only works when making the window larger but you can't make it smaller supposedly because the image has allocated the size. I could just use a->width - 100 or something but I believe there is a better way. Another thing that doesn't work in my solution is going back from maximized window. I'd like it to go back to the size where it was maximized. Now it just unmaximizes the window but the image is still the same width and height making the window to be the same width and height with the image too.

Does anybody have any good solution to this?

Upvotes: 0

Views: 356

Answers (1)

aks
aks

Reputation: 109

I found the solution. I just had to put the image in a scrolled window.

Upvotes: 1

Related Questions