RubyLit - Ruby.del.litoral!
Box Properties (changes)

Showing changes from revision #0 to #1: Added | Removed

Es comun usar cajas (V|H Box) para empaquetar widgets cuando se programa en Ruby GTK, las V y H Box heredan de Gtk::Box, y de allĂ­ podemos acceder a algunas propiedades de los hijos (child) empaquetados.

El siguiente programa muestra como acceder a las distintas propiedades descriptas en la api http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ABox#Child+Properties


require 'gtk2'

class Mi_app < Gtk::VBox
    def initialize()
        super()
        hbox = Gtk::HBox.new(true, nil)

        l1a = Gtk::Label.new("| Etiqueta 1 |")
        l2a = Gtk::Label.new("| Etiqueta 2 |")
        l3a = Gtk::Label.new("| Etiqueta 3 |")
        hbox.pack_start_defaults(l1a)
        hbox.pack_start_defaults(l2a)
        hbox.pack_start_defaults(l3a)

        pack_start( hbox, false, false, 0)

        print "Expand: ", hbox.child_get_property(l3a,'expand'), "\n" 
        print "Fill: ", hbox.child_get_property(l3a,'fill'), "\n" 
        if hbox.child_get_property(l3a,'pack-type') == Gtk::PACK_START
            print "Pack-Type: Gtk::PACK_START\n" 
        else
            print "Pack-Type: Gtk::PACK_END\n" 
        end
        print "Padding: ", hbox.child_get_property(l3a,'padding'), "\n" 
        print "Position: ", hbox.child_get_property(l3a,'position'), "\n" 

    end
end

class Viewer < Gtk::Window
  def initialize()
    super()
    set_title("App Base") 
    set_window_position(Gtk::Window::POS_CENTER)
    signal_connect("delete_event") { |i,a| Gtk::main_quit }
    set_default_size(250, 250)
    add(Mi_app.new)
  end
end

Gtk.init()

view = Viewer.new
view.show_all

Gtk.main()