changeset 18449:ed17f5530300

Allow showing right-aligned text trees. Right-align the size in the file selector tree.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 06 Jul 2007 21:42:25 +0000
parents 8fc91e437981
children 8457bb35bf8c
files finch/libgnt/gntfilesel.c finch/libgnt/gnttree.c finch/libgnt/gnttree.h
diffstat 3 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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 */
--- 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;
--- 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.
  *