/*
 * Compile using the following command:
 * gcc `pkg-config --cflags --libs gtk+-2.0` test_min_width.c
 */

#include <gtk/gtk.h>

gboolean change_text(gpointer data)
{
	GtkLabel *label = GTK_LABEL(data);
	const gchar *old_text = gtk_label_get_text(label);

	gchar *text = g_strjoin(NULL, old_text, "+", NULL); 
	gtk_label_set_text(label, text);

	glong length = g_utf8_strlen(text, -1);
	g_printf("change_text: %d characters\n", length);
	g_free(text);

	return TRUE;
}

int main(int argc, char* argv[])
{
	gtk_init(&argc, &argv);

	GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size(GTK_WINDOW(window), 400, 30);
	g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

	GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
	GtkWidget *label1 = gtk_label_new("static text");
	GtkWidget *separator = gtk_vseparator_new();

	GtkWidget *label2 = gtk_label_new("dynamic text");
	gtk_widget_set_size_request(label2, 120, -1);
	g_timeout_add(1000, change_text, (gpointer)label2);

	gtk_box_pack_start(GTK_BOX(hbox), label1, TRUE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(hbox), separator, FALSE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(hbox), label2, FALSE, TRUE, 0);
	gtk_container_add(GTK_CONTAINER(window), hbox);
	gtk_widget_show_all(window);

	gtk_main();

	return 0;
}

