[gtk+/wip/baseline3: 9/17] GtkButton: Add baseline align support
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baseline3: 9/17] GtkButton: Add baseline align support
- Date: Tue, 26 Mar 2013 15:40:08 +0000 (UTC)
commit 0f16dbed5280f1e8b9f01139b9de770b432f29b6
Author: Alexander Larsson <alexl redhat com>
Date: Thu Mar 7 13:53:16 2013 +0100
GtkButton: Add baseline align support
gtk/gtkbutton.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 57 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 3ac36a7..4189fc9 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -170,6 +170,12 @@ static void gtk_button_get_preferred_width (GtkWidget *widget,
static void gtk_button_get_preferred_height (GtkWidget *widget,
gint *minimum_size,
gint *natural_size);
+static void gtk_button_get_preferred_height_and_baseline_for_width (GtkWidget *widget,
+ gint width,
+ gint *minimum_size,
+ gint *natural_size,
+ gint *minimum_baseline,
+ gint *natural_baseline);
static guint button_signals[LAST_SIGNAL] = { 0 };
@@ -196,6 +202,7 @@ gtk_button_class_init (GtkButtonClass *klass)
widget_class->get_preferred_width = gtk_button_get_preferred_width;
widget_class->get_preferred_height = gtk_button_get_preferred_height;
+ widget_class->get_preferred_height_and_baseline_for_width =
gtk_button_get_preferred_height_and_baseline_for_width;
widget_class->destroy = gtk_button_destroy;
widget_class->screen_changed = gtk_button_screen_changed;
widget_class->realize = gtk_button_realize;
@@ -1150,11 +1157,16 @@ gtk_button_construct_child (GtkButton *button)
else
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, image_spacing);
+ gtk_widget_set_valign (image, GTK_ALIGN_BASELINE);
+ gtk_widget_set_valign (box, GTK_ALIGN_BASELINE);
+
if (priv->align_set)
align = gtk_alignment_new (priv->xalign, priv->yalign, 0.0, 0.0);
else
align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+ gtk_widget_set_valign (align, GTK_ALIGN_BASELINE);
+
if (priv->image_position == GTK_POS_LEFT ||
priv->image_position == GTK_POS_TOP)
gtk_box_pack_start (GTK_BOX (box), priv->image, FALSE, FALSE, 0);
@@ -1172,6 +1184,8 @@ gtk_button_construct_child (GtkButton *button)
else
label = gtk_label_new (label_text);
+ gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
+
if (priv->image_position == GTK_POS_RIGHT ||
priv->image_position == GTK_POS_BOTTOM)
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
@@ -1196,6 +1210,8 @@ gtk_button_construct_child (GtkButton *button)
else
label = gtk_label_new (priv->label_text);
+ gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
+
if (priv->align_set)
gtk_misc_set_alignment (GTK_MISC (label), priv->xalign, priv->yalign);
@@ -1584,6 +1600,7 @@ gtk_button_size_allocate (GtkWidget *widget,
GtkBorder border;
gint focus_width;
gint focus_pad;
+ gint baseline;
context = gtk_widget_get_style_context (widget);
@@ -1635,6 +1652,10 @@ gtk_button_size_allocate (GtkWidget *widget,
child_allocation.height = child_allocation.height - (focus_width + focus_pad) * 2;
}
+ baseline = gtk_widget_get_allocated_baseline (widget);
+ if (baseline != -1)
+ baseline -= child_allocation.y - allocation->y;
+
if (priv->depressed)
{
gint child_displacement_x;
@@ -1651,7 +1672,7 @@ gtk_button_size_allocate (GtkWidget *widget,
child_allocation.width = MAX (1, child_allocation.width);
child_allocation.height = MAX (1, child_allocation.height);
- gtk_widget_size_allocate (child, &child_allocation);
+ gtk_widget_size_allocate_with_baseline (child, &child_allocation, baseline);
}
}
@@ -2063,7 +2084,9 @@ static void
gtk_button_get_size (GtkWidget *widget,
GtkOrientation orientation,
gint *minimum_size,
- gint *natural_size)
+ gint *natural_size,
+ gint *minimum_baseline,
+ gint *natural_baseline)
{
GtkButton *button = GTK_BUTTON (widget);
GtkStyleContext *context;
@@ -2074,6 +2097,7 @@ gtk_button_get_size (GtkWidget *widget,
gint focus_width;
gint focus_pad;
gint minimum, natural;
+ gint top_offset;
context = gtk_widget_get_style_context (widget);
@@ -2084,6 +2108,8 @@ gtk_button_get_size (GtkWidget *widget,
"focus-padding", &focus_pad,
NULL);
+ top_offset = 0;
+
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
minimum = padding.left + padding.right +
@@ -2097,9 +2123,14 @@ gtk_button_get_size (GtkWidget *widget,
minimum = padding.top + padding.bottom +
border.top + border.bottom;
+ top_offset = padding.top + border.top + focus_width + focus_pad;
+
if (gtk_widget_get_can_default (GTK_WIDGET (widget)))
- minimum += default_border.top + default_border.bottom;
- }
+ {
+ minimum += default_border.top + default_border.bottom;
+ top_offset += default_border.top;
+ }
+ }
minimum += 2 * (focus_width + focus_pad);
natural = minimum;
@@ -2108,11 +2139,17 @@ gtk_button_get_size (GtkWidget *widget,
gtk_widget_get_visible (child))
{
gint child_min, child_nat;
+ gint child_min_baseline = -1, child_nat_baseline = -1;
if (orientation == GTK_ORIENTATION_HORIZONTAL)
gtk_widget_get_preferred_width (child, &child_min, &child_nat);
else
- gtk_widget_get_preferred_height (child, &child_min, &child_nat);
+ gtk_widget_get_preferred_height_and_baseline_for_width (child, -1, &child_min, &child_nat,
&child_min_baseline, &child_nat_baseline);
+
+ if (minimum_baseline && child_min_baseline >= 0)
+ *minimum_baseline = child_min_baseline + top_offset;
+ if (natural_baseline && child_nat_baseline >= 0)
+ *natural_baseline = child_nat_baseline + top_offset;
minimum += child_min;
natural += child_nat;
@@ -2130,7 +2167,7 @@ gtk_button_get_preferred_width (GtkWidget *widget,
gint *minimum_size,
gint *natural_size)
{
- gtk_button_get_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
+ gtk_button_get_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size, NULL, NULL);
}
static void
@@ -2138,7 +2175,20 @@ gtk_button_get_preferred_height (GtkWidget *widget,
gint *minimum_size,
gint *natural_size)
{
- gtk_button_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
+ gtk_button_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size, NULL, NULL);
+}
+
+static void
+gtk_button_get_preferred_height_and_baseline_for_width (GtkWidget *widget,
+ gint width,
+ gint *minimum_size,
+ gint *natural_size,
+ gint *minimum_baseline,
+ gint *natural_baseline)
+{
+ /* GtkButton is GTK_SIZE_REQUEST_CONSTANT mode, so width will be -1 all the time */
+ g_assert (width == -1);
+ gtk_button_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size, minimum_baseline,
natural_baseline);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]