After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 742281 - GtkScrolledWindow should have max-content-height and max-content-width properties
GtkScrolledWindow should have max-content-height and max-content-width proper...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkScrolledWindow
3.15.x
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2015-01-03 22:50 UTC by Christian Hergert
Modified: 2016-06-05 14:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
scrolledwindow: add ::max-content-width and -height properties (11.50 KB, patch)
2016-06-02 02:34 UTC, Georges Basile Stavracas Neto
none Details | Review
tests: adapt testscrolledwindow to have max content sizes (6.20 KB, patch)
2016-06-02 02:35 UTC, Georges Basile Stavracas Neto
committed Details | Review
scrolledwindow: add ::max-content-width and -height properties (10.93 KB, patch)
2016-06-02 12:58 UTC, Georges Basile Stavracas Neto
none Details | Review
scrolledwindow: add ::max-content-width and -height properties (10.92 KB, patch)
2016-06-02 15:35 UTC, Georges Basile Stavracas Neto
none Details | Review
testsuite: add tests for scrolledwindow (5.01 KB, patch)
2016-06-03 01:34 UTC, Georges Basile Stavracas Neto
committed Details | Review
scrolledwindow: add ::max-content-width and -height properties (10.92 KB, patch)
2016-06-03 01:43 UTC, Georges Basile Stavracas Neto
none Details | Review
scrolledwindow: add ::max-content-width and -height properties (11.58 KB, patch)
2016-06-03 17:07 UTC, Georges Basile Stavracas Neto
needs-work Details | Review
scrolledwindow: add ::max-content-width and -height properties (11.74 KB, patch)
2016-06-03 17:24 UTC, Georges Basile Stavracas Neto
none Details | Review
scrolledwindow: add ::max-content-width and -height properties (11.74 KB, patch)
2016-06-03 20:07 UTC, Georges Basile Stavracas Neto
none Details | Review
scrolledwindow: add ::max-content-width and -height properties (11.77 KB, patch)
2016-06-04 17:46 UTC, Georges Basile Stavracas Neto
committed Details | Review

Description Christian Hergert 2015-01-03 22:50:48 UTC
GtkScrolledWindow has min-content-height and min-content-width properties which can be used to keep a scrolled window from shrinking beyond a certain point. As we start to use popovers more and more, it can be convenient to have a maximum size the GtkScrolledWindow should grow. This way, content can grow and shrink using it's natural size, but only up to a point.

Builder does this for the global search popover. We have a subclass of GtkScrolledWindow to perform this and it works pretty well.

https://git.gnome.org/browse/gnome-builder/tree/src/scrolledwindow/gb-scrolled-window.c
https://git.gnome.org/browse/gnome-builder/tree/src/scrolledwindow/gb-scrolled-window.h

Thoughts?
Comment 1 Carlos Soriano 2015-07-13 09:23:12 UTC
I need this for Nautilus long operations popover and for the new GtkPlacesView gsoc project.

FWIW code of Christian looks good to me. If we don't have a strong reason to not have these properties, it would be nice to have this on master as soon as possible.
Comment 2 Christian Hergert 2015-07-13 17:30:35 UTC
The code looks rather simple when done in a subclass, but merging it into the very messy details of GtkScrolledWindow is probably what is holding this up.

Strictly speaking, we could just copy it in. But that doesn't help us from a maintainability standpoint.
Comment 3 Georges Basile Stavracas Neto 2016-06-02 02:34:49 UTC
Created attachment 328919 [details] [review]
scrolledwindow: add ::max-content-width and -height properties

The GtkScrolledWindow has support to set the minimum content size (both
width and height) which controls the minimum space allocated, but does
not exposes any way to control the maximum size the content can grow.

After the introduction of GtkPopover, which always uses the minimum
size of it's children widgets, the lack of max-content-width and -height
properties became a concrete use case.

This patch introduces the GtkScrolledWindow::max-content-width and
-height properties. The properties will alter the minimum size of
the scrolled window, making it grow up to the set value. They also
respect the previously set ::min-content-width and -height.
Comment 4 Georges Basile Stavracas Neto 2016-06-02 02:35:03 UTC
Created attachment 328920 [details] [review]
tests: adapt testscrolledwindow to have max content sizes

This patch adpats the current test to show a popover with
max-content-width and -height properties set.
Comment 5 Carlos Soriano 2016-06-02 11:09:25 UTC
Review of attachment 328919 [details] [review]:

::: gtk/gtkscrolledwindow.c
@@ +1812,3 @@
+                        priv->min_content_width > width)
+                      {
+

minimum_req.width no?

@@ +1816,3 @@
+                    else
+                      {
+                     * It'll grow at least until min_content_width, and at most until

dito
Comment 6 Carlos Soriano 2016-06-02 11:11:20 UTC
Review of attachment 328920 [details] [review]:

The test in the following patch doesn't really cover the mistake done in the previous patch. Worth expanding the test to cover all cases.
Comment 7 Georges Basile Stavracas Neto 2016-06-02 12:58:48 UTC
Created attachment 328949 [details] [review]
scrolledwindow: add ::max-content-width and -height properties

Updated and simplified the patch.

(In reply to Carlos Soriano from comment #5)
> Review of attachment 328919 [details] [review] [review]:
> 
> ::: gtk/gtkscrolledwindow.c
> @@ +1812,3 @@
> +                        priv->min_content_width > width)
> +                      {
> +
> 
> minimum_req.width no?

No.
Comment 8 Carlos Soriano 2016-06-02 13:14:11 UTC
(In reply to Georges Basile Stavracas Neto from comment #7)
> Created attachment 328949 [details] [review] [review]
> scrolledwindow: add ::max-content-width and -height properties
> 
> Updated and simplified the patch.
> 
> (In reply to Carlos Soriano from comment #5)
> > Review of attachment 328919 [details] [review] [review] [review]:
> > 
> > ::: gtk/gtkscrolledwindow.c
> > @@ +1812,3 @@
> > +                        priv->min_content_width > width)
> > +                      {
> > +
> > 
> > minimum_req.width no?
> 
> No.

No? But you actually changed it in your last patch. Are you sure you checked the line I was reviewing? (Don't trust what is printed in the comment, click the "review" button)
Comment 9 Georges Basile Stavracas Neto 2016-06-02 15:35:24 UTC
Created attachment 328962 [details] [review]
scrolledwindow: add ::max-content-width and -height properties

Done
Comment 10 Timm Bäder 2016-06-02 16:45:26 UTC
It's "bigger than", not "bigger then". But more importantly, may I mention at this point that there's a size requisition test for GtkRevealer[0] which makes sure that GtkRevealer preferred sizes make sense? *hint* *hint*




[0] https://git.gnome.org/browse/gtk+/tree/testsuite/gtk/revealer-size.c
Comment 11 Georges Basile Stavracas Neto 2016-06-03 01:34:07 UTC
Created attachment 329010 [details] [review]
testsuite: add tests for scrolledwindow

This patch adds a set of tests for scrolled window
sizing, covering both min- and max-content width and
height.
Comment 12 Georges Basile Stavracas Neto 2016-06-03 01:43:16 UTC
Created attachment 329011 [details] [review]
scrolledwindow: add ::max-content-width and -height properties

Fixed the typos.
Comment 13 Matthias Clasen 2016-06-03 16:40:34 UTC
Review of attachment 329011 [details] [review]:

Refreshingly simple patch, I have to say.

I'm not happy with the content-width/height naming of these properties - its really about the size of the viewport that you get on the child ('the content'). But too late now, since we already have the min-content-width/height properties.

::: gtk/gtkscrolledwindow.c
@@ +1810,3 @@
+                     */
+                    minimum_req.width = MAX (minimum_req.width, width);
+                    natural_req.width = width;

I think this should be

natural_req.width = MAX (natural_req.width, width)

if only for clarity (but I am not 100% convinced that you can't end up with natural_req.with < minimum_req.width without it.

@@ +1850,3 @@
+                     */
+                    minimum_req.height = MAX (minimum_req.height, height);
+                    natural_req.height = height;

Same here

@@ +4547,3 @@
+ *
+ * It is a programming error to set the max_content_width to a value bigger
+ * than min_content_width.

You mean smaller here, certainly ? Thats what your assertion is about, anyway.

And, if you consider it a programming error here, you should do the same in 

gtk_scrolled_window_set_min_content_width

@@ +4599,3 @@
+ *
+ * It is a programming error to set the max_content_height to a value bigger
+ * than min_content_height.

Same here: smaller
Comment 14 Matthias Clasen 2016-06-03 16:41:45 UTC
Review of attachment 329011 [details] [review]:

::: gtk/gtkscrolledwindow.c
@@ +1839,3 @@
 		}
+
+                if (priv->max_content_height > -1 &&

There's an indentation bug here - the whole block is off-by-2-spaces
Comment 15 Georges Basile Stavracas Neto 2016-06-03 17:07:42 UTC
Created attachment 329084 [details] [review]
scrolledwindow: add ::max-content-width and -height properties

Fixed the indentation issue, as well as the docs and the natural height
request.
Comment 16 Matthias Clasen 2016-06-03 17:13:26 UTC
Review of attachment 329084 [details] [review]:

Did you want to add the same assert and documenation to the min-content setters ?

::: gtk/gtkscrolledwindow.c
@@ +4553,3 @@
+ *
+ * It is a programming error to set the max_content_width to a value smaller
+ * than min_content_width.

Purely cosmetic, but I'd avoid te underscores in the text here and may say:

It is a programming error to set the maximum content width to a value smaller than #GtkScrolledWindow:min-content-width.

@@ +4606,3 @@
+ * It is a programming error to set the max_content_height to a value smaller
+ * than min_content_height.
+ *

Same here
Comment 17 Georges Basile Stavracas Neto 2016-06-03 17:24:21 UTC
Created attachment 329086 [details] [review]
scrolledwindow: add ::max-content-width and -height properties

Improved the documentation.
Comment 18 Matthias Clasen 2016-06-03 19:30:22 UTC
Review of attachment 329086 [details] [review]:

::: gtk/gtkscrolledwindow.c
@@ +4415,3 @@
  *
+ * It is a programming error to set the maximum content width to a
+ * value smaller than #GtkScrolledWindow:min-content-width.

I would actually flip these around here and say:

It is a programming error to set the minimum content width to a
value bigger than #GtkScrolledWindow:max-content-width.

Man, I'm picky today...

@@ +4470,3 @@
+ * It is a programming error to set the maximum content height to a
+ * value smaller than #GtkScrolledWindow:min-content-height.
+ *

Same here
Comment 19 Georges Basile Stavracas Neto 2016-06-03 20:07:37 UTC
Created attachment 329091 [details] [review]
scrolledwindow: add ::max-content-width and -height properties

(In reply to Matthias Clasen from comment #18)
> Review of attachment 329086 [details] [review] [review]:
> I would actually flip these around here and say:
> 
> It is a programming error to set the minimum content width to a
> value bigger than #GtkScrolledWindow:max-content-width.
> 
> Man, I'm picky today...

Absolutely. Fixed.
 
> + *
> 
> Same here

Done.
Comment 20 Tristan Van Berkom 2016-06-04 10:55:56 UTC
Review of attachment 329084 [details] [review]:

Overall, the patch makes perfect sense.

I don't think we should land this with the current g_assert() expressions, that's a bit overkill,
it may be a programming error to set min > max as mentioned in the new docs, but return_if_fail() 
to police the values should be used here.
Comment 21 Georges Basile Stavracas Neto 2016-06-04 17:46:13 UTC
Created attachment 329130 [details] [review]
scrolledwindow: add ::max-content-width and -height properties

Thanks for the review, Tristan. This patch changes from g_assert() to g_return_if_fail().
Comment 22 Tristan Van Berkom 2016-06-05 05:16:38 UTC
Review of attachment 329130 [details] [review]:

Looks good to me :)
Comment 23 Tristan Van Berkom 2016-06-05 07:49:04 UTC
(In reply to Tristan Van Berkom from comment #22)
> Review of attachment 329130 [details] [review] [review]:
> 
> Looks good to me :)

I should add one more note to this, in light of bug 767238 which I discovered looking into scrolled windows this weekend, equal care must be taken for the new max content size.

I.e. the added clause which 'clamps' the child request size should be performed before adding any space for optional scrollbars (content size, max or min, is not scrollbar inclusive).

That said I think it's fine to merge this with the existing mis-behavior in place and just do the right thing in bug 767238.
Comment 24 Matthias Clasen 2016-06-05 13:28:32 UTC
Review of attachment 329130 [details] [review]:

.
Comment 25 Matthias Clasen 2016-06-05 13:28:55 UTC
Review of attachment 329010 [details] [review]:

more tests always good!
Comment 26 Matthias Clasen 2016-06-05 13:29:48 UTC
Review of attachment 328920 [details] [review]:

ok. Ideally we'd also find a place in gtk3-demo or gtk-widget-factory to demonstrate this
Comment 27 Georges Basile Stavracas Neto 2016-06-05 14:05:30 UTC
Thanks for the reviews.

Attachment 328920 [details] pushed as 657fcd0 - tests: adapt testscrolledwindow to have max content sizes
Attachment 329010 [details] pushed as 3962b90 - testsuite: add tests for scrolledwindow
Attachment 329130 [details] pushed as 4e5ecb7 - scrolledwindow: add ::max-content-width and -height properties