tags:

views:

26

answers:

2

I have a GtkLabel and a GtkDrawingArea within a VBox, I want to center the label relative to a X-coordinate of the GtkDrawingArea (which is below of the label in the VBox), how can I tell GTK to center that label relative to that "anchor" point ? This point should be the center of the label.

+2  A: 

Since your GtkLabel and GtlDrawingArea are inside a GtkVBox, then their position are relative to each other. The following should set the alignment of the label to the center:

gtk_misc_set_alignment(GTK_MISC(label), 0.5F /*X*/, 0.5F /*Y*/);

If you don't want to center the text of the GtkLabel, then you might use GtkAlignment widget:

GtkWidget* helper;

helper = gtk_alignment_new(0.5F /*X*/, 0.5F /*Y*/, 0.0F, 0.0F);
gtk_container_add(GTK_CONTAINER(helper), label);

gtk_box_pack_start_defaults(GTK_BOX(vbox), helper);

You can realign it again by calling gtk_alignment_set function.

PC2st
See the part where I say "I want to center the label relative to a X-coordinate of the GtkDrawingArea", I don't want the label to be centered with the GtkDrawingArea and yes centered against an arbitrary x-axis point of the GtkDrawingArea.
Tarantula
@Tarantula: I edited my answer, now it maybe is the answer, otherwise it's my fault that i can't understand your mean.
PC2st
Thanks for answering PC2st, I solved it using the gtk_alignment_set_padding, look the answer.
Tarantula
A: 

I solved my problem by using gtk_alignment_new in order to create a centered alignment and then I used gtk_alignment_set_padding to fill the right padding with the amount of padding needed to align with an arbitrary x-axis value. Thanks for the answers !

Tarantula