diff options
author | Robert Tari <robert@tari.in> | 2020-09-05 22:35:17 +0200 |
---|---|---|
committer | Robert Tari <robert@tari.in> | 2020-09-05 22:35:17 +0200 |
commit | 73fd4da14bcd1c8e625f1d77bfa12dc8d612f4f3 (patch) | |
tree | 0db29a2fdb54db838d058b211f99c20e99095413 | |
parent | cba1c3cb8d17d0ea4058537c0c250f10d4170f33 (diff) | |
download | libayatana-indicator-73fd4da14bcd1c8e625f1d77bfa12dc8d612f4f3.tar.gz libayatana-indicator-73fd4da14bcd1c8e625f1d77bfa12dc8d612f4f3.tar.bz2 libayatana-indicator-73fd4da14bcd1c8e625f1d77bfa12dc8d612f4f3.zip |
indicator-ng.c: Fix padding and spacing for hidden indicator item labels
-rw-r--r-- | libayatana-indicator/indicator-ng.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/libayatana-indicator/indicator-ng.c b/libayatana-indicator/indicator-ng.c index 58cc2a6..ea5c3a8 100644 --- a/libayatana-indicator/indicator-ng.c +++ b/libayatana-indicator/indicator-ng.c @@ -524,19 +524,36 @@ indicator_ng_set_icon_from_variant (IndicatorNg *self, static void indicator_ng_set_label(IndicatorNg *self, const gchar *label) { - if (label == NULL || *label == '\0') + if (!self->entry.label) { - if (self->entry.label) - { - // Hiding the label also hides the image - set the label instead of gtk_widget_hide - gtk_label_set_label(GTK_LABEL (self->entry.label), NULL); - } - return; } - gtk_label_set_label(GTK_LABEL (self->entry.label), label); - gtk_widget_show(GTK_WIDGET (self->entry.label)); + const gchar *sLabel = label; + guint nSpacing = 3; + guint nPadding = 6; + + if (label == NULL || *label == '\0' || !self->entry.image || !gtk_widget_get_visible(GTK_WIDGET(self->entry.image))) + { + nSpacing = 0; + nPadding = 0; + } + + GtkWidget *pParent = gtk_widget_get_parent(GTK_WIDGET(self->entry.label)); + GtkCssProvider *pCssProvider = gtk_css_provider_new(); + GtkStyleContext *pStyleContext = gtk_widget_get_style_context(GTK_WIDGET(self->entry.label)); + gtk_style_context_add_provider(pStyleContext, GTK_STYLE_PROVIDER(pCssProvider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + gchar *sCss = g_strdup_printf("label{padding-left: %ipx;}", nPadding); + gtk_css_provider_load_from_data(pCssProvider, sCss, -1, NULL); + g_free(sCss); + g_object_unref(pCssProvider); + gtk_box_set_spacing(GTK_BOX(pParent), nSpacing); + gtk_label_set_label(GTK_LABEL (self->entry.label), sLabel); + + if (label) + { + gtk_widget_show(GTK_WIDGET (self->entry.label)); + } } static void |