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]

 



On Tue, 2008-06-03 at 14:38 +0200, Toralf Lund wrote:

> 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...

the nice part about this method is that it works for much more complex
situations too. i use it to determine the size of an hbox packed with a
5x3 table of buttons and 3 other widgets. the nature of the widgets
involved (i.e. precisely which properties they use and how they use
them) goes away and you're left with a reliable mechanism to determine
the size of any grouping of widgets ahead of time.

in gtk1, the "add to window" part wasn't necessary - i guess this became
more critical as better multi-screen support was added, but it still
seems a bit superfluous because the window isn't really attached to any
real backend window system resources when this is all done.

--p



_______________________________________________
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