@@ -326,6 +326,7 @@ module DearImGui
326326 , beginMenu
327327 , Raw. endMenu
328328
329+ , menuItemEx
329330 , menuItem
330331 , menuItemChecked
331332
@@ -2139,34 +2140,76 @@ withMenuOpen :: MonadUnliftIO m => Text -> m () -> m ()
21392140withMenuOpen label action =
21402141 withMenu label (`when` action)
21412142
2142- -- | Return true when activated. Shortcuts are displayed for convenience but not
2143- -- processed by ImGui at the moment
2143+ -- | Menu item with optional shortcut and checkmark.
2144+ --
2145+ -- Returns whether the item was activated (clicked).
2146+ -- If a checkmark is provided, it will be updated to reflect
2147+ -- the new state.
2148+ --
2149+ -- Note that shortcuts are displayed for convenience only and
2150+ -- are not automatically handled by ImGui.
2151+ --
2152+ -- Wraps @ImGui::MenuItem()@
2153+ menuItemEx
2154+ :: MonadIO m
2155+ => Text
2156+ -> Maybe Text
2157+ -> Maybe Bool
2158+ -> m (Bool , Maybe Bool )
2159+ menuItemEx label maybeShortcut maybeChecked = liftIO do
2160+ Text. withCString label $ \ labelPtr ->
2161+ case maybeShortcut of
2162+ Nothing ->
2163+ withCString " " $ \ shortcutPtr ->
2164+ go labelPtr shortcutPtr
2165+ Just shortcut ->
2166+ Text. withCString shortcut $ \ shortcutPtr ->
2167+ go labelPtr shortcutPtr
2168+ where
2169+ go labelPtr shortcutPtr =
2170+ case maybeChecked of
2171+ Nothing -> do
2172+ activated <- Raw. menuItemEx labelPtr shortcutPtr nullPtr
2173+ pure (activated, Nothing )
2174+
2175+ Just checked ->
2176+ alloca $ \ ptr -> do
2177+ poke ptr (fromBool checked)
2178+ activated <- Raw. menuItemEx labelPtr shortcutPtr ptr
2179+ newChecked <- toBool <$> peek ptr
2180+ pure (activated, Just newChecked)
2181+
2182+ -- | Simple menu item without shortcut or checkmark.
2183+ --
2184+ -- Returns True when activated.
2185+ -- This is a convenience wrapper over 'menuItemEx'.
21442186--
21452187-- Wraps @ImGui::MenuItem()@
21462188menuItem :: MonadIO m => Text -> m Bool
2147- menuItem label = liftIO do
2148- Text. withCString label Raw. menuItem
2189+ menuItem label = do
2190+ (activated, _) <- menuItemEx label Nothing Nothing
2191+ pure activated
21492192
21502193-- | Menu item with checkmark
21512194--
2152- -- Returns True when activated (clicked). The ref's value will be updated to match the checkmark state.
2195+ -- Returns (activated, newCheckedState) for whether the item
2196+ -- was activated and the updated checkmark state.
2197+ -- This is a convenience wrapper over 'menuItemEx'.
21532198menuItemChecked
21542199 :: MonadIO m
21552200 => Text
21562201 -> Maybe Text
21572202 -> Bool
21582203 -> m (Bool , Bool )
2159- menuItemChecked label maybeShortcut isChecked = liftIO do
2160- let shortcut = case maybeShortcut of
2161- Nothing -> " "
2162- Just s -> s
2163- Text. withCString label $ \ labelPtr ->
2164- Text. withCString shortcut $ \ shortcutPtr ->
2165- alloca $ \ ptr -> do
2166- poke ptr (fromBool isChecked)
2167- activated <- Raw. menuItemChecked labelPtr shortcutPtr ptr
2168- newChecked <- toBool <$> peek ptr
2169- pure (activated, newChecked)
2204+ menuItemChecked label maybeShortcut isChecked = do
2205+ (activated, mChecked) <-
2206+ menuItemEx label maybeShortcut (Just isChecked)
2207+ case mChecked of
2208+ Just newChecked ->
2209+ pure (activated, newChecked)
2210+ Nothing ->
2211+ -- This should be impossible, but keeps the function total
2212+ pure (activated, isChecked)
21702213
21712214-- | Create a @TabBar@ and start appending to it.
21722215--
0 commit comments