Class: Iup::MenuItem
Overview
A menu item is the interactive part of a menu, and acts like a button. The menu item can display a simple text label, an image, or act as a check box. When placed within a menu with the radio flag set, several menu items can act as a radio button group within a menu.
Example
(1) Item with text and action.
item_exit = Iup::MenuItem.new('Exit', ->{ Iup::CLOSE })
(2) Checkbox
= Iup::MenuItem.new('Show toolbar') do |i|
i.value = :off # assign a value to make menu item a checkbox
i.autotoggle = :yes # allow value to change when menu item clicked
end
Placing a set of checkbox menuitems into a Menu with radio set turns the menuitems into a linked radio group.
See also: Menu, Separator, SubMenu.
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#action=(callback) ⇒ Object
–.
-
#autotoggle ⇒ Object
:attr: autotoggle Sets auto toggle for item when menu activated, values ‘yes’ / ‘no’.
-
#hidemark ⇒ Object
:attr: hidemark If set, hides the mark.
-
#highlight_cb=(callback) ⇒ Object
–.
-
#image ⇒ Object
–.
-
#image=(val) ⇒ Object
:nodoc:.
-
#iminactive ⇒ Object
–.
-
#iminactive=(val) ⇒ Object
:nodoc:.
-
#initialize(title, callback = nil) {|_self| ... } ⇒ MenuItem
constructor
Creates a new instance.
-
#title ⇒ Object
:attr: title Title text to display on menu item.
-
#titleimage ⇒ Object
–.
-
#titleimage=(val) ⇒ Object
:nodoc:.
-
#value ⇒ Object
:attr: value Determines if check is enabled or not, values ‘off’ / ‘on’.
-
#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(title, callback = nil) {|_self| ... } ⇒ MenuItem
Creates a new instance. If a block is given, the new instance is yielded to it.
-
title- text to display -
callback- Optional action to call when clicked with left button.
34 35 36 37 38 39 40 41 |
# File 'lib/wrapped/menuitem.rb', line 34 def initialize(title, callback = nil) @handle = IupLib.IupItem(title, nil) self.action = callback unless callback.nil? # run any provided block on instance, to set up further attributes yield self if block_given? end |
Instance Method Details
#action=(callback) ⇒ Object
–
124 125 126 127 128 129 130 131 132 |
# File 'lib/wrapped/menuitem.rb', line 124 def action= callback unless callback.arity.zero? raise ArgumentError, 'action callback must take 0 arguments' end cb = Proc.new do |ih| callback.call end define_callback cb, 'ACTION', :plain end |
#autotoggle ⇒ Object
:attr: autotoggle Sets auto toggle for item when menu activated, values ‘yes’ / ‘no’. i.e. the menu item’s check status is inverted when clicked.
49 |
# File 'lib/wrapped/menuitem.rb', line 49 define_attribute :autotoggle |
#hidemark ⇒ Object
:attr: hidemark If set, hides the mark. Values ‘yes’ / ‘no’.
54 |
# File 'lib/wrapped/menuitem.rb', line 54 define_attribute :hidemark |
#highlight_cb=(callback) ⇒ Object
–
140 141 142 143 144 145 146 147 148 |
# File 'lib/wrapped/menuitem.rb', line 140 def highlight_cb= callback unless callback.arity.zero? raise ArgumentError, 'highlight_cb callback must take 0 arguments' end cb = Proc.new do |ih| callback.call end define_callback cb, 'HIGHLIGHT_CB', :plain end |
#image ⇒ Object
–
63 64 65 |
# File 'lib/wrapped/menuitem.rb', line 63 def image attribute_reference('IMAGE', ImageWidget, nil) end |
#image=(val) ⇒ Object
:nodoc:
67 68 69 |
# File 'lib/wrapped/menuitem.rb', line 67 def image= val # :nodoc: attribute_reference('IMAGE', ImageWidget, val) end |
#iminactive ⇒ Object
–
78 79 80 |
# File 'lib/wrapped/menuitem.rb', line 78 def iminactive attribute_reference('IMINACTION', ImageWidget, nil) end |
#iminactive=(val) ⇒ Object
:nodoc:
82 83 84 |
# File 'lib/wrapped/menuitem.rb', line 82 def iminactive= val # :nodoc: attribute_reference('IMINACTION', ImageWidget, val) end |
#title ⇒ Object
:attr: title Title text to display on menu item.
89 |
# File 'lib/wrapped/menuitem.rb', line 89 define_attribute :title |
#titleimage ⇒ Object
–
98 99 100 |
# File 'lib/wrapped/menuitem.rb', line 98 def titleimage attribute_reference('TITLEIMAGE', ImageWidget, nil) end |
#titleimage=(val) ⇒ Object
:nodoc:
102 103 104 |
# File 'lib/wrapped/menuitem.rb', line 102 def titleimage= val # :nodoc: attribute_reference('TITLEIMAGE', ImageWidget, val) end |
#value ⇒ Object
:attr: value Determines if check is enabled or not, values ‘off’ / ‘on’.
109 |
# File 'lib/wrapped/menuitem.rb', line 109 define_attribute :value |
#wid ⇒ Object
:attr_reader: wid Native widget identifier.
114 |
# File 'lib/wrapped/menuitem.rb', line 114 define_attribute :wid |