Unwanted widget movement with table container



Using gtk-2 and Ubuntu 12.04 LTS.

I want to use a table container for placing widgets:

- several single-line widgets (text-entry,checkbox and combo boxes)
  placed vertically on the left-hand side
- a single multi-line text entry, listbox or listview placed at
  top right adjacent to the left-hand widgets

I first placed the single-line widgets each with an alignment container
setting top-align and then placed the right-hand 'big' widget with a
rowspan greater than the row of the last single-line widget.
It did not work when I resized vertically. Only the first single-line
widget at the top stayed put, the remaining single-line widgets moved
downwards as I resized.

Minimal test program:

#include <gtk/gtk.h>

static void mkentrynew ( bool usealign, const char * title,
                         int startcol, int endcol,
                         int startrow, int endrow,
                         GtkWidget * tablew )
   {
   GtkWidget * e = gtk_entry_new ( ) ;
   gtk_entry_set_text ( (GtkEntry *)e , title ) ;
   GtkWidget * align ;
   if ( !usealign )
      {
      gtk_table_attach ( GTK_TABLE(tablew), e,
                         startcol,endcol, startrow,endrow,
                         GTK_FILL,GTK_FILL, 0,0 );
      }
   else
      {
      align = gtk_alignment_new ( 0.0, 0.0, 0,0 );  // align left and top
      gtk_container_add(GTK_CONTAINER(align), e);
      gtk_table_attach ( GTK_TABLE(tablew), align,
                         startcol,endcol, startrow,endrow,
                         GTK_FILL, GTK_FILL, 0,0 );
      }
   }

int main( int argc , char * argv[] )
   {
   gtk_init(&argc, &argv);
   bool usealign = true;
   bool usebutton = false;

   GtkWidget * wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_position(GTK_WINDOW(wnd), GTK_WIN_POS_CENTER);
   gtk_widget_set_size_request (wnd, 300, 250);
   gtk_window_set_resizable(GTK_WINDOW(wnd), TRUE);
   gtk_window_set_title(GTK_WINDOW(wnd), "Test Expand & Fill" );

   GtkWidget * table = gtk_table_new(16, 6, FALSE);
   gtk_container_add(GTK_CONTAINER(wnd), table);

   // single line text widgets starting at top-left (col=0,row=0)

   mkentrynew ( usealign, "Hello" , 0,1, 0,1, table );
   mkentrynew ( usealign, "Hello2", 0,1, 1,2, table );
   mkentrynew ( usealign, "Hello3", 0,1, 2,3, table );

   if ( !usebutton )  // for top right-handside
      {
      //  multi-line text widget
      GtkWidget * tv = gtk_text_view_new ( ) ;
      GtkTextBuffer * buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));
      gtk_text_buffer_set_text ( buf, "Text on\ntwo lines" , -1 ) ;
      GtkWidget * scrolledwnd = gtk_scrolled_window_new (NULL, NULL);
      gtk_container_add (GTK_CONTAINER (scrolledwnd), tv);
      gtk_table_attach ( GTK_TABLE(table), scrolledwnd, 1,2, 0,10,
                        (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                        (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                        0,0 );
      }
   else
      {
      GtkWidget * b = gtk_button_new ( ) ;
      gtk_button_set_label ( (GtkButton *)b , "Top right" ) ;
      gtk_table_attach ( GTK_TABLE(table), b, 1,2, 0,10,
                        (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                        (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                        0,0 );
      }

   gtk_widget_show_all(wnd);
   gtk_main();
   return 0;
   }

On usealign false:
All three single-line text enries (hello, hello2 and hello3) move downwards on vertical resize
On usealign true:
Hello widget stays and hello2 and hello3 widgets move downwards.

Setting usebutton to true/false shows the problem is same with a multi-line text entry and a big button on the right-hand side.

I have very little experience using table containers and I have not seen any examples of this. I am probably doing something wrong, but cannot see what it is. Or, there may be better ways of achieving a steady left-hand side.

Would be grateful for help.

Ken





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