ruby-****@sourc*****
ruby-****@sourc*****
2012年 9月 14日 (金) 03:37:04 JST
------------------------- REMOTE_ADDR = 184.145.80.187 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-txtw-scrolledwin ------------------------- @@ -59,6 +59,46 @@ --- First example, a child without scrolling support: ((*scrolling-with-help-of-viewport.rb:*)) + #!/usr/bin/env ruby + require 'gtk2' + window = Gtk::Window.new("Scrolling Widgets With Help Of Viewports") + window.resizable = true + window.border_width = 10 + window.signal_connect('destroy') { Gtk.main_quit } + window.set_size_request(400, 200) + table = Gtk::Table.new(10, 10, true) + table.row_spacings = 5 + table.column_spacings = 5 + options = Gtk::EXPAND|Gtk::FILL + x = 10; y = 10 + # Pack each table with 100 buttons. */ + x.times do |i| + y.times do |j| + b1 = Gtk::Button.new("B:%2d,%2d" % [i,j]) + b1.signal_connect('clicked') { |w| puts "Button (#{w.label}) pressed" } + # child, x1, x2, y1, y2, x-opt, y-opt, xpad, ypad + table.attach(b1, i, i + 1, j, j + 1, options, options, 0, 0) + end + end + swin = Gtk::ScrolledWindow.new + swin.border_width = 5 + swin.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC) + + ### the short way: --------------------------- (start) + ### + ### swin.add_with_viewport(table1) + ### or + ### the long way: + viewport = Gtk::Viewport.new(nil, nil) # either {{ new }} is fine + viewport.add(table) + swin.add(viewport) + ### ------------------------------------------- (end) + + window.add(swin) + window.show_all + Gtk.main + + --- Second example, a child with built-in scrolling support: