GtkSpreadTable ('spread-table' branch)
- From: Tristan Van Berkom <tristanvb openismus com>
- To: gtk-devel-list gnome org
- Subject: GtkSpreadTable ('spread-table' branch)
- Date: Thu, 07 Oct 2010 12:37:42 +0900
Hello list again,
Now for the introduction of GtkSpreadTable (still open for
a better name for this widget).
What the spread table container does is takes a linear list
of widgets, which can be of variable size and spread/distribute
the widgets as evenly as possible according to their size
across a fixed number of rows or columns. Thus requiring the
smallest size possible while maintaining the fixed number
of columns or rows.
For instance when oriented vertically, widgets will be listed
top-down with the first widget in the top-left corner and the
last widget on the bottom right; widgets will be lined up in
such a way to require the least height as possible.
This widget is the one that actually meets the requirements
for Glom[0].
To get a better idea of how this works you can checkout and
build the 'spread-table' branch I added to GTK+ yesterday...
fire up the ./tests/testspreadlayout demo.
Some technical caveats:
- When there are over ~12 columns the whole thing slows down
significantly.
The reason for this being, the algorithm in place starts
by lining up all the widgets in the first column and
then evening them out column by column... by the time
we hit the 3rd column; columns 1 & 2 need to be recalculated
for every widget we pull into the 3rd column, and so on
as the columns grow.
By the time we hit 12 columns things are getting exponentially
heavier to calculate (I've tried simpler algorithms that were
much further from perfect results than this one though).
- Columns all have even widths (rows have even heights).
There is simply no way I can conceive of achieving variable
columns widths efficiently, since the height of a widget may
grow for a smaller width (and may do so with unpredictable
proportions). The only algorithm I can conceive of for variable
column widths is to try every possible combination of widgets
distributed in columns and then choose the result that has
the smallest height (this could be a very intense process
as soon as there are lots of widgets in the list and even only
a few columns).
The api doesn't tell much about how the widget works but I'll paste
it here anyway.
Is there interest in adding a widget like this to GTK+ ?
Cheers,
-Tristan
[0] http://www.glom.org/wiki/index.php?title=Main_Page
GtkWidget *gtk_spread_table_new (GtkOrientation orientation,
guint lines);
void gtk_spread_table_insert_child(GtkSpreadTable *table,
GtkWidget *child,
gint index);
void gtk_spread_table_set_lines (GtkSpreadTable *table,
guint lines);
guint gtk_spread_table_get_lines (GtkSpreadTable *table);
void gtk_spread_table_set_horizontal_spacing
(GtkSpreadTable *table,
guint spacing);
guint gtk_spread_table_get_horizontal_spacing
(GtkSpreadTable *table);
void gtk_spread_table_set_vertical_spacing
(GtkSpreadTable *table,
guint spacing);
guint gtk_spread_table_get_vertical_spacing
(GtkSpreadTable *table);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]