Merge branch 'wip/otte/for-master' into 'master'

boxlayout: Be more careful with what to consider natural size

See merge request GNOME/gtk!4129
This commit is contained in:
Benjamin Otte 2021-11-06 03:54:08 +00:00
commit 4f4f2d169a
5 changed files with 130 additions and 1 deletions

View File

@ -327,6 +327,8 @@ gtk_box_layout_compute_opposite_size_for_size (GtkBoxLayout *self,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
int min_opposite, nat_for_min;
if (!gtk_widget_should_layout (child))
continue;
@ -335,6 +337,22 @@ gtk_box_layout_compute_opposite_size_for_size (GtkBoxLayout *self,
-1,
&sizes[i].minimum_size, &sizes[i].natural_size,
NULL, NULL);
/* Don't just use the natural size as the max size,
* the natural size is the ideal size, not necessarily
* the maximum size.
* Also check the nat size for opposite min size.
*/
gtk_widget_measure (child,
OPPOSITE_ORIENTATION (self->orientation),
-1,
&min_opposite, NULL,
NULL, NULL);
gtk_widget_measure (child,
self->orientation,
min_opposite,
NULL, &nat_for_min,
NULL, NULL);
sizes[i].natural_size = MAX (sizes[i].natural_size, nat_for_min);
children_minimum_size += sizes[i].minimum_size;
i += 1;

View File

@ -1203,7 +1203,7 @@ get_width_for_height (GtkLabel *self,
if (text_height > height)
min = mid + 1;
else
max = text_width;
max = mid;
}
*minimum_width = min;

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="width_request">150</property>
<property name="height_request">300</property>
<property name="decorated">0</property>
<child>
<object class="GtkScrolledWindow">
<child>
<object class="GtkListView" id="listview">
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<property name="wrap">1</property>
<binding name="label">
<lookup name="string" type="GtkStringObject">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
<property name="model">
<object class="GtkNoSelection">
<property name="model">
<object class="GtkStringList">
<items>
<item>Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.</item>
<item>Hello World!</item>
</items>
</object>
</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="width_request">150</property>
<property name="height_request">300</property>
<property name="decorated">0</property>
<child>
<object class="GtkScrolledWindow">
<child>
<object class="GtkListView" id="listview">
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkBox">
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="xalign">0</property>
<property name="wrap">1</property>
<binding name="label">
<lookup name="string" type="GtkStringObject">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</child>
</object>
</child>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
<property name="model">
<object class="GtkNoSelection">
<property name="model">
<object class="GtkStringList">
<items>
<item>Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.</item>
<item>Hello World!</item>
</items>
</object>
</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -385,6 +385,8 @@ testdata = [
'link-coloring.css',
'link-coloring.ref.ui',
'link-coloring.ui',
'listview-with-wrapped-labels.ref.ui',
'listview-with-wrapped-labels.ui',
'marble.xpm',
'messagedialog-secondarytext.ui',
'messagedialog-secondarytext.ref.ui',