diff console/libgnt/gntbox.c @ 13939:5d5c84239eea

[gaim-migrate @ 16470] Add an alignment option in a GntBox to align the widgets in it. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 09 Jul 2006 04:44:58 +0000
parents 917a71dd02eb
children 25be562aaca8
line wrap: on
line diff
--- a/console/libgnt/gntbox.c	Sun Jul 09 01:23:12 2006 +0000
+++ b/console/libgnt/gntbox.c	Sun Jul 09 04:44:58 2006 +0000
@@ -372,6 +372,10 @@
 	box->pad = 1;
 	gnt_widget_set_take_focus(widget, TRUE);
 	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
+	if (vert)
+		box->alignment = GNT_ALIGN_LEFT;
+	else
+		box->alignment = GNT_ALIGN_MID;
 
 	return widget;
 }
@@ -431,18 +435,42 @@
 	{
 		GntWidget *w = GNT_WIDGET(iter->data);
 		int height, width;
+		int x, y;
 
 		if (GNT_IS_BOX(w))
 			gnt_box_sync_children(GNT_BOX(w));
 
 		gnt_widget_get_size(w, &width, &height);
 
+		x = w->priv.x - widget->priv.x;
+		y = w->priv.y - widget->priv.y;
+
+		if (box->vertical)
+		{
+			if (box->alignment == GNT_ALIGN_RIGHT)
+				x += widget->priv.width - width;
+			else if (box->alignment == GNT_ALIGN_MID)
+				x += (widget->priv.width - width)/2;
+			if (x + width > widget->priv.width - 1)
+				x -= x + width - (widget->priv.width - 1);
+		}
+		else
+		{
+			if (box->alignment == GNT_ALIGN_BOTTOM)
+				y += widget->priv.height - height;
+			else if (box->alignment == GNT_ALIGN_MID)
+				y += (widget->priv.height - height)/2;
+			if (y + height > widget->priv.height - 1)
+				y -= y + height - (widget->priv.height - 1);
+		}
+
 		copywin(w->window, widget->window, 0, 0,
-				w->priv.y - widget->priv.y,
-				w->priv.x - widget->priv.x,
-				w->priv.y - widget->priv.y + height - 1,
-				w->priv.x - widget->priv.x + width - 1,
-				FALSE);
+				y, x, y + height - 1, x + width - 1, FALSE);
 	}
 }
 
+void gnt_box_set_alignment(GntBox *box, GntAlignment alignment)
+{
+	box->alignment = alignment;
+}
+