Re: How to find the exact size a button is going to get?

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

 



Paul Davis wrote:
> On Tue, 2008-06-03 at 13:03 +0200, Toralf Lund wrote:
>   
>> Paul Davis wrote:
>>     
>>> On Tue, 2008-06-03 at 09:36 +0200, Toralf Lund wrote:
>>>   
>>>       
>>>> varun shrivastava wrote:
>>>>     
>>>>         
>>>>> you can access GtkAllocation structure which stores the x, y, width 
>>>>> and height allocated to a widget
>>>>>       
>>>>>           
>>>> That will (only) give me the size of an existing widget, won't it?
>>>>
>>>> Not what I'm looking for; as I was saying, I want to know what size a 
>>>> widget will have without actually creating it. Or differently put, I'd 
>>>> like to know the "rules" for margins/borders that are drawn around a 
>>>> widget I add to a button.
>>>>     
>>>>         
>>> gtk_widget_size_request() is your friend.
>>>   
>>>       
>> Hmmm. I still don't understand how this is supposed to help we when the 
>> widget doesn't exist. Perhaps I'm a bit slow today...
>>     
>
> [ ... ] there is no fixed sized that is known in
> advance.[ ... ]
>
> create a GtkWindow (do not show it). create the widget, add it to the
> window. show the widget (not the window). this forces all style
> information to be processed and "injected" into the widget. then call
> size_request. then delete the window and widget, and continue on. the
> whole process takes a couple of msecs at best.
>   


OK. I actually looked at the widget implementation after I wrote the 
last post, and it seems like it might be possible to extract the "real" 
value from style properties, but it wouldn't be easy as too many 
parameters are involved.

So I've done (using the C++ API)

static Gtk::Requisition addSize={ -1, -1 };

  if(addSize.width<0) {
    Gtk::Window dummyWin;
    Gtk::Button dummyButton;
    Gtk::Requisition req;

    dummyWin.add(dummyButton);
    dummyButton.show();
   
    dummyButton.size_request(req);
  }

"addSize" is then added to the content size of each button when I need 
to know its size. This seems to work quite all right.

I still think it's a bit strange that this info isn't directly available 
somewhere, but never mind that...

Thanks,


- Toralf


_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux