# HG changeset patch # User Sadrul Habib Chowdhury # Date 1183758145 0 # Node ID ed17f55303005f2d66e2b5247fe929b20b272bb7 # Parent 8fc91e4379817b3bf8cf7ede191d0feaa48aabf3 Allow showing right-aligned text trees. Right-align the size in the file selector tree. diff -r 8fc91e437981 -r ed17f5530300 finch/libgnt/gntfilesel.c --- a/finch/libgnt/gntfilesel.c Fri Jul 06 06:14:31 2007 +0000 +++ b/finch/libgnt/gntfilesel.c Fri Jul 06 21:42:25 2007 +0000 @@ -653,6 +653,7 @@ gnt_tree_set_show_title(GNT_TREE(sel->files), TRUE); gnt_tree_set_col_width(GNT_TREE(sel->files), 0, 25); gnt_tree_set_col_width(GNT_TREE(sel->files), 1, 10); + gnt_tree_set_column_is_right_aligned(GNT_TREE(sel->files), 1, TRUE); g_signal_connect(G_OBJECT(sel->files), "selection_changed", G_CALLBACK(file_sel_changed), sel); /* The location entry */ diff -r 8fc91e437981 -r ed17f5530300 finch/libgnt/gnttree.c --- a/finch/libgnt/gnttree.c Fri Jul 06 06:14:31 2007 +0000 +++ b/finch/libgnt/gnttree.c Fri Jul 06 21:42:25 2007 +0000 @@ -33,6 +33,7 @@ #define COLUMN_INVISIBLE(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_INVISIBLE) #define BINARY_DATA(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_BINARY_DATA) +#define RIGHT_ALIGNED(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_RIGHT_ALIGNED) enum { @@ -306,10 +307,7 @@ len = gnt_util_onscreen_width(display, NULL); - if (i == tree->lastvisible) - width = GNT_WIDGET(tree)->priv.width - gnt_util_onscreen_width(string->str, NULL); - else - width = tree->columns[i].width; + width = tree->columns[i].width; if (i == 0) { @@ -348,6 +346,11 @@ len = width - 1; cut = TRUE; } + + if (RIGHT_ALIGNED(tree, i) && len < tree->columns[i].width) { + g_string_append_printf(string, "%*s", width - len, ""); + } + text = gnt_util_onscreen_width_to_pointer(display, len - fl, NULL); string = g_string_append_len(string, display, text - display); if (cut) { /* ellipsis */ @@ -358,7 +361,7 @@ len++; } - if (len < tree->columns[i].width && iter->next) + if (!RIGHT_ALIGNED(tree, i) && len < tree->columns[i].width && iter->next) g_string_append_printf(string, "%*s", width - len, ""); } return g_string_free(string, FALSE); @@ -1709,6 +1712,12 @@ set_column_flag(tree, col, GNT_TREE_COLUMN_FIXED_SIZE, bin); } +void gnt_tree_set_column_is_right_aligned(GntTree *tree, int col, gboolean right) +{ + g_return_if_fail(col < tree->ncol); + set_column_flag(tree, col, GNT_TREE_COLUMN_RIGHT_ALIGNED, right); +} + void gnt_tree_set_column_width_ratio(GntTree *tree, int cols[]) { int i; diff -r 8fc91e437981 -r ed17f5530300 finch/libgnt/gnttree.h --- a/finch/libgnt/gnttree.h Fri Jul 06 06:14:31 2007 +0000 +++ b/finch/libgnt/gnttree.h Fri Jul 06 21:42:25 2007 +0000 @@ -51,6 +51,7 @@ GNT_TREE_COLUMN_INVISIBLE = 1 << 0, GNT_TREE_COLUMN_FIXED_SIZE = 1 << 1, GNT_TREE_COLUMN_BINARY_DATA = 1 << 2, + GNT_TREE_COLUMN_RIGHT_ALIGNED = 1 << 3, } GntTreeColumnFlag; struct _GntTree @@ -481,6 +482,15 @@ void gnt_tree_set_column_is_binary(GntTree *tree, int col, gboolean bin); /** + * Set whether text in a column should be right-aligned. + * + * @param tree The tree + * @param col The index of the column + * @param right @c TRUE if the text in the column should be right aligned + */ +void gnt_tree_set_column_is_right_aligned(GntTree *tree, int col, gboolean right); + +/** * Set column widths to use when calculating column widths after a tree * is resized. *