Skip to content

Comments

add Menuitem checked#228

Open
AskBid wants to merge 4 commits intohaskell-game:mainfrom
AskBid:menuitem-checked
Open

add Menuitem checked#228
AskBid wants to merge 4 commits intohaskell-game:mainfrom
AskBid:menuitem-checked

Conversation

@AskBid
Copy link
Contributor

@AskBid AskBid commented Jan 13, 2026

Adds support for menu items with checkmarks by exposing the bool* p_selected
variant of ImGui's MenuItem() function.

Changes

Raw API (DearImGui.Raw)

  • Added menuItemBool :: CString -> CString -> Ptr CBool -> m Bool
    • Takes label, shortcut text, and bool pointer
    • Returns True when activated
    • Updates the bool pointer to reflect checkbox state

High-level API (DearImGui)

  • Added menuItemBool :: Text -> Maybe Text -> Bool -> m (Bool, Bool)
    • Takes label, optional shortcut, and current checked state
    • Returns (was clicked, new checked state)
    • Pure interface - caller manages state

Example Usage

currentState <- use (myState . someFlag)
(clicked, newState) <- ImGui.menuItemBool "My Option" Nothing currentState
myState . someFlag .= newState

This enables proper checkable menu items as seen in the C++ demo.

-- Return true when activated. The bool pointer will be updated to reflect the new state.
--
-- Wraps @ImGui::MenuItem()@ with bool* parameter
menuItemBool :: (MonadIO m) => CString -> CString -> Ptr CBool -> m Bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use menuItemChecked too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, done. thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just drop the short one from raw, and make it take all 3 args.
The non-raw wrapper then can pass nulls there.

src/DearImGui.hs Outdated
-> Maybe Text
-> Bool
-> m (Bool, Bool)
menuItemChecked label maybeShortcut isChecked = liftIO do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this one picks up a shortcuts capability, please give it a proper intro too as menuItemEx. The original menuItem will stay as a shorthand, and this will give everything.

- Replace raw MenuItem bindings with a single full-parameter variant
- Add menuItemEx to the high-level API
- Keep menuItem and menuItemChecked as a shorthand wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants