Re: How center a small button horizontally like in this picture....
- From: Deborah Swayne <dfs research att com>
- To: gtk-list gnome org
- Subject: Re: How center a small button horizontally like in this picture....
- Date: Thu, 28 Mar 2002 14:07:26 -0500
I want to do something similar, and I've tried to follow the
suggestions put forth in this thread, but to no avail.
Objective: To vertically center a label in an hbox in a vbox (or
in any other arrangement of widgets that would produce this pattern)
It's easy to control the horizontal position of the label, shifting
it right or center, but I don't seem to have any control over its
vertical position; it always appears at the top of its container.
I've tried using a vbox in the hbox, and using
gtk_misc_set_alignment; I've tried using an alignment widget in the
hbox or in the vbox in the hbox; I've tried a table. I'm stumped,
and yet it seems so easy.
vbox:
-------------------------
| | | |
| | | -------- |<-- hbox containing two togglebuttons and a label
| X | Y | |Label A | |
| | | -------- |
| | | |
-------------------------
| | | |
| | | -------- |<-- ditto
| X | Y | |Label B | |
| | | -------- |
| | | |
-------------------------
| | | |
| | | -------- |<-- ditto
| X | Y | |Label C | |
| | | -------- |
| | | |
-------------------------
I'll be grateful for any help anyone can offer.
Debby
-------
Here's the code I've been playing with to test it out; it's
borrowed from the scrolled window example in gtk1.2.
/* varpanelA.c */
#include <gtk/gtk.h>
#define false 0
#define true 1
void destroy( GtkWidget *widget, gpointer data )
{
gtk_main_quit();
}
int main( int argc, char *argv[] )
{
static GtkWidget *window;
GtkWidget *swin, *hbox, *vbox, *vb;
GtkWidget *button, *align, *label;
gchar *buffer;
int j;
gtk_init (&argc, &argv);
/* Create a dialog window */
window = gtk_dialog_new ();
gtk_signal_connect (GTK_OBJECT (window), "destroy",
(GtkSignalFunc) destroy, NULL);
gtk_window_set_title (GTK_WINDOW (window), "GtkScrolledWindow example");
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
gtk_widget_set_usize(window, 300, 300);
/* create a scrolled window. */
swin = gtk_scrolled_window_new (NULL, NULL);
gtk_container_set_border_width (GTK_CONTAINER (swin), 10);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window)->vbox), swin,
TRUE, TRUE, 0);
vbox = gtk_vbox_new (true, 2);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (swin), vbox);
/* create a grid of toggle buttons */
for (j = 0; j < 10; j++) {
hbox = gtk_hbox_new (false, 2);
gtk_box_pack_start (GTK_BOX (vbox), hbox, true, true, 0);
button = gtk_toggle_button_new_with_label (" X ");
gtk_box_pack_start (GTK_BOX (hbox), button, false, false, 2);
button = gtk_toggle_button_new_with_label (" Y ");
gtk_box_pack_start (GTK_BOX (hbox), button, false, false, 2);
buffer = g_strdup_printf ("variable %d\n", j);
label = gtk_label_new (buffer);
/*gtk_misc_set_alignment (GTK_MISC(label), 0, .5);*/
g_free (buffer);
align = gtk_alignment_new (0, 1.0, 0, 0);
gtk_box_pack_start (GTK_BOX (hbox), align, 0, 1, 0);
gtk_container_add (GTK_CONTAINER (align), label);
}
/* Add a "close" button to the bottom of the dialog */
button = gtk_button_new_with_label ("close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
(GtkSignalFunc) gtk_widget_destroy, GTK_OBJECT (window));
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
button, TRUE, TRUE, 0);
gtk_widget_show_all (window);
gtk_main();
return(0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]