forked from AuroraMiddleware/gtk
GtkLabel: Drop use of GtkMisc::x/yalign
Instead, use GtkWidget::h/valign to position the text inside the allocation. And just stop using GtkMisc::x/ypad. https://bugzilla.gnome.org/show_bug.cgi?id=730613
This commit is contained in:
parent
0011c9dae4
commit
b320c198b6
@ -962,6 +962,7 @@ gtk_label_class_init (GtkLabelClass *class)
|
|||||||
G_MAXINT,
|
G_MAXINT,
|
||||||
-1,
|
-1,
|
||||||
GTK_PARAM_READWRITE));
|
GTK_PARAM_READWRITE));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Key bindings
|
* Key bindings
|
||||||
*/
|
*/
|
||||||
@ -3218,6 +3219,17 @@ gtk_label_get_measuring_layout (GtkLabel * label,
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_label_get_border (GtkLabel *label, GtkBorder *border)
|
||||||
|
{
|
||||||
|
GtkStyleContext *context;
|
||||||
|
GtkStateFlags state;
|
||||||
|
|
||||||
|
context = gtk_widget_get_style_context (GTK_WIDGET (label));
|
||||||
|
state = gtk_widget_get_state_flags (GTK_WIDGET (label));
|
||||||
|
gtk_style_context_get_border (context, state, border);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_label_update_layout_width (GtkLabel *label)
|
gtk_label_update_layout_width (GtkLabel *label)
|
||||||
{
|
{
|
||||||
@ -3232,9 +3244,7 @@ gtk_label_update_layout_width (GtkLabel *label)
|
|||||||
PangoRectangle logical;
|
PangoRectangle logical;
|
||||||
gint width, height;
|
gint width, height;
|
||||||
|
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
gtk_label_get_border (label, &border);
|
||||||
_gtk_misc_get_padding_and_border (GTK_MISC (label), &border);
|
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
||||||
|
|
||||||
width = gtk_widget_get_allocated_width (GTK_WIDGET (label)) - border.left - border.right;
|
width = gtk_widget_get_allocated_width (GTK_WIDGET (label)) - border.left - border.right;
|
||||||
height = gtk_widget_get_allocated_height (GTK_WIDGET (label)) - border.top - border.bottom;
|
height = gtk_widget_get_allocated_height (GTK_WIDGET (label)) - border.top - border.bottom;
|
||||||
@ -3651,9 +3661,7 @@ gtk_label_get_preferred_size (GtkWidget *widget,
|
|||||||
smallest_rect.width = PANGO_PIXELS_CEIL (smallest_rect.width);
|
smallest_rect.width = PANGO_PIXELS_CEIL (smallest_rect.width);
|
||||||
smallest_rect.height = PANGO_PIXELS_CEIL (smallest_rect.height);
|
smallest_rect.height = PANGO_PIXELS_CEIL (smallest_rect.height);
|
||||||
|
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
gtk_label_get_border (label, &border);
|
||||||
_gtk_misc_get_padding_and_border (GTK_MISC (label), &border);
|
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
||||||
|
|
||||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
{
|
{
|
||||||
@ -3757,9 +3765,7 @@ gtk_label_get_preferred_width_for_height (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkBorder border;
|
GtkBorder border;
|
||||||
|
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
gtk_label_get_border (label, &border);
|
||||||
_gtk_misc_get_padding_and_border (GTK_MISC (label), &border);
|
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
||||||
|
|
||||||
if (priv->wrap)
|
if (priv->wrap)
|
||||||
gtk_label_clear_layout (label);
|
gtk_label_clear_layout (label);
|
||||||
@ -3794,9 +3800,7 @@ gtk_label_get_preferred_height_and_baseline_for_width (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkBorder border;
|
GtkBorder border;
|
||||||
|
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
gtk_label_get_border (label, &border);
|
||||||
_gtk_misc_get_padding_and_border (GTK_MISC (label), &border);
|
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
||||||
|
|
||||||
if (priv->wrap)
|
if (priv->wrap)
|
||||||
gtk_label_clear_layout (label);
|
gtk_label_clear_layout (label);
|
||||||
@ -3922,6 +3926,60 @@ gtk_label_style_updated (GtkWidget *widget)
|
|||||||
gtk_label_update_layout_attributes (label);
|
gtk_label_update_layout_attributes (label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gfloat
|
||||||
|
halign_to_float (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
gfloat ret = 0.5;
|
||||||
|
|
||||||
|
switch (gtk_widget_get_halign (widget))
|
||||||
|
{
|
||||||
|
case GTK_ALIGN_FILL:
|
||||||
|
case GTK_ALIGN_CENTER:
|
||||||
|
ret = 0.5;
|
||||||
|
break;
|
||||||
|
case GTK_ALIGN_START:
|
||||||
|
ret = 0.0;
|
||||||
|
break;
|
||||||
|
case GTK_ALIGN_END:
|
||||||
|
ret = 1.0;
|
||||||
|
break;
|
||||||
|
case GTK_ALIGN_BASELINE:
|
||||||
|
ret = 0.0;
|
||||||
|
g_assert_not_reached ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
|
||||||
|
ret = 1.0 - ret;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gfloat
|
||||||
|
valign_to_float (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
gfloat ret = 0.5;
|
||||||
|
|
||||||
|
switch (gtk_widget_get_valign (widget))
|
||||||
|
{
|
||||||
|
case GTK_ALIGN_FILL:
|
||||||
|
case GTK_ALIGN_CENTER:
|
||||||
|
ret = 0.5;
|
||||||
|
break;
|
||||||
|
case GTK_ALIGN_START:
|
||||||
|
ret = 0.0;
|
||||||
|
break;
|
||||||
|
case GTK_ALIGN_END:
|
||||||
|
ret = 1.0;
|
||||||
|
break;
|
||||||
|
case GTK_ALIGN_BASELINE:
|
||||||
|
ret = 0.0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_layout_location (GtkLabel *label,
|
get_layout_location (GtkLabel *label,
|
||||||
gint *xp,
|
gint *xp,
|
||||||
@ -3940,13 +3998,10 @@ get_layout_location (GtkLabel *label,
|
|||||||
widget = GTK_WIDGET (label);
|
widget = GTK_WIDGET (label);
|
||||||
priv = label->priv;
|
priv = label->priv;
|
||||||
|
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
gtk_label_get_border (label, &border);
|
||||||
gtk_misc_get_alignment (GTK_MISC (label), &xalign, &yalign);
|
|
||||||
_gtk_misc_get_padding_and_border (GTK_MISC (label), &border);
|
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
||||||
|
|
||||||
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
|
xalign = halign_to_float (widget);
|
||||||
xalign = 1.0 - xalign;
|
yalign = valign_to_float (widget);
|
||||||
|
|
||||||
pango_layout_get_extents (priv->layout, NULL, &logical);
|
pango_layout_get_extents (priv->layout, NULL, &logical);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user