RE: Could GtkLayout be contained within GtkLayout??



Thanks for your replication. 

I wrote a test program for GtkLayout contained within another GtkLayout. 
The size of inner GtkLayout is 300x180. I split the inner GtkLayout up into
4 equal pieces (their size are 150x90). Then I create 4 GtkLayout widgets,
each contains a single button, to fill in the inner GtkLayout. When the test
program begins running, there isn't any button widget displayed. What's the 
problem with my code??
=====================Code Begin=============================
#include <gtk/gtk.h>

gint main(int argc, char* argv[])
{
  
  GtkWidget* window;
  GtkWidget* main_layout;
  GtkWidget* layout;
  GtkWidget* button;
  GtkAdjustment *hadj, *vadj;
  gint i, j, x = 0, y =0, x1 = 60, y1 = 30;
  gchar l[23];

  gtk_init(&argc, &argv);

  window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
  gtk_window_set_default_size(GTK_WINDOW(window), 300, 180);
  
  hadj = (GtkAdjustment *)gtk_adjustment_new(0,0,300,0,0,0);
  vadj = (GtkAdjustment *)gtk_adjustment_new(0,0,180,0,0,0);

  main_layout = gtk_layout_new(hadj, vadj);
  gtk_layout_set_size(GTK_LAYOUT(main_layout), 300, 180);

  hadj = (GtkAdjustment *)gtk_adjustment_new(0,0,150,0,0,0);
  vadj = (GtkAdjustment *)gtk_adjustment_new(0,0,90,0,0,0);

  for( i=0; i<2; i++ ) { 
    for( j=0; j<2; j++) {
      layout = gtk_layout_new(hadj, vadj);
      gtk_layout_set_size(GTK_LAYOUT(layout), 150, 90);
      sprintf(l, "(%d, %d)", i, j);
      button = gtk_button_new_with_label(l);
      gtk_layout_put(GTK_LAYOUT(layout), button, x1, y1);
      gtk_layout_put(GTK_LAYOUT(main_layout), layout, x, y);
      x1 += 150;
      x += 150; 
    }
    x1 = 60;
    y1 += 90;
    x = 0;
    y +=90;  
  }

  gtk_container_add(GTK_CONTAINER(window), main_layout);
  gtk_widget_show_all(window);

  gtk_main();
  return 0;
}
=====================Code End===========================
From: jrb redhat com [mailto:jrb redhat com]
Subject: Re: Could GtkLayout be contained within GtkLayout??

Hi,

Is it possible to make outer GtkLayout contained within inner 
GtkLayout widget?
I need a container widget which is like the Panel component in Java.
This container widget can contain another container widget 
provided with its location
coordinate with respect to its parent container. 

Yes, GtkLayouts can contain any widget, including another GtkLayout.  I
don't know if it's worth bringing up the usual warnings about absolute
placement of widgets in this case.



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