Re: widget alignment



>>>>> "L" == Lee  <drazka@geocities.com> writes:

 L> Hi, Is it possible to align widgets in tables?

 L> More specifically I'm packing labels in cells next to entry
 L> widgets, but the labels are always aligned in the center of the
 L> table cell.

 L> This looks really bad, but I can't for the life of me find out how
 L> to left (or even right) align the labels against the table edges.

Now, one would think you could use something like set_justify or
something...but no (as the attached file will show).  Instead you can
use gtk_misc_set_alignment.  You use numbers between 0 and 1 to adjust
horizontally and vertically.

	/mailund

===File ~/tmp/bar.c=========================================
#include <gtk/gtk.h>

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

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  table = gtk_table_new (3, 2, TRUE);
  gtk_container_add (GTK_CONTAINER (window), table);

  /* insert some labels in table... */
  label = gtk_label_new ("foo");
  gtk_label_set_justify (GTK_LABEL (label),   GTK_JUSTIFY_LEFT);
  gtk_table_attach_defaults (GTK_TABLE (table),
			     label,
			     0, 1, 0, 1);
  label = gtk_label_new ("foobar");
  gtk_label_set_justify (GTK_LABEL (label),   GTK_JUSTIFY_LEFT);
  gtk_table_attach_defaults (GTK_TABLE (table),
			     label,
			     0, 1, 1, 2);
  label = gtk_label_new ("foobarbaz");
  gtk_label_set_justify (GTK_LABEL (label),   GTK_JUSTIFY_LEFT);
  gtk_table_attach_defaults (GTK_TABLE (table),
			     label,
			     0, 1, 2, 3);

  label = gtk_label_new ("foo");
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
  gtk_table_attach_defaults (GTK_TABLE (table),
			     label,
			     1, 2, 0, 1);
  label = gtk_label_new ("foobar");
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
  gtk_table_attach_defaults (GTK_TABLE (table),
			     label,
			     1, 2, 1, 2);
  label = gtk_label_new ("foobarbaz");
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
  gtk_table_attach_defaults (GTK_TABLE (table),
			     label,
			     1, 2, 2, 3);

  gtk_widget_show_all (window);

  gtk_main ();

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



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