3 Feb 2004 (updated 3 Feb 2004 at 11:10 UTC)
»
Some more progress: now the grid uses the GtkListStore as its model. We are a little bit closer to the MVC architecture.
Wanna see more screenshots? Well this time nothing is really spectacular but I can tell you is a important step to separate the data from the widget. Ok, the screenshot is here.
Now it's time to paste some code. As an add-on, the GtkGrid API will be pretty similar to the GtkTreeView one, so programmers will not need to learn a lot of different things. Let's see an example of how to use it:
/* Create the model and populate it */
for (i=0; i<n_columns; i++)
types[i] = G_TYPE_STRING;
model = gtk_list_store_newv (n_columns, types);
for (y=0; y<n_rows; y++)
{
GtkTreeIter iter;
gtk_list_store_append (model, &iter);
for (x=0; x<n_columns; x++)
{
GValue value = { 0, };
g_value_init (&value, G_TYPE_STRING);
snprintf (buffer, 99, "cell %d %d", y, x);
g_value_set_string (&value, buffer);
gtk_list_store_set_value (model, &iter, x, &value);
}
}
/* Create the grid with the model */
grid = GTK_GRID (gtk_grid_new_with_model (model));
for (i=0; i<n_columns; i++)
{
renderer = gtk_cell_renderer_text_new ();
column = gtk_grid_column_new_with_attributes ("testing",
renderer,
"text",
i,
NULL);
gtk_grid_append_column(grid, column);
}