[gtk+/extended-layout-jhs: 32/64] Propagate baseline offset to the child widget. Properly apply baseline
- From: Johannes Schmid <jhs src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtk+/extended-layout-jhs: 32/64] Propagate baseline offset to the child widget. Properly apply baseline
- Date: Wed, 25 Nov 2009 11:21:36 +0000 (UTC)
commit 21c99aa99a5283eecaf755b17662b777e3ce8875
Author: Mathias Hasselmann <mathias hasselmann gmx de>
Date: Wed Jul 11 12:24:25 2007 +0000
Propagate baseline offset to the child widget. Properly apply baseline
2007-07-04 Mathias Hasselmann <mathias hasselmann gmx de>
* gtk/gtkbin.c: Propagate baseline offset to the child widget.
* gtk/gtkhbox.c: Properly apply baseline alignment by using the
baseline found during requisition calculation for size allocation.
* tests/testextendedlayout.c: Add yscale variantes of GtkAlignment
to the baseline tests. Improve widget names. Split status message
into two lines.
svn path=/branches/extended-layout/; revision=18444
ChangeLog.gtk-extended-layout | 9 +++++++
gtk/gtkbin.c | 20 ++++++++++++++++
gtk/gtkhbox.c | 49 ++++++++++++++++------------------------
tests/testextendedlayout.c | 26 ++++++++++++---------
4 files changed, 64 insertions(+), 40 deletions(-)
---
diff --git a/ChangeLog.gtk-extended-layout b/ChangeLog.gtk-extended-layout
index bd60ef2..5f0ee4a 100644
--- a/ChangeLog.gtk-extended-layout
+++ b/ChangeLog.gtk-extended-layout
@@ -1,3 +1,12 @@
+2007-07-04 Mathias Hasselmann <mathias hasselmann gmx de>
+
+ * gtk/gtkbin.c: Propagate baseline offset to the child widget.
+ * gtk/gtkhbox.c: Properly apply baseline alignment by using the
+ baseline found during requisition calculation for size allocation.
+ * tests/testextendedlayout.c: Add yscale variantes of GtkAlignment
+ to the baseline tests. Improve widget names. Split status message
+ into two lines.
+
2007-07-03 Mathias Hasselmann <mathias hasselmann gmx de>
* tests/testextendedlayout.c: Allow choosing initially active
diff --git a/gtk/gtkbin.c b/gtk/gtkbin.c
index a7ffce2..068931a 100644
--- a/gtk/gtkbin.c
+++ b/gtk/gtkbin.c
@@ -245,6 +245,25 @@ gtk_bin_extended_layout_get_baselines (GtkExtendedLayout *layout,
}
static void
+gtk_bin_extended_layout_set_baseline_offset (GtkExtendedLayout *layout,
+ gint offset)
+{
+ GtkBin *bin = GTK_BIN (layout);
+
+ g_return_if_fail (GTK_IS_EXTENDED_LAYOUT (bin->child));
+
+ if (GTK_EXTENDED_LAYOUT_HAS_PADDING (layout))
+ {
+ GtkBorder padding;
+
+ gtk_extended_layout_get_padding (layout, &padding);
+ offset -= padding.top;
+ }
+
+ gtk_extended_layout_set_baseline_offset (GTK_EXTENDED_LAYOUT (bin->child), offset);
+}
+
+static void
gtk_bin_extended_layout_interface_init (GtkExtendedLayoutIface *iface)
{
iface->get_features = gtk_bin_extended_layout_get_features;
@@ -252,6 +271,7 @@ gtk_bin_extended_layout_interface_init (GtkExtendedLayoutIface *iface)
iface->get_width_for_height = gtk_bin_extended_layout_get_width_for_height;
iface->get_natural_size = gtk_bin_extended_layout_get_natural_size;
iface->get_baselines = gtk_bin_extended_layout_get_baselines;
+ iface->set_baseline_offset = gtk_bin_extended_layout_set_baseline_offset;
}
#define __GTK_BIN_C__
diff --git a/gtk/gtkhbox.c b/gtk/gtkhbox.c
index 683fd36..6ce6d41 100644
--- a/gtk/gtkhbox.c
+++ b/gtk/gtkhbox.c
@@ -43,6 +43,7 @@ typedef struct _GtkHBoxPrivate GtkHBoxPrivate;
struct _GtkHBoxPrivate
{
GtkBaselinePolicy baseline_policy;
+ gint baseline;
};
static void gtk_hbox_set_property (GObject *object,
@@ -173,12 +174,13 @@ gtk_hbox_size_request (GtkWidget *widget,
if (nvis_children > 0)
{
GtkHBoxPrivate *priv = GTK_HBOX_GET_PRIVATE (widget);
- gint effective_baseline = 0, i;
gint *baselines = NULL;
+ gint i;
if (priv->baseline_policy != GTK_BASELINE_NONE)
{
baselines = g_newa (gint, nvis_children);
+ priv->baseline = 0;
i = 0;
children = box->children;
@@ -196,8 +198,7 @@ gtk_hbox_size_request (GtkWidget *widget,
gtk_extended_layout_set_baseline_offset (layout, 0);
baselines[i] = gtk_extended_layout_get_single_baseline (layout, priv->baseline_policy);
-
- effective_baseline = MAX (effective_baseline, baselines[i]);
+ priv->baseline = MAX (priv->baseline, baselines[i]);
}
else
baselines[i] = 0;
@@ -233,7 +234,7 @@ gtk_hbox_size_request (GtkWidget *widget,
if (baselines)
{
- gint padding = MAX (effective_baseline - baselines[i], 0);
+ gint padding = MAX (priv->baseline - baselines[i], 0);
child_requisition.height += padding;
}
@@ -288,9 +289,7 @@ gtk_hbox_size_allocate (GtkWidget *widget,
{
GtkHBoxPrivate *priv = GTK_HBOX_GET_PRIVATE (widget);
- gint effective_baseline;
GtkPackType packing;
- gint *baselines;
GtkTextDirection direction;
gint border_width;
@@ -370,9 +369,6 @@ gtk_hbox_size_allocate (GtkWidget *widget,
extra = 0;
}
- effective_baseline = 0;
- baselines = g_newa (gint, nvis_children);
-
child_allocation.y = allocation->y + border_width;
child_allocation.height = MAX (1, (gint) allocation->height - (gint) border_width * 2);
@@ -446,20 +442,6 @@ gtk_hbox_size_allocate (GtkWidget *widget,
gtk_widget_size_allocate (child->widget, &child_allocation);
- if (GTK_BASELINE_NONE != priv->baseline_policy &&
- GTK_IS_EXTENDED_LAYOUT (child->widget) &&
- GTK_EXTENDED_LAYOUT_HAS_BASELINES (child->widget))
- {
- GtkExtendedLayout *layout = GTK_EXTENDED_LAYOUT (child->widget);
-
- gtk_extended_layout_set_baseline_offset (layout, 0);
- baselines[i] = gtk_extended_layout_get_single_baseline (layout, priv->baseline_policy);
-
- effective_baseline = MAX (effective_baseline, baselines[i]);
- }
- else
- baselines[i] = 0;
-
if (GTK_PACK_START == packing)
x += child_width + box->spacing;
else
@@ -480,14 +462,23 @@ gtk_hbox_size_allocate (GtkWidget *widget,
child = children->data;
children = children->next;
- if (GTK_IS_EXTENDED_LAYOUT (child->widget) &&
- GTK_EXTENDED_LAYOUT_HAS_BASELINES (child->widget))
+ if (GTK_WIDGET_VISIBLE (child->widget))
{
- gint dy = MAX (0, effective_baseline - baselines[i]);
- gtk_extended_layout_set_baseline_offset (GTK_EXTENDED_LAYOUT (child->widget), dy);
- }
+ if (GTK_IS_EXTENDED_LAYOUT (child->widget) &&
+ GTK_EXTENDED_LAYOUT_HAS_BASELINES (child->widget))
+ {
+ GtkExtendedLayout *layout = GTK_EXTENDED_LAYOUT (child->widget);
+ gint baseline, dy;
- ++i;
+ gtk_extended_layout_set_baseline_offset (layout, 0);
+ baseline = gtk_extended_layout_get_single_baseline (layout, priv->baseline_policy);
+ dy = priv->baseline - baseline;
+
+ gtk_extended_layout_set_baseline_offset (layout, dy);
+ }
+
+ ++i;
+ }
}
} /* baseline_policy */
} /* nvis_children */
diff --git a/tests/testextendedlayout.c b/tests/testextendedlayout.c
index 407de64..72612c0 100644
--- a/tests/testextendedlayout.c
+++ b/tests/testextendedlayout.c
@@ -539,7 +539,7 @@ create_baseline_test_hbox (TestSuite *suite,
hbox = gtk_hbox_new (FALSE, 6);
test_case_append_guide (test, hbox, GUIDE_EXTERIOUR_BOTH, -1);
- set_widget_name (hbox, "debug-hbox-%s", names[i]);
+ set_widget_name (hbox, "hbox-%s", names[i]);
if (i > 0)
gtk_hbox_set_baseline_policy (GTK_HBOX (hbox), GTK_BASELINE_FIRST);
@@ -551,10 +551,10 @@ create_baseline_test_hbox (TestSuite *suite,
1, G_N_ELEMENTS (captions), i, i + 1,
GTK_FILL, GTK_FILL, 0, 0);
- for (j = 0; captions[j]; ++j)
+ for (j = i ? -3 : 0; captions[MAX (0, j)]; ++j)
{
child = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (child), captions[j]);
+ gtk_label_set_markup (GTK_LABEL (child), captions[MAX (0, j)]);
if (buttons)
{
@@ -565,10 +565,13 @@ create_baseline_test_hbox (TestSuite *suite,
test_case_append_guide (test, child, GUIDE_BASELINE, i);
- if (0 == j && i > 1)
+ if (j < 0 && i > 1)
{
- bin = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
- set_widget_name (hbox, "debug-align-%s-%s", buttons ? "button" : "label", names[i]);
+ bin = gtk_alignment_new (0.5, 0.5, 0.0, (j + 3) * 0.5);
+
+ set_widget_name (bin, "align-%s-%s-%d",
+ buttons ? "button" : "label",
+ names[i], (j + 3) * 50);
switch (i)
{
@@ -1351,13 +1354,13 @@ update_status (TestSuite *suite,
{
const gchar *widget_name = gtk_widget_get_name (child);
const gchar *type_name = G_OBJECT_TYPE_NAME (child);
- GString *status = g_string_new (widget_name);
+ GString *status = g_string_new (type_name);
if (strcmp (widget_name, type_name))
- g_string_append_printf (status, " (%s)", type_name);
+ g_string_append_printf (status, " (%s)", widget_name);
g_string_append_printf (status,
- ": pos=%dx%d; size=%dx%d",
+ ":\npos=%dx%d; size=%dx%d",
child->allocation.x,
child->allocation.y,
child->allocation.width,
@@ -1470,7 +1473,7 @@ watch_pointer_cb (gpointer data)
if (suite->current)
gtk_label_set_text (GTK_LABEL (suite->statusbar),
- "No widget selected.");
+ "No widget selected.\n");
suite->current = NULL;
}
@@ -1606,7 +1609,8 @@ test_suite_setup_ui (TestSuite *self)
G_CALLBACK (gtk_widget_queue_draw),
self->notebook);
- self->statusbar = gtk_label_new ("No widget selected.");
+ self->statusbar = gtk_label_new ("No widget selected.\n");
+ gtk_misc_set_alignment (GTK_MISC (self->statusbar), 0.0, 0.5);
gtk_label_set_ellipsize (GTK_LABEL (self->statusbar),
PANGO_ELLIPSIZE_END);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]