GtkTextView: Anchors ignore gutter
Steps to reproduce
- Use this code:
#include <gtk/gtk.h>
static void add_anchor (GtkTextView *view, const char *str, int line, int column) {
GtkWidget *widget = gtk_label_new (g_strdup_printf ("<span foreground=\"red\" background=\"purple\"><b>%s</b></span>", str));
gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
GtkTextIter iter;
gtk_text_buffer_get_start_iter (gtk_text_view_get_buffer (view), &iter);
gtk_text_iter_forward_lines (&iter, line);
gtk_text_iter_forward_chars (&iter, column);
GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor (gtk_text_view_get_buffer (view), &iter);
gtk_text_view_add_child_at_anchor (view, widget, anchor);
}
static void on_activate (GtkApplication *app) {
GtkWidget *window = gtk_application_window_new (app);
GtkWidget *sc = gtk_scrolled_window_new ();
GtkWidget *b = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
GtkTextView *view = GTK_TEXT_VIEW (gtk_text_view_new ());
gtk_box_append (GTK_BOX (b), gtk_label_new ("FOO"));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sc), GTK_WIDGET (view));
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (gtk_text_view_get_buffer (view)), "int main (string[] args) {\n\tvar foo = 1;\n}\n",-1);
add_anchor (view, ":int", 1, 9);
gtk_window_set_child (GTK_WINDOW (window), sc);
// gtk_text_view_set_gutter (view, GTK_TEXT_WINDOW_LEFT, b);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char *argv[]) {
// Create a new application
GtkApplication *app = gtk_application_new ("com.example.GtkApplication",
G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
return g_application_run (G_APPLICATION (app), argc, argv);
}
Compile using gcc repor.c $(pkgconf --cflags --libs gtk4)
.
Current behavior
Now, remove the comment from // gtk_text_view_set_gutter (view, GTK_TEXT_WINDOW_LEFT, b);
.
The result is:
You can see two issues: The label itself is moved to the left, and there is an additional empty space inserted, where the label should be
Expected outcome
I would expect, that the gutter does not move the position of the labels.
Version information
- 4.6.5, Fedora 36
- Flatpak version from
org.gnome.Sdk//master
Edited by JCWasmx86