Hello Everyone
I have written a code which uses a XML with a lable.
When designing the XML in glade the text with the label appears correctly centered withing the label.
But when the XML is loaded into the program the text appear offset to the LEFT of the label.
Also changing the text in the label has the new text offset to the LEFT. Why does this happen and how can I get around it?
The code I have used is below and the XML file is also below(For some reason i cannot attache any files, it keeps telling me that all the extensions that I have attached are not allowed!!!).
Code:
#include <gtk/gtk.h>
//gcc -Wall -g fixed-xml.c -o fixed-xml -export-dynamic `pkg-config --cflags --libs gtk+-2.0`
GtkWidget *window, *fixed, *label, * button;
static void new_text (GtkWidget * button, gint data)
{
gtk_label_set_markup(GTK_LABEL(label), "<span font_desc='11'><b> Bonkey! how are you today.\nThe day is bright and sunny and the morning is funny.\nAnd now I have spotted a bunny!</b></span>");
}
int main (int argc, char *argv[])
{
GtkBuilder * builder;
gtk_init (&argc, &argv);
builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, "fixed-xml.xml", NULL);
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_window_set_title (GTK_WINDOW (window), "Fixed");
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
g_signal_connect (G_OBJECT (window), "destroy",G_CALLBACK (gtk_main_quit), NULL);
fixed = GTK_WIDGET (gtk_builder_get_object (builder,"fixed"));
label = GTK_WIDGET (gtk_builder_get_object (builder,"label"));
button = GTK_WIDGET (gtk_builder_get_object (builder,"button1"));
g_signal_connect (G_OBJECT (button), "clicked",G_CALLBACK (new_text), NULL);
g_object_unref (G_OBJECT (builder));
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
Please name the file as "fixed-xml.xml"
Code:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 2.12 -->
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="default_width">400</property>
<property name="default_height">200</property>
<signal name="destroy" handler="on_WindowLogout_destroy" swapped="no"/>
<child>
<object class="GtkFixed" id="fixed">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label">
<property name="width_request">800</property>
<property name="height_request">100</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes"><span font_desc='11'><b> Hello how are you today.
The day is bright and sunny and the morning is funny.
And now I have spotted a bunny!</b></span></property>
<property name="use_markup">True</property>
<property name="justify">center</property>
<property name="wrap">True</property>
</object>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">Put new text
</property>
<property name="use_action_appearance">False</property>
<property name="width_request">800</property>
<property name="height_request">41</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
</object>
<packing>
<property name="y">120</property>
</packing>
</child>
</object>
</child>
</object>
</interface>