ruby-****@sourc*****
ruby-****@sourc*****
2012年 9月 14日 (金) 06:54:44 JST
------------------------- REMOTE_ADDR = 184.145.80.187 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-txtw-scrolledwin ------------------------- @@ -151,19 +151,22 @@ {{br}} -The following listing demonstrates how to use scrolled windows and viewports. As the scrollbar is moved, the viewport will scroll as well because adjustments are synchronized. New scrolled windows are created with: Gtk::ScrolledWindow.new(hadjustment = nil, vadjustment = nil), where the two arguments are the scrolled window's adjustments; these will be shared with the scrollbars and the child widget to keep the bars in sync with the child. Though you could supply adjustments you previously created, usually you do not specify any arguments, hence using the default nil(s) instead, which causes the scrolled window to create them for you. In our example the adjustments are used when viewport is created with Gtk::Viewport.new(horizontal, vertical). The viewport adjustments are initialized with those from the scrolled window, ensuring that both containers will be scrolled at the same time. +{{image_right("viewports-w2tables.png")}} -One of the decisions you have to make when setting up a scrolled window is to specify when the scrollbars will be visible (Gtk::ScrolledWindow#set_policy(hscrollbar_policy, vscrollbar_policy)). This is done with the policy arguments, which take one of the values defined in ((<GtkPolicyType|Gtk#GtkPolicyType>)). Though unlikely, another thing you may wish to set is the placement of the scrollbars. For that you have Gtk::Scrollbar#window_placement=(window_placement) method at your disposal. Look for the correct argument values at ((<GtkCornerType|Gtk#GtkCornerType>)). +The following listing demonstrates how to use scrolled windows and viewports, and how the two relate to each other. The program is called "viewports-w2tables.rb", because it implements two scolling tables. However, what is interesting is that only one of the two tables is adorned with scrollbars, and even more peculiar is that these very same scrolbars are actually scrolling both tables. (Not that you will often or ever need to do such a thing, we nevertheless include this program in the tutorial, since it does show expose hidden relationship between these widgets to us). -After you have setup a scrolled window you should add a child widget which you intend to slide around with your scrollbars. There are two possible ways of doing this, and the method is chosen based on the type of child widget. If you are adding to your scrolling window a Gtk::TextView, Gtk::TreeView, Gtk::IconView, or Gtk::Layout widget you should use Gtk::Container#add method, since all four of these containers include native scrolling support. -All other GTK+ widgets, such as our Gtk::Table, which do not have scrolling support, you must first add to a Gtk::Viewport widget, and then add the Gtk::Viewport to the scrolled window. This longer method of adding a widget without the scrolling support to the scrolled window, demonstrates precisely what happens, when you use a convenience method Gtk::ScrolledWindow#add_with_viewport, which does exactly what we have just described. Namely, it adds the scrolling ability to a child widget such as for instance to our table, adds it (the table) to the viewport, and finally adds this viewport with the child (table) to the scrolling window. +As the scrollbar is moved, the viewport will scroll as well because adjustments are synchronized. Namely, new scrolled windows are created with: Gtk::ScrolledWindow.new(hadjustment = nil, vadjustment = nil), where the two arguments are the scrolled window's adjustments; these will be shared with the scrollbars and the child widget to kept in sync between these widgets. Note, that unlike for Gtk::Viewport.new, where you must always specify all arguments, even when they are nil, for Gtk::ScrolledWindow.new, you must always supply both adjustment arguments. So so if you previously created adjustments, obviously, you supply them to Gtk::ScrolledWindow.new method, however if you would like the scrolled window to create them for you, then you do not have to specify any arguments at all, hence using the default nil(s) instead. +In our example the adjustments are used when viewport is created with Gtk::Viewport.new(horizontal, vertical). The viewport adjustments are initialized with those from the scrolled window, ensuring that both containers will be scrolled at the same time. +One additional decision you often would like to make when setting up a scrolled window is to specify when the scrollbars will be visible. This is accomplished with Gtk::ScrolledWindow#set_policy(hscrollbar_policy, vscrollbar_policy). The policy arguments, take one of the values defined in ((<GtkPolicyType|Gtk#GtkPolicyType>)). Though unlikely, another thing you may wish to set is the placement of the scrollbars. For that you have Gtk::Scrollbar#window_placement=(window_placement) method at your disposal. Look for the correct argument values at ((<GtkCornerType|Gtk#GtkCornerType>)). +After you have setup a scrolled window you should add a child widget which you intend to slide around with your scrollbars. There are two possible ways of doing this, and the method is chosen based on the type of child widget. If you are adding to your scrolling window a Gtk::TextView, Gtk::TreeView, Gtk::IconView, or Gtk::Layout widget you should use Gtk::Container#add method, since all five of these containers include native scrolling support. +All other GTK+ widgets, such as our Gtk::Table, which do not have scrolling support, you must first add to a Gtk::Viewport widget, and then add the Gtk::Viewport to the scrolled window. This longer method of adding a widget without the scrolling support to the scrolled window, demonstrates precisely what happens, when you use a convenience method Gtk::ScrolledWindow#add_with_viewport, which does exactly what we have just described. Namely, it adds the scrolling ability to a child widget such as for instance to our table, adds it (the table) to the viewport, and finally adds this viewport with the child (table) to the scrolling window. -{{image_right("viewports-w2tables.png")}} + {{br}} ((*viewports-w2tables.rb*))