summaryrefslogtreecommitdiff
path: root/iup/srclua5/menu.lua
blob: 70be2368b999e6765fdd16d10a8a51dd4884709b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
------------------------------------------------------------------------------
-- Menu class 
------------------------------------------------------------------------------
local ctrl = {
  nick = "menu",
  parent = iup.BOX,
  creation = "-",
  callback = {
    open_cb = "",
    menuclose_cb = "",
  }
}

function ctrl.popup(handle, x, y)
  iup.Popup(handle, x, y)
end

function ctrl.append(handle, elem)
  iup.Append(handle, elem)
end

function ctrl.createElement(class, param)
  local n = #param
  for i=1,n do
    if type(param[i]) == "table" then 
      local itemarg = {}
      for u,v in pairs(param[i]) do
        if type(u) ~= "number" then
          itemarg[u] = v
        end
      end
      if type(param[i][1]) == "string" and (type(param[i][2]) == "function" or type(param[i][2]) == "string") then
        itemarg.title = param[i][1]
        itemarg.action = param[i][2]
        param[i] = iup.item(itemarg)
      elseif type(param[i][1]) == "string" and type(param[i][2]) == "userdata" then
        itemarg[1] = param[i][2]
        itemarg.title = param[i][1]
        param[i] = iup.submenu(itemarg)
      end
    end
  end
  return iup.Menu()
end

function ctrl.showxy(handle, x, y)
  return iup.ShowXY(handle, x, y)
end

function ctrl.destroy(handle)
  return iup.Destroy(handle)
end

iup.RegisterWidget(ctrl)
iup.SetClass(ctrl, "iup widget")