[gtksourceview] map: give better measurements for the map width



commit 7227906ef28fbc57819d2fcbd76142dab6e5634b
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jun 19 13:24:13 2021 -0700

    map: give better measurements for the map width
    
    Instead of multiplying, actually calculate the width of a longer string of
    text in case we aren't a strict multiplicity.

 gtksourceview/gtksourcemap.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/gtksourceview/gtksourcemap.c b/gtksourceview/gtksourcemap.c
index 7207b4bf..7f744ad6 100644
--- a/gtksourceview/gtksourcemap.c
+++ b/gtksourceview/gtksourcemap.c
@@ -612,8 +612,16 @@ gtk_source_map_measure (GtkWidget      *widget,
                else
                {
                        PangoLayout *layout;
-                       gint height;
-                       gint width;
+                       char *text;
+                       guint right_margin_position;
+                       int height;
+                       int width;
+
+                       right_margin_position = gtk_source_view_get_right_margin_position (priv->view);
+
+                       text = g_malloc (right_margin_position + 1);
+                       memset (text, 'X', right_margin_position);
+                       text[right_margin_position] = 0;
 
                        /*
                         * FIXME:
@@ -622,11 +630,10 @@ gtk_source_map_measure (GtkWidget      *widget,
                         * rebuilding our CSS since it gets used a bunch and changes
                         * very little.
                         */
-                       layout = gtk_widget_create_pango_layout (GTK_WIDGET (map), "X");
+                       layout = gtk_widget_create_pango_layout (GTK_WIDGET (map), text);
                        pango_layout_get_pixel_size (layout, &width, &height);
                        g_object_unref (layout);
-
-                       width *= gtk_source_view_get_right_margin_position (priv->view);
+                       g_free (text);
 
                        *minimum = *natural = width;
                }


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