[gtk+/overlay: 29/34] Fix handling of subwidget-relative positioning in GtkOverlay
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/overlay: 29/34] Fix handling of subwidget-relative positioning in GtkOverlay
- Date: Sat, 11 Jun 2011 01:01:05 +0000 (UTC)
commit 0c7bc0bb6d25d759ee0f3325ff7c955f50656b8c
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jun 10 20:13:01 2011 -0400
Fix handling of subwidget-relative positioning in GtkOverlay
gtk/gtkoverlay.c | 68 +++++++++++++++++++++++++++--------------------------
1 files changed, 35 insertions(+), 33 deletions(-)
---
diff --git a/gtk/gtkoverlay.c b/gtk/gtkoverlay.c
index e912d6d..9211332 100644
--- a/gtk/gtkoverlay.c
+++ b/gtk/gtkoverlay.c
@@ -243,24 +243,31 @@ gtk_overlay_size_allocate (GtkWidget *widget,
if (priv->main_widget == NULL)
return;
- /* main widget allocation */
- main_alloc.x = allocation->x;
- main_alloc.y = allocation->y;
- main_alloc.width = allocation->width;
- main_alloc.height = allocation->height;
-
- gtk_widget_size_allocate (overlay->priv->main_widget, &main_alloc);
+ gtk_widget_size_allocate (priv->main_widget, allocation);
/* if a relative widget exists place the floating widgets in relation to it */
if (priv->relative_widget)
- gtk_widget_get_allocation (priv->relative_widget, &main_alloc);
+ {
+ gint x, y;
+
+ gtk_widget_translate_coordinates (priv->relative_widget, priv->main_widget, 0, 0, &x, &y);
+ main_alloc.x = allocation->x + x;
+ main_alloc.y = allocation->y + y;
+ main_alloc.width = gtk_widget_get_allocated_width (priv->relative_widget);
+ main_alloc.height = gtk_widget_get_allocated_height (priv->relative_widget);
+ }
+ else
+ {
+ main_alloc.x = allocation->x;
+ main_alloc.y = allocation->y;
+ main_alloc.width = allocation->width;
+ main_alloc.height = allocation->height;
+ }
for (children = priv->children; children; children = g_slist_next (children))
{
GtkRequisition req;
GtkAllocation alloc, child_alloc;
- guint x_offset, y_offset;
- GtkAlign halign, valign;
child = children->data;
@@ -269,48 +276,43 @@ gtk_overlay_size_allocate (GtkWidget *widget,
continue;
gtk_widget_get_preferred_size (child->widget, NULL, &req);
- halign = gtk_widget_get_halign (child->widget);
- valign = gtk_widget_get_valign (child->widget);
- x_offset = child->x_offset;
- y_offset = child->y_offset;
- switch (halign)
+ alloc.x = child->x_offset + main_alloc.x;
+ alloc.width = MIN (main_alloc.width, req.width);
+
+ switch (gtk_widget_get_halign (child->widget))
{
case GTK_ALIGN_START:
- alloc.x = x_offset;
+ case GTK_ALIGN_FILL:
+ /* nothing to do */
break;
case GTK_ALIGN_CENTER:
- alloc.x = MAX (main_alloc.x, main_alloc.width / 2 - req.width / 2 + x_offset);
+ alloc.x += main_alloc.width / 2 - req.width / 2;
break;
case GTK_ALIGN_END:
- alloc.x = MAX (main_alloc.x, main_alloc.width - req.width + x_offset);
+ alloc.x += main_alloc.width - req.width;
break;
- default:
- alloc.x = 0;
}
- switch (valign)
+ alloc.y = child->y_offset + main_alloc.y;
+ alloc.height = MIN (main_alloc.height, req.height);
+
+ switch (gtk_widget_get_valign (child->widget))
{
case GTK_ALIGN_START:
- alloc.y = y_offset;
+ case GTK_ALIGN_FILL:
+ /* nothing to do */
break;
case GTK_ALIGN_CENTER:
- alloc.y = MAX (main_alloc.y, main_alloc.height / 2 - req.height / 2 + y_offset);
+ alloc.y += main_alloc.height / 2 - req.height / 2;
break;
case GTK_ALIGN_END:
- alloc.y = MAX (main_alloc.y, main_alloc.height - req.height + y_offset);
- break;
- default:
- alloc.y = 0;
+ alloc.y += main_alloc.height - req.height;
break;
}
- alloc.x += allocation->x;
- alloc.y += allocation->y;
- alloc.width = MIN (main_alloc.width, req.width);
- alloc.height = MIN (main_alloc.height, req.height);
-
- child_alloc.x = child_alloc.y = 0;
+ child_alloc.x = 0;
+ child_alloc.y = 0;
child_alloc.width = alloc.width;
child_alloc.height = alloc.height;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]