Re: [HIG] Visual layout section

On Sat, Oct 19, 2002 at 06:18:36PM -0400, Dave Bordoley wrote:
> Some hackers have expressed concern about the fact that the HIGs current
> recommendation for dialog layout is virtually unimplementable without
> bad hacks (like using text boxes to fake the spacing etc.).[1]

This may fall under bad hacks, but I have a way to do it.

Once you have the toplevel of the indented widgets (typically a vbox)
connect to the "size-allocate" signal:

  g_signal_connect (indented_toplevel, "size_allocate",
                    G_CALLBACK (adjust_allocation), NULL);

The adjust_allocation callback is then:

  static void
  adjust_allocation (GtkWidget *widget, GtkAllocation *allocation)
    allocation->x += INDENTATION_IN_PIXELS;
    allocation->width -= INDENTATION_IN_PIXELS;
    GTK_WIDGET_GET_CLASS (widget)->size_allocate (widget, allocation);

I think an INDENTATION_IN_PIXELS value of 24 achieves the desired effect.

I've attached a code sample showing this.

Greg Merchan
/* cc `pkg-config --cflags --libs gtk+-2.0` packtest.c */
#include <gtk/gtk.h>

static void adjust_allocation  (GtkWidget     *widget,
				GtkAllocation *allocation);

main (int argc, char *argv[])
	GtkWidget *window;
	GtkWidget *group_vbox;
	GtkWidget *group_label;
	GtkWidget *widgets_vbox;
	GtkWidget *field0_hbox;
	GtkWidget *field0_label;
	GtkWidget *field0_entry;
	GtkWidget *field1_hbox;
	GtkWidget *field1_label;
	GtkWidget *field1_entry;
	GtkWidget *option_hbox;
	GtkWidget *option_label;
	GtkWidget *option_menu;
	GtkSizeGroup *label_size_group;

	gtk_init (&argc, &argv);

	label_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_container_set_border_width (GTK_CONTAINER (window), 12);
	g_signal_connect (window, "delete-event",
			  G_CALLBACK (gtk_main_quit), NULL);

	group_vbox = gtk_vbox_new (FALSE, 6);
	gtk_container_add (GTK_CONTAINER (window), group_vbox);

	group_label = gtk_label_new ("<b>Group</b>");
	gtk_label_set_use_markup (GTK_LABEL (group_label), TRUE);
	gtk_misc_set_alignment (GTK_MISC (group_label), 0.0, 0.5);
	gtk_box_pack_start (GTK_BOX (group_vbox), group_label,
			    FALSE, FALSE, 0);

	widgets_vbox = gtk_vbox_new (FALSE, 12);
	gtk_box_pack_start (GTK_BOX (group_vbox), widgets_vbox,
			    TRUE, TRUE, 0);
	g_signal_connect (widgets_vbox, "size-allocate",
			  G_CALLBACK (adjust_allocation), NULL);

	field0_hbox = gtk_hbox_new (FALSE, 6);
	gtk_box_pack_start (GTK_BOX (widgets_vbox), field0_hbox,
			    FALSE, FALSE, 0);

	field0_label = gtk_label_new_with_mnemonic ("_Field 1:");
	gtk_misc_set_alignment (GTK_MISC (field0_label), 0.0, 0.5);
	gtk_size_group_add_widget (label_size_group, field0_label);
	gtk_box_pack_start (GTK_BOX (field0_hbox), field0_label,
			    FALSE, TRUE, 0);

	field0_entry = gtk_entry_new ();
	gtk_box_pack_start (GTK_BOX (field0_hbox), field0_entry,
			    TRUE, TRUE, 0);
	gtk_label_set_mnemonic_widget (GTK_LABEL (field0_label),

	field1_hbox = gtk_hbox_new (FALSE, 6);
	gtk_box_pack_start (GTK_BOX (widgets_vbox), field1_hbox,
			    FALSE, FALSE, 0);

	field1_label = gtk_label_new_with_mnemonic ("F_ield 2:");
	gtk_misc_set_alignment (GTK_MISC (field1_label), 0.0, 0.5);
	gtk_size_group_add_widget (label_size_group, field1_label);
	gtk_box_pack_start (GTK_BOX (field1_hbox), field1_label,
			    FALSE, TRUE, 0);

	field1_entry = gtk_entry_new ();
	gtk_box_pack_start (GTK_BOX (field1_hbox), field1_entry,
			    TRUE, TRUE, 0);
	gtk_label_set_mnemonic_widget (GTK_LABEL (field1_label),

	option_hbox = gtk_hbox_new (FALSE, 6);
	gtk_box_pack_start (GTK_BOX (widgets_vbox), option_hbox,
			    FALSE, FALSE, 0);

	option_label = gtk_label_new_with_mnemonic ("_Option:");
	gtk_misc_set_alignment (GTK_MISC (option_label), 0.0, 0.5);
	gtk_size_group_add_widget (label_size_group, option_label);
	gtk_box_pack_start (GTK_BOX (option_hbox), option_label,
			    FALSE, TRUE, 0);

	option_menu = gtk_option_menu_new ();
	gtk_box_pack_start (GTK_BOX (option_hbox), option_menu,
			    TRUE, TRUE, 0);
	gtk_label_set_mnemonic_widget (GTK_LABEL (option_label),

	gtk_widget_show_all (window);

	gtk_main ();

	return 0;

static void
adjust_allocation (GtkWidget *widget, GtkAllocation *allocation)
	allocation->x += 24;
	allocation->width -= 24;
	GTK_WIDGET_GET_CLASS (widget)->size_allocate (widget,

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