Commit d39424fc authored by Matthias Clasen's avatar Matthias Clasen

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
parent c2330e7f
......@@ -2085,6 +2085,8 @@ gtk_label_set_markup
gtk_label_set_markup_with_mnemonic
gtk_label_set_pattern
gtk_label_set_justify
gtk_label_set_xalign
gtk_label_set_yalign
gtk_label_set_ellipsize
gtk_label_set_width_chars
gtk_label_set_max_width_chars
......@@ -2102,6 +2104,8 @@ gtk_label_set_selectable
gtk_label_set_text_with_mnemonic
gtk_label_get_attributes
gtk_label_get_justify
gtk_label_get_xalign
gtk_label_get_yalign
gtk_label_get_ellipsize
gtk_label_get_width_chars
gtk_label_get_max_width_chars
......
......@@ -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;
}
......@@ -213,6 +213,19 @@ void gtk_label_set_track_visited_links (GtkLabel *label,
GDK_AVAILABLE_IN_ALL
gboolean gtk_label_get_track_visited_links (GtkLabel *label);
GDK_AVAILABLE_IN_3_16
void gtk_label_set_xalign (GtkLabel *label,
gfloat xalign);
GDK_AVAILABLE_IN_3_16
gfloat gtk_label_get_xalign (GtkLabel *label);
GDK_AVAILABLE_IN_3_16
void gtk_label_set_yalign (GtkLabel *label,
gfloat xalign);
GDK_AVAILABLE_IN_3_16
gfloat gtk_label_get_yalign (GtkLabel *label);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment