Re: Shrinking and growing widgets in GTK+ 3.x
- From: Tristan Van Berkom <tristanvb openismus com>
- To: Bastien Nocera <hadess hadess net>
- Cc: GTK Development List <gtk-devel-list gnome org>
- Subject: Re: Shrinking and growing widgets in GTK+ 3.x
- Date: Thu, 02 Dec 2010 13:07:03 +0900
On Thu, 2010-12-02 at 00:56 +0000, Bastien Nocera wrote:
> Heya,
>
> One of the features of Totem (and one implemented in a number of movie
> players) is to resize the video to match the actual video size (or a
> multiple of it). For example, a 320x480 video would see Totem resize its
> video canvas to 480x320, if the preference is enabled.
>
> The old GTK+ 2.x code did that by:
> - shrinking the toplevel to 1x1 (so all the widgets in the window get
> their minimum size set)
> - wait for the "size-request"
> - request our real size (480x320) in the size-request signal
> - and unset that size request in an idle (so that the window can be
> shrinked)
>
> http://git.gnome.org/browse/totem/tree/src/backend/video-utils.c#n197
>
> It's pretty gruesome, but mostly works.
>
> For GTK+ 3.x, I wanted to clean that code.
>
> I tried saving our wanted size, calling gtk_widget_queue_resize() and
> wait for ->get_preferred_{width,height} to be called, and set the wanted
> size as the natural size. Problem is that this only worked when growing
> the window, not shrinking it.
>
> My current backup plan was to do the above in 2 steps:
> - save our wanted size and queue a resize
> * set the natural size to 1x1, and queue an idle handler
> - idle handler calls gtk_widget_queue_resize()
> * set the natural size to the actual wanted size
>
> This is just about as gruesome as the original GTK+ 2.x code.
>
> Does anyone have a better idea on how i implement my own sync-ish
> "gtk_widget_resize()".
You want your toplevel GtkWindow to "shrink" because of the new video
size ? or you just want your canvas to "fit" the video size in a
user resizable toplevel ?
Lets assume you have a derived GtkWidget which is the VideoDisplay
and that it implements get_preferred_width()/get_preferred_height().
Pack it into something in your UI (whatever it is) and set the
"valign"/"halign" GtkWidget properties to GTK_ALIGN_CENTER.
When the stream's video sizes is detected, queue a resize on
VideoDisplay and it will be re-requested (and just return the
video size from the get_preferred_width()/height() vfuncs on
VideoDisplay).
If you want the whole window to "shrink", a.) that's a little
yuck, I'm not sure how much end-users like that behaviour ...
b.) GTK+ doesnt like doing that... but if I recall correctly
you might provoke GTK+ to do that by calling
gtk_container_check_resize()... I'd have to take a deeper look
to make sure.
Cheers,
-Tristan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]