Aligning label baselines




Hello, does anyone know how to align the baselines of
GtkLabels?  Without reimplementing most of GtkLabel, if
possible.

Assume a table such as this one:

====================================================================
include <gtk/gtk.h>

int
main(int argc, char *argv[])
{
    static const gchar *labels[] = {
        "Tag<sub>1</sub>:", "bloody",
        "Tag<sub>2</sub>:", "10<sup>6</sup>",
        "Value:",           "10<sup>-2</sup>",
    };
    GtkWidget *window, *table;
    guint i;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    table = g_object_new(GTK_TYPE_TABLE,
                         "n-rows", G_N_ELEMENTS(labels)/2, "n-columns", 2,
                         "row-spacing", 2, "column-spacing", 6,
                         "border-width", 6,
                         NULL);
    gtk_container_add(GTK_CONTAINER(window), table);

    for (i = 0; i < G_N_ELEMENTS(labels); i++)
        gtk_table_attach(GTK_TABLE(table),
                         g_object_new(GTK_TYPE_LABEL,
                                      "label", labels[i], "use-markup", TRUE,
                                      "xalign", 0.0,
                                      NULL),
                         i % 2, i % 2 + 1, i/2, i/2 + 1,
                         GTK_FILL, GTK_FILL, 0, 0);

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}
====================================================================

The baselines of the labels are clearly misaligned due to
the presence of subscripts and superscripts.

Pango of course can calculate the ascent, descent and
baseline position of a layout, however I cannot see how to
use them to get aligned labels (except for some ugly hacks
and implementation of a new label widget).

Insertion of some strut with the height and depth of a text
with both subscripts and superscripts to each label involved
would correct the alignment too, but I do not know how to do
this either.

Yeti

--
http://gwyddion.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]