GtkLayout Constructor

GtkLayout Constructor

GtkLayout ( GtkAdjustment hadjustment , GtkAdjustment vadjustment );

The following example is based on the GTK+ test file testgtk.c. Unix users will not need to use the callback function in order to achieve scrolling, but it shouldn't do any harm to run it as it stands. Win32 users will find that the labels are redrawn and the buttons are not, giving a somewhat psychedelic effect. To redraw both types of object under win32, replace the callback function with:

Example 21. Forcing a GtkLayout to redraw

<?php

dl('php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));

/* callback that forces a redraw of simple child widgets */
function exposure($adj, $layout) {
  $layout->queue_draw();
}

/* set up a window and size it to be smaller than the intended layout */
$window = &new GtkWindow();
$window->set_position(GTK_WIN_POS_CENTER);
$window->set_title('Layout');
$window->set_usize(200, 200);
$window->connect_object('destroy', array('gtk', 'main_quit'));

/* create and add the scrolled window to the main window */
$scrolledwindow = &new GtkScrolledWindow();
$window->add($scrolledwindow);

/* create and add the layout widget to the scrolled window */
$layout = &new GtkLayout(null, null);
$scrolledwindow->add($layout);

/* set the layout to be bigger than the windows that contain it */
$x = gdk::screen_width();
$y = gdk::screen_height();
$layout->set_size($x, $y);

/* get the adjustment objects and connect them to the callback.  This
   part should not be necessary under *nix systems */
$hadj = $scrolledwindow->get_hadjustment();
$vadj = $scrolledwindow->get_vadjustment();
$hadj->connect('value-changed', 'exposure', $layout);
$vadj->connect('value-changed', 'exposure', $layout);

/* populate the layout with a mixture of buttons and labels */
for ($i=0 ; $i < round($y/100); $i++)  {
  for ($j=0 ; $j < round($x/100); $j++)  {
    $buf =sprintf('Button %d, %d', $i, $j);
    if (($i + $j) % 2) $button = &new GtkButton($buf);
    else $button = &new GtkLabel($buf);
    $layout->put($button, $j*100, $i*100);
  }
}

/* display everything and run the main loop */
$layout->show_all();
$window->show_all();

gtk::main();

?>

add is not implemented for GtkLayout. You must use put to add children to the layout.

© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.