Re: gtk_widget_set_size_request stopped working with GTK3



Hi Tristan!

> I suggest you start by filing an enhancement bug against GtkImage for this.

Yes, I can do that.  Just to make sure, I file a new bug for component gtk, severity set to enhancement, and put somethign like "Size request of GtkImage" into the title.  Is this correct?

> If you have a patch to propose, here would be a good place to discuss
> the proposed new apis.

I might also be able to work on this and provide a patch.  Before starting on this, how about the following changes:

Regarding size request:

We add a new property of type boolean to GtkImage.  If it is set (default), the size request for GtkImage will be the size of the underlying image (or the pixel-size), i.e. the exact same behaviour as it is now.  If it is set to FALSE then the minimum size will be (1, 1) and an application can use "width-request" and "height-request" for making the widget size larger.  I am not sure what a good name for this new property would be, but maybe you have a suggestion?.  Something like "min-size-is-image-size" would probably make the property self-explanatory but is obviously too long compared to other existing property names.  Maybe "full-image" or "image-size-request"?

Regading placement:

In GTK2, GtkImage cropped the image such that only the center is shown, i.e. it took off an equal amount of image content on the left and right, and top and bottom.  It probably just sets the right clipping mask when drawing the image for achieving this.  We could simply use the same policy, or we modify the usage of GtkWidget's "halign" and "valign" properties.  Currently the docs reads:

"halign" GtkAlign : Read / Write

How to distribute horizontal space if widget gets extra space, see GtkAlign

enum GtkAlign
typedef enum { GTK_ALIGN_FILL, GTK_ALIGN_START, GTK_ALIGN_END, GTK_ALIGN_CENTER
} GtkAlign; 

Controls how a widget deals with extra space in a single (x or y)
dimension. 

Alignment only matters if the widget receives a "too large" allocation,
for example if you packed the widget with the "expand" flag inside a GtkBox, then the widget might get extra space.  If
you have for example a 16x16 icon inside a 32x32 space, the icon
could be scaled and stretched, it could be centered, or it could be
positioned to one side of the space. 

Note that in horizontal context GTK_ALIGN_START and GTK_ALIGN_END are interpreted relative to text direction. 
GTK_ALIGN_FILL stretch to fill all space if possible, center if no meaningful way to stretch  
GTK_ALIGN_START snap to left or top side, leaving space on right or bottom  
GTK_ALIGN_END snap to right or bottom side, leaving space on left or top  
GTK_ALIGN_CENTER center natural width of widget inside the allocation

My suggestion is to make halign and valign also deal with the case where the content of the widget is larger than the allocated space.  The modified docs would then read:

"halign" GtkAlign : Read / Write

How to distribute horizontal space, see GtkAlign

enum GtkAlign
typedef enum { GTK_ALIGN_FILL, GTK_ALIGN_START, GTK_ALIGN_END, GTK_ALIGN_CENTER
} GtkAlign; 

Controls how a widget deals with space in a single (x or y)
dimension. 

Alignment only matters if the widget receives a "too large" or "too small" allocation,
for example if you packed the widget with the "expand" flag inside a GtkBox, then the widget might get extra space.  If
you have for example a 16x16 icon inside a 32x32 space, the icon
could be scaled and stretched, it could be centered, or it could be
positioned to one side of the space.  Likewise, if you have a 100x100 image inside a 20x20 space
then the image could be scaled down, only the center part of the image be shown, or it could
be cropped to the top left or bottom right part.


Note that in horizontal context GTK_ALIGN_START and GTK_ALIGN_END are interpreted relative to text direction. 
GTK_ALIGN_FILL stretch or shrink to fill all space if possible, or center if no meaningful way to scale
GTK_ALIGN_START snap to left or top side, leaving space or cropping widget content on right or bottom  
GTK_ALIGN_END snap to right or bottom side, leaving space or cropping widget content on left or top  
GTK_ALIGN_CENTER center widget inside the allocation

Steffen



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