Class: Iup::MenuItem

Inherits:
Widget show all
Defined in:
lib/wrapped/menuitem.rb

Overview

A menu item is 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.

Attributes

autotoggle

Sets auto toggle for item when menu activated, values ‘yes’ / ‘no’.

hidemark

If set, hides the mark. Values ‘yes’ / ‘no’.

image

Image used when check enabled.

impress

Image used when check disabled.

title

Label to display on menu item.

titleimage

Image to show on menu item.

value

Determines if check is enabled or not, values ‘off’ / ‘on’.

wid

read-only Native widget identifier.

Instance Attribute Summary

Attributes inherited from Widget

#handle

Instance Method Summary collapse

Methods inherited from Widget

#assign_handle, #enterwindow_cb, #getfocus_cb, #help_cb, #k_any, #killfocus_cb, #leavewindow_cb, #map_cb, #open_controls, #unmap_cb

Methods included from AttributeBuilders

#define_attribute, #define_id_attribute, #define_id_readonly, #define_id_writeonly, #define_property_attribute, #define_property_writeonly, #define_readonly, #define_writeonly

Methods included from CallbackSetter

#define_callback

Constructor Details

#initialize(title, callback = nil, &block) ⇒ MenuItem

Creates an instance of MenuItem.

title

Label to display

callback

Optional action to call when MenuItem is clicked.

block

Optional block to set up menu item’s attributes.



25
26
27
28
29
30
31
32
# File 'lib/wrapped/menuitem.rb', line 25

def initialize title, callback = nil, &block
  @handle = IupLib.IupItem title, nil

  action callback unless callback.nil?

  # run any provided block on instance, to set up further attributes
  self.instance_eval &block if block_given?
end

Instance Method Details

#action(callback) ⇒ Object

Action generated when the element is activated.



59
60
61
62
63
64
65
66
67
# File 'lib/wrapped/menuitem.rb', line 59

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

#highlight_cb(callback) ⇒ Object

Action generated when the item is highlighted.



70
71
72
73
74
75
76
77
78
# File 'lib/wrapped/menuitem.rb', line 70

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(val = nil) ⇒ Object

:nodoc:



39
40
41
# File 'lib/wrapped/menuitem.rb', line 39

def image val=nil # :nodoc:
  attribute_reference 'IMAGE', ImageWidget, val
end

#iminactive(val = nil) ⇒ Object

:nodoc:



43
44
45
# File 'lib/wrapped/menuitem.rb', line 43

def iminactive val=nil # :nodoc:
  attribute_reference 'IMINACTION', ImageWidget, val
end

#titleimage(val = nil) ⇒ Object

:nodoc:



49
50
51
# File 'lib/wrapped/menuitem.rb', line 49

def titleimage val=nil # :nodoc:
  attribute_reference 'TITLEIMAGE', ImageWidget, val
end