From: <sa...@us...> - 2006-07-09 04:45:07
|
Revision: 16470 Author: sadrul Date: 2006-07-08 21:44:58 -0700 (Sat, 08 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16470&view=rev Log Message: ----------- Add an alignment option in a GntBox to align the widgets in it. Modified Paths: -------------- trunk/console/libgnt/gntbox.c trunk/console/libgnt/gntbox.h trunk/console/libgnt/test/combo.c Modified: trunk/console/libgnt/gntbox.c =================================================================== --- trunk/console/libgnt/gntbox.c 2006-07-09 01:23:12 UTC (rev 16469) +++ trunk/console/libgnt/gntbox.c 2006-07-09 04:44:58 UTC (rev 16470) @@ -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; +} + Modified: trunk/console/libgnt/gntbox.h =================================================================== --- trunk/console/libgnt/gntbox.h 2006-07-09 01:23:12 UTC (rev 16469) +++ trunk/console/libgnt/gntbox.h 2006-07-09 04:44:58 UTC (rev 16470) @@ -14,6 +14,19 @@ typedef struct _GnBox GntBox; typedef struct _GnBoxClass GntBoxClass; +typedef enum +{ + /* These for vertical boxes */ + GNT_ALIGN_LEFT, + GNT_ALIGN_RIGHT, + + GNT_ALIGN_MID, + + /* These for horizontal boxes */ + GNT_ALIGN_TOP, + GNT_ALIGN_BOTTOM +} GntAlignment; + struct _GnBox { GntWidget parent; @@ -24,6 +37,7 @@ GntWidget *active; int pad; /* Number of spaces to use between widgets */ + GntAlignment alignment; /* How are the widgets going to be aligned? */ char *title; GList *focus; /* List of widgets to cycle focus (only valid for parent boxes) */ @@ -60,6 +74,8 @@ void gnt_box_sync_children(GntBox *box); +void gnt_box_set_alignment(GntBox *box, GntAlignment alignment); + G_END_DECLS #endif /* GNT_BOX_H */ Modified: trunk/console/libgnt/test/combo.c =================================================================== --- trunk/console/libgnt/test/combo.c 2006-07-09 01:23:12 UTC (rev 16469) +++ trunk/console/libgnt/test/combo.c 2006-07-09 04:44:58 UTC (rev 16470) @@ -1,19 +1,29 @@ #include <gnt.h> #include <gntbox.h> +#include <gntbutton.h> #include <gntcombobox.h> #include <gntlabel.h> int main() { GntWidget *box, *combo, *button; + GntWidget *hbox; gnt_init(); - box = gnt_box_new(FALSE, FALSE); + box = gnt_box_new(FALSE, TRUE); + gnt_widget_set_name(box, "box"); + gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_MID); + gnt_box_set_pad(GNT_BOX(box), 0); gnt_box_set_toplevel(GNT_BOX(box), TRUE); gnt_box_set_title(GNT_BOX(box), "Checkbox"); + hbox = gnt_box_new(FALSE, FALSE); + gnt_box_set_pad(GNT_BOX(hbox), 0); + gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); + gnt_widget_set_name(hbox, "upper"); + combo = gnt_combo_box_new(); gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "1", "1"); gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "2", "2"); @@ -22,12 +32,20 @@ gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "5", "5"); gnt_combo_box_add_data(GNT_COMBO_BOX(combo), "6", "6"); - gnt_box_add_widget(GNT_BOX(box), gnt_label_new("Select")); - gnt_box_add_widget(GNT_BOX(box), combo); + gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new("Select")); + gnt_box_add_widget(GNT_BOX(hbox), combo); + gnt_box_add_widget(GNT_BOX(box), hbox); + + hbox = gnt_box_new(TRUE, FALSE); + gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); + gnt_widget_set_name(hbox, "lower"); + button = gnt_button_new("OK"); - gnt_box_add_widget(GNT_BOX(box), button); + gnt_box_add_widget(GNT_BOX(hbox), button); + gnt_box_add_widget(GNT_BOX(box), hbox); + gnt_widget_show(box); gnt_main(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |