ImGui Menus


GeeXLab - ImGui menus demo

ImGui menus have been added in the branch 0.22+ of GeeXLab. Here is a code snippet that shows how to use the menu functions of the gh_imgui library.

The complete demo is available HERE (demo_menus.xml) as well as in the full code sample pack (gl-32/imgui/demo_menus.xml).

ImGui defines two kinds of menu bars: a main menu bar and a window menu bar.

 

Main menu bar

The main menu bar is a fullscreen menu bar. It’s placed on the top of GeeXLab 3D window.


GeeXLab - ImGui main menu bar

Here is the code that draws the main menu bar:

if (gh_imgui.menu_begin_main_bar() == 1) then

  local enabled = 1
  if (gh_imgui.menu_begin("File", enabled) == 1) then
  
    local item_selected = 0
    local item_enabled = 1

    if (gh_imgui.menu_item("Show log file", "", item_selected, item_enabled) == 1) then
      --
      -- do something
      --
    end
  
    gh_imgui.menu_end()
  end

  if (gh_imgui.menu_begin("Tools", enabled) == 1) then
  
    local item_selected = 0
    local item_enabled = 1
    if (gh_imgui.menu_item("Wireframe", "", item_selected, item_enabled) == 1) then
      --
      -- do something
      --
    end
    if (gh_imgui.menu_item("Solid", "", item_selected, item_enabled) == 1) then
      --
      -- do something
      --
    end
  
    gh_imgui.menu_end()
  end

  gh_imgui.menu_end_main_bar()
end

 

Window menu bar

Each ImGui window can have its own menu bar.


GeeXLab - ImGui window menu bar

Here is the code that draws this menu:

gh_imgui.window_begin("Menu test", .......)


-- Window menu.
--
if (gh_imgui.menu_begin_bar() == 1) then

  local enabled = 1
  if (gh_imgui.menu_begin("File", enabled) == 1) then
    local item_selected = 0
    local item_enabled = 1
    if (gh_imgui.menu_item("Show log file", "", item_selected, item_enabled) == 1) then
      --
      -- do something
      --
    end
    gh_imgui.menu_end()
  end

  if (gh_imgui.menu_begin("Tools", enabled) == 1) then
    local item_selected = 0
    local item_enabled = 1
    if (gh_imgui.menu_item("Wireframe", "", item_selected, item_enabled) == 1) then
      --
      -- do something
      --
    end
    if (gh_imgui.menu_item("Solid", "", item_selected, item_enabled) == 1) then
      --
      -- do something
      --
    end
    gh_imgui.menu_end()
  end

  gh_imgui.menu_end_bar()
end



gh_imgui.window_end()




Leave a Comment

Your email address will not be published. Required fields are marked *