ruby-****@sourc*****
ruby-****@sourc*****
2012年 11月 6日 (火) 05:44:48 JST
------------------------- REMOTE_ADDR = 184.145.95.170 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-mnub ------------------------- @@ -136,7 +136,29 @@ A new menu bar widget is created with Gtk::MenuBar.new. This creates an empty menu shell into which you add content. After you have created a menu bar you can set a pack direction with Gtk::MenuBar#pack_direction=(pack_dir), where pack_dir is one of the constants defined in Gtk::MenuBar::PackDirection. By default pack direction is left to right (Gtk::MenuBar::PACK_DIRECTION_LTR). Gtk::MenuBar class provides also child_pack_direction=(pack_dir) instance method, which sets how widgets should be packed inside the children of a menubar. -Each child item in a menu bar is actually another Gtk::MenuItem widget. It is important that you understand the structure underneath the Gtk::MenuBar. Most likely the children of menu bar will be sub-menus. However they are not added directly to the menu bar. The direct children of any menu are menu items created with Gtk::MenuItem.new. You assign your sub-menus, which you created with my_sub_menu=Gtk::Menu.new, to these menu items with Gtk::MenuItem#submenu(my_sub_menu). +Each child item in a menu bar is actually another Gtk::MenuItem widget. It is important that you understand the structure underneath the Gtk::MenuBar. Most likely the children of menu bar will be sub-menus. However they are not added directly to the menu bar. The direct children of any menu are menu items created with Gtk::MenuItem.new. You assign your sub-menus, which you created with my_sub_menu=Gtk::Menu.new, to these menu items with Gtk::MenuItem#submenu(my_sub_menu). Compare what was just said with the following code segment from our example program above: + + + menubar = Gtk::MenuBar.new + + # Create menu items to be displayed on Menu Bar + file = Gtk::MenuItem.new("File") + edit = Gtk::MenuItem.new("Edit") + org = Gtk::MenuItem.new("Organize") + help = Gtk::MenuItem.new("Help") + + # Create menus to be assigned to Menu Bar's items + filemenu = Gtk::Menu.new + editmenu = Gtk::Menu.new + orgmenu = Gtk::Menu.new + helpmenu = Gtk::Menu.new + + # Turn menu items into triggers of drop-down menus (sub-menus) + file.submenu = filemenu + edit.submenu = editmenu + org.submenu = orgmenu + help.submenu = helpmenu + Since all menus are derived from Gtk::MenuShell abstract class, we assigning menu items to sub-menus, using Gtk::MenuShell#append(child). Note that we use the this instance method on both menu bar objects as well as on menus i.e. sub-menus. We also have Gtk::MenuShell#prepend or Gtk::MenuShell#insert at our disposal.