Re: Top down layout



Hi Matthew,

On 9 June 2010 06:16, Matthew Allen <list sydneyband com au> wrote:
When I tried putting putting a scrollable area into a window...
I didn't get very convincing results. The code below attempts to put a very
large button into a 300x300 size window.

I made you a tiny example program. This puts a 400x400 button into a
300x300 window. If the window is too small, you get scrollbars. If the
window is too big, the button expands to fill the available space.
Hope I've not misunderstood what you need.

-----------
/* compile with

   gcc -Wall try161.c `pkg-config gtk+-2.0 --cflags --libs`

 */
#include <gtk/gtk.h>

int
main (int argc, char **argv)
{
  GtkWidget *window;
  GtkWidget *scrolled_window;
  GtkWidget *button;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_container_add (GTK_CONTAINER (window), scrolled_window);

  button = gtk_button_new_with_label ("push me!");
  gtk_widget_set_size_request (button, 400, 400);
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW
                                         (scrolled_window), button);

  gtk_widget_show_all (window);
  gtk_main ();

  return (0);
}
--------------

John



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