summaryrefslogtreecommitdiff
path: root/gtk/gtklabel.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2014-09-15 23:17:11 -0400
committerMatthias Clasen <mclasen@redhat.com>2014-09-29 23:56:20 -0400
commitd39424fc1c0f7d876ccd9632f3b16d7a67aed290 (patch)
tree82b42a11a8f0d09d96f699df1faf0174529a18e4 /gtk/gtklabel.c
parentc2330e7fd167618e9ec2c7f8137e545e328805f1 (diff)
downloadgtk+-d39424fc1c0f7d876ccd9632f3b16d7a67aed290.tar.gz
GtkLabel: add x/yalign properties
Since it turns out that x/yalign can't be quite equivalently replaced by h/valign, bring them back as label properties, so we can eventually get rid of GtkMisc. https://bugzilla.gnome.org/show_bug.cgi?id=735841
Diffstat (limited to 'gtk/gtklabel.c')
-rw-r--r--gtk/gtklabel.c151
1 files changed, 148 insertions, 3 deletions
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 2c9e00774e..024db06884 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -238,6 +238,8 @@ struct _GtkLabelPrivate
gchar *text;
gdouble angle;
+ gfloat xalign;
+ gfloat yalign;
guint mnemonics_visible : 1;
guint jtype : 2;
@@ -345,7 +347,9 @@ enum {
PROP_ANGLE,
PROP_MAX_WIDTH_CHARS,
PROP_TRACK_VISITED_LINKS,
- PROP_LINES
+ PROP_LINES,
+ PROP_XALIGN,
+ PROP_YALIGN
};
/* When rotating ellipsizable text we want the natural size to request
@@ -754,11 +758,47 @@ gtk_label_class_init (GtkLabelClass *class)
PROP_JUSTIFY,
g_param_spec_enum ("justify",
P_("Justification"),
- P_("The alignment of the lines in the text of the label relative to each other. This does NOT affect the alignment of the label within its allocation. See GtkMisc::xalign for that"),
+ P_("The alignment of the lines in the text of the label relative to each other. This does NOT affect the alignment of the label within its allocation. See GtkLabel:xalign for that"),
GTK_TYPE_JUSTIFICATION,
GTK_JUSTIFY_LEFT,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+ /**
+ * GtkLabel:xalign:
+ *
+ * The xalign property determines the horizontal aligment of the label text
+ * inside the labels size allocation. Compare this to #GtkWidget:halign,
+ * which determines how the labels size allocation is positioned in the
+ * space available for the label.
+ *
+ * Since: 3.16
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_XALIGN,
+ g_param_spec_float ("xalign",
+ P_("X align"),
+ P_("The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
+ 0.0, 1.0, 0.5,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+
+ /**
+ * GtkLabel:yalign:
+ *
+ * The yalign property determines the vertical aligment of the label text
+ * inside the labels size allocation. Compare this to #GtkWidget:valign,
+ * which determines how the labels size allocation is positioned in the
+ * space available for the label.
+ *
+ * Since: 3.16
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_YALIGN,
+ g_param_spec_float ("yalign",
+ P_("Y align"),
+ P_("The vertical alignment, from 0 (top) to 1 (bottom)"),
+ 0.0, 1.0, 0.5,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+
g_object_class_install_property (gobject_class,
PROP_PATTERN,
g_param_spec_string ("pattern",
@@ -1162,6 +1202,12 @@ gtk_label_set_property (GObject *object,
case PROP_LINES:
gtk_label_set_lines (label, g_value_get_int (value));
break;
+ case PROP_XALIGN:
+ gtk_label_set_xalign (label, g_value_get_float (value));
+ break;
+ case PROP_YALIGN:
+ gtk_label_set_yalign (label, g_value_get_float (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1236,6 +1282,12 @@ gtk_label_get_property (GObject *object,
case PROP_LINES:
g_value_set_int (value, gtk_label_get_lines (label));
break;
+ case PROP_XALIGN:
+ g_value_set_float (value, gtk_label_get_xalign (label));
+ break;
+ case PROP_YALIGN:
+ g_value_set_float (value, gtk_label_get_yalign (label));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1257,6 +1309,9 @@ gtk_label_init (GtkLabel *label)
priv->label = NULL;
priv->lines = -1;
+ priv->xalign = 0.5;
+ priv->yalign = 0.5;
+
priv->jtype = GTK_JUSTIFY_LEFT;
priv->wrap = FALSE;
priv->wrap_mode = PANGO_WRAP_WORD;
@@ -3888,8 +3943,10 @@ get_layout_location (GtkLabel *label,
widget = GTK_WIDGET (label);
priv = label->priv;
+ xalign = priv->xalign;
+ yalign = priv->yalign;
+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_misc_get_alignment (GTK_MISC (label), &xalign, &yalign);
_gtk_misc_get_padding_and_border (GTK_MISC (label), &border);
G_GNUC_END_IGNORE_DEPRECATIONS
@@ -7023,3 +7080,91 @@ _gtk_label_get_link_focused (GtkLabel *label,
return FALSE;
}
+
+/**
+ * gtk_label_set_xalign:
+ * @label: a #GtkLabel
+ * @xalign: the new xalign value, between 0 and 1
+ *
+ * Sets the #GtkLabel:xalign property for @label.
+ *
+ * Since: 3.16
+ */
+void
+gtk_label_set_xalign (GtkLabel *label,
+ gfloat xalign)
+{
+ g_return_if_fail (GTK_IS_LABEL (label));
+
+ xalign = CLAMP (xalign, 0.0, 1.0);
+
+ if (label->priv->xalign == xalign)
+ return;
+
+ label->priv->xalign = xalign;
+
+ gtk_widget_queue_draw (GTK_WIDGET (label));
+ g_object_notify (G_OBJECT (label), "xalign");
+}
+
+/**
+ * gtk_label_get_xalign:
+ * @label: a #GtkLabel
+ *
+ * Gets the #GtkLabel:xalign property for @label.
+ *
+ * Returns: the xalign property
+ *
+ * Since: 3.16
+ */
+gfloat
+gtk_label_get_xalign (GtkLabel *label)
+{
+ g_return_val_if_fail (GTK_IS_LABEL (label), 0.5);
+
+ return label->priv->xalign;
+}
+
+/**
+ * gtk_label_set_yalign:
+ * @label: a #GtkLabel
+ * @xalign: the new yalign value, between 0 and 1
+ *
+ * Sets the #GtkLabel:yalign property for @label.
+ *
+ * Since: 3.16
+ */
+void
+gtk_label_set_yalign (GtkLabel *label,
+ gfloat yalign)
+{
+ g_return_if_fail (GTK_IS_LABEL (label));
+
+ yalign = CLAMP (yalign, 0.0, 1.0);
+
+ if (label->priv->yalign == yalign)
+ return;
+
+ label->priv->yalign = yalign;
+
+ gtk_widget_queue_draw (GTK_WIDGET (label));
+ g_object_notify (G_OBJECT (label), "yalign");
+}
+
+/**
+ * gtk_label_get_yalign:
+ * @label: a #GtkLabel
+ *
+ * Gets the #GtkLabel:yalign property for @label.
+ *
+ * Returns: the yalign property
+ *
+ * Since: 3.16
+ */
+gfloat
+gtk_label_get_yalign (GtkLabel *label)
+{
+ g_return_val_if_fail (GTK_IS_LABEL (label), 0.5);
+
+ return label->priv->yalign;
+}