Index: fixed_flow/Makefile =================================================================== --- fixed_flow/Makefile (nonexistent) +++ fixed_flow/Makefile (revision 25438) @@ -0,0 +1,12 @@ +TRUNK=../../../trunk +CFLAGS=-g -Wall -I $(TRUNK)/src_plugins `pkg-config --cflags gtk+-2.0` +LDFLAGS=-g `pkg-config --libs gtk+-2.0` +#CFLAGS=-g -Wall -I $(TRUNK)/src_plugins -DPCB_GTK3 `pkg-config --cflags gtk+-3.0` +#LDFLAGS=-g `pkg-config --libs gtk+-3.0` + +all: fixed_flow + +fixed_flow: fixed_flow.o + +clean: + rm *.o fixed_flow \ No newline at end of file Index: fixed_flow/fixed_flow.c =================================================================== --- fixed_flow/fixed_flow.c (nonexistent) +++ fixed_flow/fixed_flow.c (revision 25438) @@ -0,0 +1,74 @@ +#include + +/* Flow layout: left-to-right first, top-to-bottom next */ +static void flow_resize_lrtb(GtkWidget *flow, GtkAllocation *af, gpointer user_data) +{ + int x = 0, y = 0, row_height = 0, cols = 0, total_width = af->width; + GList *ch = gtk_container_get_children(GTK_CONTAINER(flow)); + + for(; ch != NULL; ch = ch->next) { + GtkWidget *cw = ch->data; + GtkAllocation aw; + + gtk_widget_get_allocation(cw, &aw); + + if ((x + aw.width >= total_width) && (cols > 0)) { /* line wrap */ + y += row_height; + x = 0; + cols = 0; + } + + if ((aw.x != x) || (aw.y != y)) + gtk_fixed_move(GTK_FIXED(flow), cw, x, y); + x += aw.width; + if (aw.height > row_height) + row_height = aw.height; + cols++; + } +} + +static GtkWidget *pcb_gtk_flow_lrtb(void) +{ + GtkWidget *flow = gtk_fixed_new(); + g_signal_connect(G_OBJECT(flow), "size-allocate", G_CALLBACK(flow_resize_lrtb), NULL); + return flow; +} + +static void create_widgets(GtkWidget *window, const char **text) +{ + const char **s; + GtkWidget *flow = pcb_gtk_flow_lrtb(); + + for(s = text; *s != NULL; s++) { + GtkWidget *label = gtk_label_new(*s); + gtk_container_add(GTK_CONTAINER(flow), label); + } + + gtk_container_add(GTK_CONTAINER(window), flow); +} + +int main(int argc, char **argv) +{ + GtkWidget *window; + static const char *text[] = { + "|this is a long text|", + "|that brea|", + "|ks only at|", + "|specific|", + "|locations|", + NULL + }; + + gtk_init(&argc, &argv); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + g_signal_connect(G_OBJECT(window), "destroy", gtk_main_quit, NULL); + gtk_window_set_default_size(GTK_WINDOW(window), 10, 400); + + create_widgets(window, text); + gtk_widget_show_all(window); + + gtk_main(); + + return 0; +}