Re: Need your help on the widget's width and height



Le Vendredi 17 Mars 2006 13:17, yeajchao a écrit :
> Hello everyone
>     I am writing my own gtk widget
>     and i want my own widget's height and width ratio is 0.8, like this:
>
>                widget->allocation.height / widget->allocation.width == 0.8
>
>     and my gtk_mywidget_size_allocate() function like this:
>
> -------- Start of my code
> -------------------------------------------------------
> static void
> gtk_mywidget_size_allocate(GtkWidget     *widget,
>                            GtkAllocation *allocation)
> {
>      ??
>
>     if (allocation->height >= allocation->width * 0.8)
>             allocation->height = allocation->width;
>     else
>             allocation->width = allocation->height/0.8;
>
>     widget->allocation = *allocation;
>
>     ??
> }
> -------- End of my code -----------------------------
>
>    But ,i found ,in my test application,my own widget's size didn't change
>    Who can tell my what's wrroy ?
>    And who can tell my how to maintain my widget's height, width ratio to a
> constant value ?
>
>    Any help would be much appreciated !
>

The GtkAspectFrame widget seems to be what you are looking for. You
can probably use it or at least have a look at its source code. It
looks like you already read it, but just in case there is a chapter
'Creating your own widget' in the Gtk tutorial which explains the size
negotiation process.

Bye,
-- 
Cédric Lucantis




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