The Fixed container allows you to place widgets at a fixed position within it's window, relative to it's upper left hand corner. The position of the widgets can be changed dynamically.
There are only a few methods associated with the fixed widget:
Gtk::Fixed.new Gtk::Fixed#put( widget, x, y ) Gtk::Fixed#move( widget, x, y )
The method #new allows you to create a new Fixed container.
Gtk::Fixed#put places widget in the container fixed at the position specified by x and y.
Gtk::Fixed#move allows the specified widget to be moved to a new position.
Gtk::Fixed#set_has_window( has_window ) Gtk::Fixed#has_window=( has_window ) Gtk::Fixed#has_window?
Normally, Fixed widgets don't have their own X window. Since this is different from the behavior of Fixed widgets in earlier releases of GTK, the method Gtk::Fixed#set_has_window allows the creation of Fixed widgets with their own window. It has to be called before realizing the widget.
The following example illustrates how to use the Fixed Container.
require 'gtk2' @y = 50 @x = 50 # Callback method moves the button to a new position # in the fixed container def move_button( widget, fixed ) x = ( @x + 30 ) % 300 y = ( @y + 50 ) % 300 fixed.move( widget, x, y ) end Gtk.init window = Gtk::Window.new( Gtk::Window::TOPLEVEL ) window.set_title( "Fixed Container" ) window.signal_connect( "destroy" ) { Gtk.main_quit } # Create a fixed conatiner fixed = Gtk::Fixed.new window.add( fixed ) for i in 1..3 button = Gtk::Button.new( "Press Me" ) button.signal_connect( "clicked" ) { |w| move_button( w, fixed ) } fixed.put( button, i*50, i*50 ) end window.show_all Gtk.main
Prev | Next |