Re: Center align labels in container using label top as reference



David Nečas wrote:
On Sun, Jan 03, 2010 at 04:46:31PM -0500, Vikram Noel Ambrose wrote:
I added each label to their own vbox

I said size group, not vbox.

Note that the on_size_allocate_tadeboro_hack() hack is utter crap and it
makes the widget (or some parent container) to get stuck in a resizing
and allocation loop and eat 100% cpu if you resize it below certain
size.

Yeti


--- label-valign.c.orig	2010-01-03 23:27:31.000000000 +0100
+++ label-valign.c	2010-01-03 23:36:12.251769040 +0100
@@ -23,20 +23,26 @@
 	/* Create an empty button */
 	GtkWidget *button = gtk_button_new();
+ GtkWidget *alignment = gtk_alignment_new(0.5,0.5,1.0,0.0);
+	gtk_container_add(GTK_CONTAINER(button),alignment);	
 	/* Add a horizontal box as the button's child */
 	GtkWidget *button_hbox = gtk_hbox_new(FALSE,0);
-	gtk_container_add(GTK_CONTAINER(button),button_hbox);	
+	gtk_container_add(GTK_CONTAINER(alignment),button_hbox);	
+ GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_VERTICAL);
 	/* Create the left label */
 	GtkWidget *left_label = gtk_label_new(
 			"<b>This is a really long label that should wrap at least once</b>");
-	gtk_misc_set_alignment(GTK_MISC(left_label),0,0.5);
+	gtk_misc_set_alignment(GTK_MISC(left_label),0,0.0);
 	gtk_label_set_line_wrap(GTK_LABEL(left_label),TRUE);
 	gtk_label_set_use_markup(GTK_LABEL(left_label),TRUE);
+	gtk_size_group_add_widget(sizegroup, left_label);
/* Create the right label */
 	GtkWidget *right_label = gtk_label_new("Small Label");
-	gtk_misc_set_alignment(GTK_MISC(right_label),1,0.5);
+	gtk_misc_set_alignment(GTK_MISC(right_label),1,0.0);
+	gtk_size_group_add_widget(sizegroup, right_label);
+	g_object_unref(sizegroup);
/* GtkLabel Line Wrap Hack - GTK SUCKS! */
 	g_signal_connect( G_OBJECT( left_label ), "size-allocate",


Thanks. Thats exactly what I was trying to get at.

I hate hacks as much as the next person, but how do I get the GtkLabel to line-wrap "dynamically" (if thats the right term for it) without that "size-allocate" hack?

thanks again.

Vikram.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]