Naten Baptista
Naten Baptista

Reputation: 51

gtk label text center and wrap

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?

Upvotes: 4

Views: 5219

Answers (1)

user12205
user12205

Reputation: 2702

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().

Upvotes: 4

Related Questions