Murga-Projects Forums

Full Version: multiple menu bar issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I don't know if this is a problem with FLTK or the murgaLua bindings, but there seems to be a problem when using multiple menubars and the menubar:add() function. Even when creating a different menubar for separate windows, any attempt to include menu items to the second menubar with add(item) seems to cause trouble for both menu bars. The second menu bar receives nothing, and the first menu bar seems to fail in receiving subsequent commands.

As a test I had a main window menu bar that would successfully recieve commands to enable or disable certain menu items when that was the only menu bar. When adding a new window with a new menu bar, that new menubar would not display its added items and the first menubar would not enable/disable its items.

I tried this both before and after first_window:show() with the same results.
I've come up with a sloppy workaround, which I haven't fully explored but it does prevent the troubles I was having. It consists of using either a hidden menu that supplies menu items for all visible menus, or using one of the visible menus to supply menu items for all other menus. The second option could potentially become very sloppy, since items not intended to be seen on that main menu must be hidden. This could easily result in losing track of what items you have, and where they are.

The process goes something like this....

Code:
function menu_callback()
if menu2:text()=="&disable item3" then toggle_item:deactivate()
elseif menu2:text()=="&enable item3" then toggle_item:activate()
end
menu1:redraw()
end

window = fltk:Fl_Window(400, 200, "menu test")
main_menu=fltk:Fl_Menu_Button(0,0,0,0) -- essentially invisible
menu1=fltk:Fl_Menu_Bar(0,0,400,30)
menu2=fltk:Fl_Menu_Bar(0,40,400,30)

main_menu:add("menu1/item1")
main_menu:add("menu1/item2")
main_menu:add("menu1/item3/item3a")
main_menu:add("menu1/item3/item3b")
main_menu:add("menu1/item4")
main_menu:add("menu2/&File/item5")
main_menu:add("menu2/&File/item6")
main_menu:add("menu2/&File/item7")
main_menu:add("menu2/&File/&enable item3")
main_menu:add("menu2/&File/&disable item3")

-- create pointers to the first items in each submenu
-- this will allow menu() to grab all items on or below that level
menu1menu=main_menu:find_item("menu1/item1")
menu2menu=main_menu:find_item("menu2/&File")
menu1:menu(menu1menu)
menu2:menu(menu2menu)

toggle_item=menu1:find_item("item3") --create a pointer to menu1/item3

menu2:callback(menu_callback)

window:show()
Fl:run()


Important note: using "add()" on menu1 or menu2 after this point may cause a segfault, and adding to main_menu can cause an unwanted shift to the other menus, so apparently this is still not a solution for dynamically changing the number of menu items available.

Again, this is a workaround for something I don't fully understand, and should not to be considered the recommended method.

Reference URL's