Wrap menu support

This commit is contained in:
Ollie Charles 2021-01-24 16:49:28 +00:00
parent 4f9a552a32
commit bc4b74cfea
2 changed files with 80 additions and 0 deletions

11
Main.hs
View File

@ -65,6 +65,17 @@ loop w checked = do
selectable "Testing 2"
endCombo
beginMainMenuBar >>= whenTrue do
beginMenu "Hello" >>= whenTrue do
menuItem "Hello"
endMenu
beginMenu "World" >>= whenTrue do
menuItem "World"
endMenu
endMainMenuBar
end
render

View File

@ -67,6 +67,15 @@ module DearImGui
-- ** Selectables
, selectable
-- ** Menus
, beginMenuBar
, endMenuBar
, beginMainMenuBar
, endMainMenuBar
, beginMenu
, endMenu
, menuItem
-- * Types
, ImGuiDir
, pattern ImGuiDirLeft
@ -393,6 +402,66 @@ selectable label = liftIO do
(1 == ) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
-- | Append to menu-bar of current window (requires 'ImGuiWindowFlagsMenuBar'
-- flag set on parent window).
--
-- Wraps @ImGui::BeginMenuBar()@.
beginMenuBar :: MonadIO m => m Bool
beginMenuBar = liftIO do
(1 == ) <$> [C.exp| bool { BeginMenuBar() } |]
-- | Only call 'endMenuBar' if 'beginMenuBar' returns true!
--
-- Wraps @ImGui::EndMenuBar()@.
endMenuBar :: MonadIO m => m ()
endMenuBar = liftIO do
[C.exp| void { EndMenuBar(); } |]
-- | Create and append to a full screen menu-bar.
--
-- Wraps @ImGui::BeginMainMenuBar()@.
beginMainMenuBar :: MonadIO m => m Bool
beginMainMenuBar = liftIO do
(1 == ) <$> [C.exp| bool { BeginMainMenuBar() } |]
-- | Only call 'endMainMenuBar' if 'beginMainMenuBar' returns true!
--
-- Wraps @ImGui::EndMainMenuBar()@.
endMainMenuBar :: MonadIO m => m ()
endMainMenuBar = liftIO do
[C.exp| void { EndMainMenuBar(); } |]
-- | Create a sub-menu entry.
--
-- Wraps @ImGui::BeginMenu()@.
beginMenu :: MonadIO m => String -> m Bool
beginMenu label = liftIO do
withCString label \labelPtr ->
(1 == ) <$> [C.exp| bool { BeginMenu($(char* labelPtr)) } |]
-- | Only call 'endMenu' if 'beginMenu' returns true!
--
-- Wraps @ImGui::EndMenu()@.
endMenu :: MonadIO m => m ()
endMenu = liftIO do
[C.exp| void { EndMenu(); } |]
-- Return true when activated. Shortcuts are displayed for convenience but not
-- processed by ImGui at the moment
--
-- Wraps @ImGui::MenuItem()@
menuItem :: MonadIO m => String -> m Bool
menuItem label = liftIO do
withCString label \labelPtr ->
(1 ==) <$> [C.exp| bool { MenuItem($(char* labelPtr)) } |]
-- | A cardinal direction.
newtype ImGuiDir = ImGuiDir CInt