Statuses

GtkTable and GtkLabel with wrap on Gtk+-3, and trying to stay compatible with Gtk+-2…

In Bluefish, Gnome, open source, Programming on November 30, 2011 by oli4444

Bluefish has several dialogs that use a GtkLabel with wrap enabled inside a GtkTable. Since the width-for-height changes in Gtk+-3.2 these GtkLabel’s take an enormous amount of vertical space. If this launchpad bug is correct it will use enough vertical space to put every word on a new line.

The suggestion in that bugreport is to switch to GtkGrid. This is a good suggestion, but is has a drawback. In Gtk+-2 there is no way to set widget specifc expand properties in a GtkGrid (in a GtkTable this is done with gtk_table_attach()). In Gtk+-3 new properties have been added to GtkWidget to control whether a widget may expand or not. We (Bluefish developers) try to remain compatible with Gtk+-2 at the moment. So what to do? GtkGrid may solve our problem in Gtk+-3 but causes problems in Gtk+-2, and GtkTable solves our problem in Gtk+-2 but causes problems in Gtk+-3 ?

Luckily I found a workaround:

#if GTK_CHECK_VERSION(3,2,0)
    gtk_label_set_width_chars(GTK_LABEL(label),50);
#endif

This fixes the problem with a GtkLabel with wrap in a GtkTable in Gtk+-3.2. So for the moment we stick with GtkTable with this workaround.

Advertisements

One Response to “GtkTable and GtkLabel with wrap on Gtk+-3, and trying to stay compatible with Gtk+-2…”

  1. > The suggestion in that bugreport is to switch to GtkGrid

    Then you must choose between gtk 3.0 and gtk 3.2. GtkGrid is incompatible between those versions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: