Skip to content

Commit bc4b74c

Browse files
committed
Wrap menu support
1 parent 4f9a552 commit bc4b74c

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

Main.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ loop w checked = do
6565
selectable "Testing 2"
6666
endCombo
6767

68+
beginMainMenuBar >>= whenTrue do
69+
beginMenu "Hello" >>= whenTrue do
70+
menuItem "Hello"
71+
endMenu
72+
73+
beginMenu "World" >>= whenTrue do
74+
menuItem "World"
75+
endMenu
76+
77+
endMainMenuBar
78+
6879
end
6980

7081
render

src/DearImGui.hs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ module DearImGui
6767
-- ** Selectables
6868
, selectable
6969

70+
-- ** Menus
71+
, beginMenuBar
72+
, endMenuBar
73+
, beginMainMenuBar
74+
, endMainMenuBar
75+
, beginMenu
76+
, endMenu
77+
, menuItem
78+
7079
-- * Types
7180
, ImGuiDir
7281
, pattern ImGuiDirLeft
@@ -393,6 +402,66 @@ selectable label = liftIO do
393402
(1 == ) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |]
394403

395404

405+
-- | Append to menu-bar of current window (requires 'ImGuiWindowFlagsMenuBar'
406+
-- flag set on parent window).
407+
--
408+
-- Wraps @ImGui::BeginMenuBar()@.
409+
beginMenuBar :: MonadIO m => m Bool
410+
beginMenuBar = liftIO do
411+
(1 == ) <$> [C.exp| bool { BeginMenuBar() } |]
412+
413+
414+
-- | Only call 'endMenuBar' if 'beginMenuBar' returns true!
415+
--
416+
-- Wraps @ImGui::EndMenuBar()@.
417+
endMenuBar :: MonadIO m => m ()
418+
endMenuBar = liftIO do
419+
[C.exp| void { EndMenuBar(); } |]
420+
421+
422+
-- | Create and append to a full screen menu-bar.
423+
--
424+
-- Wraps @ImGui::BeginMainMenuBar()@.
425+
beginMainMenuBar :: MonadIO m => m Bool
426+
beginMainMenuBar = liftIO do
427+
(1 == ) <$> [C.exp| bool { BeginMainMenuBar() } |]
428+
429+
430+
-- | Only call 'endMainMenuBar' if 'beginMainMenuBar' returns true!
431+
--
432+
-- Wraps @ImGui::EndMainMenuBar()@.
433+
endMainMenuBar :: MonadIO m => m ()
434+
endMainMenuBar = liftIO do
435+
[C.exp| void { EndMainMenuBar(); } |]
436+
437+
438+
-- | Create a sub-menu entry.
439+
--
440+
-- Wraps @ImGui::BeginMenu()@.
441+
beginMenu :: MonadIO m => String -> m Bool
442+
beginMenu label = liftIO do
443+
withCString label \labelPtr ->
444+
(1 == ) <$> [C.exp| bool { BeginMenu($(char* labelPtr)) } |]
445+
446+
447+
-- | Only call 'endMenu' if 'beginMenu' returns true!
448+
--
449+
-- Wraps @ImGui::EndMenu()@.
450+
endMenu :: MonadIO m => m ()
451+
endMenu = liftIO do
452+
[C.exp| void { EndMenu(); } |]
453+
454+
455+
-- Return true when activated. Shortcuts are displayed for convenience but not
456+
-- processed by ImGui at the moment
457+
--
458+
-- Wraps @ImGui::MenuItem()@
459+
menuItem :: MonadIO m => String -> m Bool
460+
menuItem label = liftIO do
461+
withCString label \labelPtr ->
462+
(1 ==) <$> [C.exp| bool { MenuItem($(char* labelPtr)) } |]
463+
464+
396465
-- | A cardinal direction.
397466
newtype ImGuiDir = ImGuiDir CInt
398467

0 commit comments

Comments
 (0)