Compare commits

...

2 Commits

Author SHA1 Message Date
Matthias Clasen
526b25747c Add tests for the new wrap behavior 2022-04-13 11:50:55 -04:00
Matthias Clasen
9bbe101d5c label: Only produce multiple lines when wrapping
We have a wrap property, and we should respect it.

This changes things so that the lines property is
ignored unless the label is both ellipsized and
wrapping.

Fixes: #4714
2022-04-13 11:02:49 -04:00
20 changed files with 308 additions and 3 deletions

View File

@@ -2547,7 +2547,7 @@ gtk_label_class_init (GtkLabelClass *class)
* The number of lines to which an ellipsized, wrapping label
* should be limited.
*
* This property has no effect if the label is not wrapping or ellipsized.
* This property has no effect if the label is not wrapping and ellipsized.
* Set this property to -1 if you don't want to limit the number of lines.
*/
label_props[PROP_LINES] =
@@ -4168,8 +4168,10 @@ gtk_label_ensure_layout (GtkLabel *self)
pango_layout_set_ellipsize (self->layout, self->ellipsize);
pango_layout_set_wrap (self->layout, self->wrap_mode);
pango_layout_set_single_paragraph_mode (self->layout, self->single_line_mode);
if (self->lines > 0)
if (self->wrap && self->lines > 0)
pango_layout_set_height (self->layout, - self->lines);
else
pango_layout_set_height (self->layout, -1);
if (self->ellipsize || self->wrap)
pango_layout_set_width (self->layout, gtk_widget_get_width (GTK_WIDGET (self)) * PANGO_SCALE);
@@ -5777,7 +5779,7 @@ _gtk_label_get_selection_bound (GtkLabel *self)
* Sets the number of lines to which an ellipsized, wrapping label
* should be limited.
*
* This has no effect if the label is not wrapping or ellipsized.
* This has no effect if the label is not wrapping and ellipsized.
* Set this to -1 if you dont want to limit the number of lines.
*/
void

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">1</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">…</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">1</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello World multi line</property>
<property name="max-width-chars">2</property>
<property name="wrap-mode">word</property>
<property name="ellipsize">end</property>
<property name="lines">2</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">…</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello World multi line</property>
<property name="max-width-chars">2</property>
<property name="wrap-mode">word</property>
<property name="ellipsize">end</property>
<property name="lines">2</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">200</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">…</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">200</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello World multi line</property>
<property name="max-width-chars">2</property>
<property name="wrap-mode">word</property>
<property name="ellipsize">end</property>
<property name="lines">2</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">1</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello
W…</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<!--- Set this:
1 to test min height
remove it to test nat height
200 to test oversize
-->
<property name="default-height">1</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello World multi line</property>
<property name="max-width-chars">2</property>
<property name="wrap-mode">word</property>
<property name="wrap">1</property>
<property name="ellipsize">end</property>
<property name="lines">2</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">1</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello
W…</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello World multi line</property>
<property name="max-width-chars">2</property>
<property name="wrap-mode">word</property>
<property name="wrap">1</property>
<property name="ellipsize">end</property>
<property name="lines">2</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">200</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello
W…</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">200</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello World multi line</property>
<property name="max-width-chars">2</property>
<property name="wrap-mode">word</property>
<property name="wrap">1</property>
<property name="ellipsize">end</property>
<property name="lines">2</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">1</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello
World
multi
line</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">1</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello World multi line</property>
<property name="max-width-chars">2</property>
<property name="wrap-mode">word</property>
<property name="wrap">1</property>
<property name="lines">2</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello
World
multi
line</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello World multi line</property>
<property name="max-width-chars">2</property>
<property name="wrap-mode">word</property>
<property name="wrap">1</property>
<property name="lines">2</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">200</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello
World
multi
line</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="default-width">10</property>
<property name="default-height">200</property>
<property name="decorated">0</property>
<child>
<object class="GtkLabel">
<property name="label">Hello World multi line</property>
<property name="max-width-chars">2</property>
<property name="wrap-mode">word</property>
<property name="wrap">1</property>
<property name="lines">2</property>
</object>
</child>
</object>
</interface>

View File

@@ -416,6 +416,24 @@ testdata = [
'label-wrap-word-char-natural-size.ui',
'label-wrapped-huge-max-width-chars.ref.ui',
'label-wrapped-huge-max-width-chars.ui',
'label-wrap-ellipsize-min-size.ref.ui',
'label-wrap-ellipsize-min-size.ui',
'label-wrap-ellipsize-nat-size.ref.ui',
'label-wrap-ellipsize-nat-size.ui',
'label-wrap-ellipsize-oversize.ref.ui',
'label-wrap-ellipsize-oversize.ui',
'label-nowrap-ellipsize-min-size.ref.ui',
'label-nowrap-ellipsize-min-size.ui',
'label-nowrap-ellipsize-nat-size.ref.ui',
'label-nowrap-ellipsize-nat-size.ui',
'label-nowrap-ellipsize-oversize.ref.ui',
'label-nowrap-ellipsize-oversize.ui',
'label-wrap-noellipsize-min-size.ref.ui',
'label-wrap-noellipsize-min-size.ui',
'label-wrap-noellipsize-nat-size.ref.ui',
'label-wrap-noellipsize-nat-size.ui',
'label-wrap-noellipsize-oversize.ref.ui',
'label-wrap-noellipsize-oversize.ui',
# this seems to make assumptions on text positioning
# that are not valid with subpixel positioning
#'label-wrap-justify.ref.ui',