GtkStyle Constructor

GtkStyle Constructor

GtkStyle (void);

There are several ways to define the style across an application, but only two ways to directly set the style on a given widget.

Example 42. Writing to a widget's style property.

<?php
if( !extension_loaded('gtk')) {	
	dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); 
}

$window = &new GtkWindow();
$window->set_position(GTK_WIN_POS_CENTER);
$window->connect_object('destroy', array('gtk', 'main_quit'));

/* set up a few buttons just to prove we're only changing one of them */
$bbox = &new GtkVButtonBox();
$window->add($bbox);

for($i = 0; $i < 8; $i++) {
  $button[$i] = &new GtkButton("This is Button $i");
  $bbox->pack_start($button[$i], false);
  $button[$i]->show();
}

/* method 1 : set up a new style and define the parts you want to define. 
   The remaining style elements retain the application's default settings. */
$newstyle = &new GtkStyle();
$cyan = &new GdkColor('#00FFFF');
$newstyle->fg[GTK_STATE_PRELIGHT] = $cyan;
$label = $button[5]->child;
$label->set_style($newstyle);

/* gdk::color_parse() uses a color that is defined on your system to fill
   a GdkColor structure.  It can be more convenient than manually creating
   a new GdkColor, particularly if you're only assigning the color once. */
$newstyle->bg[GTK_STATE_NORMAL] = gdk::color_parse('ivory');
$button[5]->set_style($newstyle);

/* method 2 : copy the existing style from a widget and alter it.  Defining
   a new style would overwrite the existing non-default style settings. */
$style2 = $label->style;
$newstyle2 = $style2->copy();
$font = gdk::font_load('-*-Arial-bold-r-normal--*-160-*-*-p-0-iso8859-1');
$newstyle2->font = $font;
$label->set_style($newstyle2);

$window->show_all();

gtk::main();
?>

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