[libdazzle] bolding-label: add convenience property
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] bolding-label: add convenience property
- Date: Sat, 24 Jun 2017 02:04:20 +0000 (UTC)
commit 05c3c05b295fc605633ce4942fa6dca79f5ecabb
Author: Christian Hergert <chergert redhat com>
Date: Fri Jun 23 19:04:09 2017 -0700
bolding-label: add convenience property
This is handy to use from g_object_bind_property() to set things bold.
Might as well add it here.
src/widgets/dzl-bolding-label.c | 48 +++++++++++++++++++++++++++++++++++++++
src/widgets/dzl-bolding-label.h | 2 +
2 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/widgets/dzl-bolding-label.c b/src/widgets/dzl-bolding-label.c
index cf94a88..b7a23e8 100644
--- a/src/widgets/dzl-bolding-label.c
+++ b/src/widgets/dzl-bolding-label.c
@@ -38,6 +38,14 @@ struct _DzlBoldingLabel
G_DEFINE_TYPE (DzlBoldingLabel, dzl_bolding_label, GTK_TYPE_LABEL)
+enum {
+ PROP_0,
+ PROP_BOLD,
+ N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
static void
dzl_bolding_label_get_preferred_width (GtkWidget *widget,
gint *min_width,
@@ -88,11 +96,42 @@ dzl_bolding_label_get_preferred_width (GtkWidget *widget,
}
static void
+dzl_bolding_label_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ DzlBoldingLabel *self = DZL_BOLDING_LABEL (object);
+
+ switch (prop_id)
+ {
+ case PROP_BOLD:
+ dzl_bolding_label_set_bold (self, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
dzl_bolding_label_class_init (DzlBoldingLabelClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = dzl_bolding_label_set_property;
widget_class->get_preferred_width = dzl_bolding_label_get_preferred_width;
+
+ properties [PROP_BOLD] =
+ g_param_spec_boolean ("bold",
+ "Bold",
+ "Set the bold weight for the label",
+ FALSE,
+ (G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
@@ -129,3 +168,12 @@ dzl_bolding_label_set_weight (DzlBoldingLabel *self,
gtk_widget_queue_draw (GTK_WIDGET (self));
pango_attr_list_unref (copy);
}
+
+void
+dzl_bolding_label_set_bold (DzlBoldingLabel *self,
+ gboolean bold)
+{
+ g_return_if_fail (DZL_IS_BOLDING_LABEL (self));
+
+ dzl_bolding_label_set_weight (self, bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
+}
diff --git a/src/widgets/dzl-bolding-label.h b/src/widgets/dzl-bolding-label.h
index 52bacc3..70a8591 100644
--- a/src/widgets/dzl-bolding-label.h
+++ b/src/widgets/dzl-bolding-label.h
@@ -29,6 +29,8 @@ G_DECLARE_FINAL_TYPE (DzlBoldingLabel, dzl_bolding_label, DZL, BOLDING_LABEL, Gt
void dzl_bolding_label_set_weight (DzlBoldingLabel *self,
PangoWeight weight);
+void dzl_bolding_label_set_bold (DzlBoldingLabel *self,
+ gboolean bold);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]