Class: Iup::Menu
Overview
A menu is a collection of menu items, submenus, and separators. It is usually placed within a Dialog, or launched from an action, using popup.
This widget basically acts as a container for other menu widgets, but setting the radio attribute makes those other widgets act as a radio group.
Example
The following example creates open, save and exit menu items, and places them onto a menu. The save menu item is initially inactive. Notice the use of a separator, and how a SubMenu adds a clickable title to the file menu.
item_open = Iup::MenuItem.new('Open')
item_save = Iup::MenuItem.new('Save') do |i|
i.active = 'NO'
end
item_exit = Iup::MenuItem.new('Exit', ->{ Iup::CLOSE })
= Iup::Menu.new(
item_open, item_save,
Iup::Separator.new,
item_exit)
= Iup::Menu.new(Iup::SubMenu.new('File', ))
See also: MenuItem, Separator, SubMenu
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#initialize(*widgets) {|_self| ... } ⇒ Menu
constructor
Creates instance of a menu for given menu widgets.
-
#menuclose_cb=(callback) ⇒ Object
–.
-
#open_cb=(callback) ⇒ Object
–.
-
#radio ⇒ Object
:attr: radio If set, makes children act as a radio group.
-
#wid ⇒ Object
:attr_reader: wid Native widget identifier.
Methods inherited from Widget
#active, #assign_handle, #bgcolor, #destroy, #enterwindow_cb=, #fgcolor, #font, #getfocus_cb=, #help_cb=, #k_any=, #killfocus_cb=, #leavewindow_cb=, #map_cb=, #maxsize, #minsize, #open_controls, #size, #unmap_cb=, #visible, #zorder
Methods included from AttributeBuilders
#define_attribute, #define_id_attribute, #define_id_reader, #define_id_writer, #define_property_attribute, #define_property_reader, #define_property_writer, #define_reader, #define_writer
Methods included from CallbackSetter
Constructor Details
#initialize(*widgets) {|_self| ... } ⇒ Menu
Creates instance of a menu for given menu widgets. If a block is given, the new instance is yielded to it.
-
widgets- one or more menu items, sub menus or separators.
38 39 40 41 42 43 |
# File 'lib/wrapped/menu.rb', line 38 def initialize * @handle = IupLib.IupMenu *() # run any provided block on instance, to set up further attributes yield self if block_given? end |
Instance Method Details
#menuclose_cb=(callback) ⇒ Object
–
81 82 83 84 85 86 87 88 89 |
# File 'lib/wrapped/menu.rb', line 81 def callback unless callback.arity.zero? raise ArgumentError, 'menuclose callback must take 0 arguments' end cb = Proc.new do |ih| callback.call end define_callback cb, 'MENUCLOSE_CB', :plain end |
#open_cb=(callback) ⇒ Object
–
65 66 67 68 69 70 71 72 73 |
# File 'lib/wrapped/menu.rb', line 65 def open_cb= callback unless callback.arity.zero? raise ArgumentError, 'open callback must take 0 arguments' end cb = Proc.new do |ih| callback.call end define_callback cb, 'OPEN_CB', :plain end |
#radio ⇒ Object
:attr: radio If set, makes children act as a radio group. Values ‘yes’ / ‘no’.
50 |
# File 'lib/wrapped/menu.rb', line 50 define_attribute :radio |
#wid ⇒ Object
:attr_reader: wid Native widget identifier.
55 |
# File 'lib/wrapped/menu.rb', line 55 define_reader :wid |