V
V
Vitaliy2018-01-19 19:55:40
Lua
Vitaliy, 2018-01-19 19:55:40

How to create a popup menu in conjunction: iup + lua?

I took the "menu" example from the examples folder as a basis, there are no problems when altering it to my needs, I want to add a right-click pop-up menu.
The help says: "A popup menu is displayed for the user using the IupPopup function (usually on the mouse position) and disappears when an item is selected."
Until the problem is solved. Please share a minimal working example.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy, 2018-01-21
@Vitaliy_dzen

The answer was suggested on ru.stackoverflow.com, here is the whole code:

require("iuplua")

cv       = iup.canvas {size="300x100", xmin=0, xmax=99, posx=0, dx=10}
dlg      = iup.dialog{iup.frame{cv}; title="IupCanvas"}

mnu = iup.menu
{
  iup.submenu
  {
    iup.menu
    {
      iup.item{title="IupItem 1 Checked",value="ON"},
      iup.separator{},
      iup.item{title="IupItem 2 Disabled",active="NO"}
    } 
    ;title="IupSubMenu 1"
  },
  iup.item{title="IupItem 3"},
  iup.item{title="IupItem 4"}
}

function cv:button_cb(button, pressed, x, y, status)
    if button == 51 and pressed == 0 then
        mnu:popup(iup.MOUSEPOS, iup.MOUSEPOS)
    end
end

dlg:showxy(iup.CENTER,iup.CENTER)

if (iup.MainLoopLevel()==0) then
  iup.MainLoop()
  iup.Close()
end

All the highlights in the function
function cv:button_cb(button, pressed, x, y, status)

redefining cv you can make pop-up menus for any interface element.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question