Class: Iup::Menu

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

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 })
file_menu = Iup::Menu.new(
  item_open, item_save, 
  Iup::Separator.new, 
  item_exit)
menu = Iup::Menu.new(Iup::SubMenu.new('File', file_menu))

See also: MenuItem, Separator, SubMenu

Instance Attribute Summary

Attributes inherited from Widget

#handle

Instance Method Summary collapse

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

#define_callback

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.

Yields:

  • (_self)

Yield Parameters:

  • _self (Iup::Menu)

    the object that the method was called on



38
39
40
41
42
43
# File 'lib/wrapped/menu.rb', line 38

def initialize *widgets
  @handle = IupLib.IupMenu *widget_list(widgets)

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

Instance Method Details



81
82
83
84
85
86
87
88
89
# File 'lib/wrapped/menu.rb', line 81

def menuclose_cb= 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

#radioObject

: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

#widObject

:attr_reader: wid Native widget identifier.



55
# File 'lib/wrapped/menu.rb', line 55

define_reader :wid