ocarina: New column registering framework
I keep one array instead of two, and I store more information for each array entry. I can then find the size of the array for the number of columns, and I can add new columns without having to modify the allay, treestore and liststore. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
8623779210
commit
f72447decc
|
@ -5,8 +5,32 @@
|
|||
SongList::SongList() {}
|
||||
SongList::~SongList() {}
|
||||
|
||||
static string columns[7] = { "Id", "#", "Title", "Length", "Artist", "Album", "Year" };
|
||||
static int col_width[7] = { 2, 20, 300, 60, 125, 125, 50 };
|
||||
struct column_info {
|
||||
const char *name;
|
||||
int width;
|
||||
bool visible;
|
||||
GType type;
|
||||
|
||||
column_info(const char *n, GType t, int w, bool v)
|
||||
{
|
||||
name = n;
|
||||
width = w;
|
||||
visible = v;
|
||||
type = t;
|
||||
}
|
||||
};
|
||||
|
||||
static struct column_info columns[] = {
|
||||
column_info( "Id", G_TYPE_LONG, 2, false),
|
||||
column_info( "#", G_TYPE_INT, 20, true),
|
||||
column_info( "Title", G_TYPE_STRING, 300, true),
|
||||
column_info("Length", G_TYPE_STRING, 60, true),
|
||||
column_info("Artist", G_TYPE_STRING, 125, true),
|
||||
column_info( "Album", G_TYPE_STRING, 125, true),
|
||||
column_info( "Year", G_TYPE_INT, 50, true),
|
||||
};
|
||||
|
||||
#define NUM_COLUMNS (sizeof(columns) / sizeof(column_info))
|
||||
|
||||
static GtkWidget *setup_label(string text)
|
||||
{
|
||||
|
@ -24,11 +48,12 @@ static GtkCellRenderer *setup_renderer()
|
|||
|
||||
static GtkListStore *setup_liststore()
|
||||
{
|
||||
GtkListStore *liststore;
|
||||
liststore = gtk_list_store_new(7, G_TYPE_LONG, G_TYPE_INT, G_TYPE_STRING,
|
||||
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
|
||||
G_TYPE_INT);
|
||||
return liststore;
|
||||
GType types[NUM_COLUMNS];
|
||||
|
||||
for (unsigned int i = 0; i < NUM_COLUMNS; i++)
|
||||
types[i] = columns[i].type;
|
||||
|
||||
return gtk_list_store_newv(NUM_COLUMNS, types);
|
||||
}
|
||||
|
||||
static GtkTreeModel *setup_filter(GtkListStore *liststore)
|
||||
|
@ -70,20 +95,23 @@ static GtkWidget *setup_window(GtkWidget *treeview)
|
|||
|
||||
static void add_column(GtkCellRenderer *textcell, GtkWidget *treeview, int index)
|
||||
{
|
||||
if (columns[index].visible == false)
|
||||
return;
|
||||
|
||||
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(
|
||||
columns[index].c_str(), textcell,
|
||||
columns[index].name, textcell,
|
||||
"text", index, NULL);
|
||||
gtk_tree_view_column_set_resizable(column, TRUE);
|
||||
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_min_width(column, 2);
|
||||
gtk_tree_view_column_set_max_width(column, 700);
|
||||
gtk_tree_view_column_set_fixed_width(column, col_width[index]);
|
||||
gtk_tree_view_column_set_fixed_width(column, columns[index].width);
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
|
||||
}
|
||||
|
||||
static void setup_columns(GtkCellRenderer *textcell, GtkWidget *treeview)
|
||||
{
|
||||
for (unsigned int i = 0; i < 7; i++)
|
||||
for (unsigned int i = 0; i < NUM_COLUMNS; i++)
|
||||
add_column(textcell, treeview, i);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue