[ruby-gnome2-doc-cvs] [Ruby-GNOME2 Project Website] update - tut-gtk2-txtw-scrolledwin

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2012年 9月 14日 (金) 06:04:19 JST


-------------------------
REMOTE_ADDR = 184.145.80.187
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-txtw-scrolledwin
-------------------------
@@ -169,31 +169,29 @@
 
  #!/usr/bin/env ruby
  require 'gtk2'
-
- def button_clicked(b)
-   puts "Button (#{b.label}) pressed"
- end
- window = Gtk::Window.new("Scrolled Window & Viewport")
+ 
+ window = Gtk::Window.new("Scrlld. Viewports With Two Tables")
  window.resizable = true
  window.border_width = 10
  window.signal_connect('destroy') { Gtk.main_quit }
  window.set_size_request(350, 300)
+ 
  table1 = Gtk::Table.new(10, 10, true)
  table2 = Gtk::Table.new(10, 10, true)
  table1.row_spacings = 5
  table2.row_spacings = 5
  table1.column_spacings = 5
  table2.column_spacings = 5
-
+ 
  options = Gtk::EXPAND|Gtk::FILL
  x = 10; y = 10
- # Pack each table with 100 buttons. */
+ # Pack each table with 100 buttons.
  x.times do |i|
    y.times do |j|
-     b1 = Gtk::Button.new("V:%2d,%2d" % [i,j])
-     b2 = Gtk::Button.new("S:%2d,%2d" % [i,j])
-     b1.signal_connect('clicked') { |w| button_clicked(w) }
-     b2.signal_connect('clicked') { |w| button_clicked(w) }
+     b1 = Gtk::Button.new("S:%2d,%2d" % [i,j])
+     b2 = Gtk::Button.new("V:%2d,%2d" % [i,j])
+     b1.signal_connect('clicked') { |w| puts "Button (#{w.label}) pressed" }
+     b2.signal_connect('clicked') { |w| puts "Button (#{w.label}) pressed" }
               # child, x1,    x2, y1,    y2, x-opt,   y-opt, xpad, ypad
      table1.attach(b1,  i, i + 1,  j, j + 1, options, options, 0, 0)
      table2.attach(b2,  i, i + 1,  j, j + 1, options, options, 0, 0)
@@ -202,25 +200,30 @@
  # Create a scrolled window and a viewport, each with one table.
  # Use the adjustments in the scrolled window to synchronize
  # both containers.
- swin = Gtk::ScrolledWindow.new
+ swin       = Gtk::ScrolledWindow.new
  swin.border_width = 5
+ # Gtk::POLICY_ALWAYS/Gtk::POLICY_AUTOMATIC ... when to show scrollbars
  swin.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS)
  swin.add_with_viewport(table1)
  
- horizontal = swin.hadjustment
- vertical   = swin.vadjustment
- viewport   = Gtk::Viewport.new(horizontal, vertical)
+ # Connect {{ swin }} scrollbars to {{ viewport }}
+ viewport   = Gtk::Viewport.new(swin.hadjustment, swin.vadjustment)
+ 
+ # Creates new adjustment (not connected as above), but seems better
+ # viewport   = Gtk::Viewport.new(nil, nil)	# better than above
+ 
  viewport.border_width = 5
  viewport.add(table2)
-
+ 
  # Pack the widgets into a GtkVBox and then into the window.
  vbox = Gtk::VBox.new(true, 5)
- vbox.pack_start_defaults(viewport)
+ 
  vbox.pack_start_defaults(swin)
-
+ vbox.pack_start_defaults(viewport)
+ 
  window.add(vbox)
  window.show_all
  Gtk.main
+ 
+
 
 The scrolled window is simply a container with scrollbars. Neither the container nor the scrollbars perform any action by themselves. Scrolling is handled by the child widget, which is why the child widget must have a scrolling support. As you know by now, most GTK+ widgets originally do not include such a support - we mentioned only four that do (Gtk::TextView, Gtk::TreeView, Gtk::IconView, or Gtk::Layout). For all these other widgets, without native scrolling support, scrolling behaviour is added with the help of portview.
 




ruby-gnome2-cvs メーリングリストの案内
Back to archive index