2

Below is what should be a reproducible example of the code that doesn't work. It's based on the introduction sample from the GTK documentation. I am using v4.8.3 of Gtk and v1.50.12 of Pango.

#include <gtk/gtk.h>

static void activate(GtkApplication *app, gpointer) {
    ///////////////////////////
    // -- Attribute Setup -- //
    ///////////////////////////

    PangoAttrList *attributes;
    PangoAttribute *background_color;
    PangoAttribute *strikethrough;

    background_color = pango_attr_background_new(UINT16_MAX * 0.5, UINT16_MAX * 0.5, 0);
    strikethrough = pango_attr_strikethrough_new(TRUE);

    attributes = pango_attr_list_new();
    pango_attr_list_insert(attributes, background_color);
    pango_attr_list_insert(attributes, strikethrough);

    ////////////////////////////////
    // -- Widget Configuration -- //
    ////////////////////////////////

    GtkWidget *window;
    GtkWidget *label;

    label = gtk_label_new(NULL);
    gtk_label_set_markup(GTK_LABEL(label), "This is a label!");
    gtk_label_set_attributes(GTK_LABEL(label), attributes);

    window = gtk_application_window_new(app);
    gtk_window_set_title(GTK_WINDOW(window), "Strikethrough");
    gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
    gtk_window_set_child(GTK_WINDOW(window), label);
    gtk_widget_show(window);
}

int main(int argc, char **argv) {
    GtkApplication *app;
    int status;

    app = gtk_application_new("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    status = g_application_run(G_APPLICATION(app), argc, argv);
    g_object_unref(app);

    return status;
}

The result looks like this:

enter image description here

I would expect the label to be strikethrough. What's interesting, though, is if I add a little markup to the label and make part of the text "small", the label is strikethough:

gtk_label_set_markup(GTK_LABEL(label), "This <small>is a</small> label!");

enter image description here

Of course, that's not a solution as I don't want my text to look strange just to have strikethrough. I have tested setting the "strikethrough" property directly in a UI file like this:

<object class="GtkLabel" id="content_label">
  <attributes>
    <attribute name="strikethrough" value="true" />
  </attributes>
  <property name="margin-top">12</property>
  <property name="margin-bottom">12</property>
  <property name="margin-start">12</property>
  <property name="margin-end">12</property>
</object>

And the same issue applies. So I suppose my question is, am I doing something wrong, or is GTK misbehaving in this aspect?

rburmorrison
  • 612
  • 4
  • 12

0 Answers0