Re: Label and wrap text



On Sun, Jun 19, 2005 at 09:30:46AM +0200, Jean Bréfort wrote:
> 
> I did not try it, but a call to gtk_label_set_justify should solve your
> problem:
> gtk_label_set_justify (label, GTK_JUSTIFY_FILL);

This doesn't help -- in fact, it doesn't even seem to do
what it should do, I get ragged right text like with
GTK_JUSTIFY_LEFT (GTK_JUSTIFY_RIGHT works, though).

A simple test case is atached to this mail.  The question is
how to make the long text fill window width like the
progress bar does.  An ugly workaround is to compute the
right width manually from other widgets and use
gtk_widget_set_size_request().

Yeti


--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


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

static const gchar *long_line =
    "g_signal_connect(window, \"destroy\", G_CALLBACK(gtk_main_quit), NULL);";

static const gchar *text =
    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
    "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim "
    "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
    "aliquip ex ea commodo consequat. Duis aute irure dolor in "
    "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
    "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
    "culpa qui officia deserunt mollit anim id est laborum.";

int
main(int argc, char *argv[])
{
    GtkWidget *window, *box, *label, *pbar;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    box = gtk_vbox_new(FALSE, 8);
    gtk_container_add(GTK_CONTAINER(window), box);

    label = gtk_label_new(long_line);
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);

    label = gtk_label_new(NULL);
    gtk_label_set_markup(GTK_LABEL(label), text);
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
    /*gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_FILL);*/
    gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);

    pbar = gtk_progress_bar_new();
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pbar), 1.0);
    gtk_box_pack_start(GTK_BOX(box), pbar, FALSE, FALSE, 0);

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}



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