Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gtk label text center and wrap

Tags:

c

label

gtk2

I have been experiencing some really weird problems with gtk_label text positioning.

I have a gtk_label positioned on a fixed container, the label has been set to:

gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);

However when a single word is present in the label, instead of getting centered it gets left aligned.

If I unset gtk_label_set_line_wrap(GTK_LABEL(label), TRUE) to FALSE the word then appears in the center of the label, but I lose wrapping.

How should this be fixed?

like image 315
Naten Baptista Avatar asked Oct 24 '25 03:10

Naten Baptista


1 Answers

From the documentation (emphasis mine):

gtk_label_set_justify ()

Sets the alignment of the lines in the text of the label relative to each other. GTK_JUSTIFY_LEFT is the default value when the widget is first created with gtk_label_new(). If you instead want to set the alignment of the label as a whole, use gtk_misc_set_alignment() instead. gtk_label_set_justify() has no effect on labels containing only a single line.

As suggested in the above quote, you may wish to add a call to the gtk_misc_set_alignment() function, with its xalign parameter set to 0.5, before calling gtk_label_set_justify().

like image 170
user12205 Avatar answered Oct 26 '25 17:10

user12205



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!