tooltip: Don't play games with max-width-chars
authorMatthias Clasen <mclasen@redhat.com>
Sat, 28 Jan 2023 18:04:01 +0000 (13:04 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 28 Jan 2023 18:06:30 +0000 (13:06 -0500)
Setting max-width-chars to the number of characters
in the string works ok only as long as the average
char width we get from Pango matches reality. Sadly
that seems not always the case, and this code was
causing short Chinese tooltips to always be broken
into two lines.

Fixes: #4470
gtk/gtktooltipwindow.c
gtk/ui/gtktooltipwindow.ui

index 491598a1f52e681b41915f35868851289df069bb..a24bcb4157970907cc32f997aa72eba27b5c3a48 100644 (file)
@@ -401,36 +401,12 @@ gtk_tooltip_window_new (void)
   return g_object_new (GTK_TYPE_TOOLTIP_WINDOW, NULL);
 }
 
-static void
-update_label_width (GtkLabel *label)
-{
-  const char *text;
-
-  text = gtk_label_get_text (label);
-  if (strchr (text, '\n'))
-    {
-      gtk_label_set_wrap (label, FALSE);
-    }
-  else
-    {
-      int len;
-
-      len = g_utf8_strlen (text, -1);
-
-      gtk_label_set_max_width_chars (label, MIN (len, 50));
-      gtk_label_set_wrap (label, TRUE);
-    }
-}
-
 void
 gtk_tooltip_window_set_label_markup (GtkTooltipWindow *window,
                                      const char       *markup)
 {
   if (markup != NULL)
-    {
-      gtk_label_set_markup (GTK_LABEL (window->label), markup);
-      update_label_width (GTK_LABEL (window->label));
-    }
+    gtk_label_set_markup (GTK_LABEL (window->label), markup);
 
   gtk_widget_set_visible (window->label, markup != NULL);
 }
@@ -440,10 +416,7 @@ gtk_tooltip_window_set_label_text (GtkTooltipWindow *window,
                                    const char       *text)
 {
   if (text != NULL)
-    {
-      gtk_label_set_text (GTK_LABEL (window->label), text);
-      update_label_width (GTK_LABEL (window->label));
-    }
+    gtk_label_set_text (GTK_LABEL (window->label), text);
 
   gtk_widget_set_visible (window->label, text != NULL);
 }
index 127fa045e48f7752738fe7dc4b99068e230818bc..2cecd58c73c49200a7ac03cd0551c72f1eb8f04b 100644 (file)
@@ -14,6 +14,7 @@
         <child>
           <object class="GtkLabel" id="label">
             <property name="wrap">1</property>
+            <property name="max-width-chars">50</property>
           </object>
         </child>
       </object>