Wrap ImGui popups

This commit is contained in:
Ollie Charles 2021-01-24 17:35:00 +00:00
parent c4d54a6e36
commit 93b729dae3
2 changed files with 55 additions and 1 deletions

View File

@ -45,9 +45,13 @@ loop w checked = do
text "Hello!"
button "Click me" >>= \case
True -> putStrLn "Oh hi Mark"
True -> openPopup "Button Popup"
False -> return ()
beginPopupModal "Button Popup" >>= whenTrue do
button "Close" >>= whenTrue closeCurrentPopup
endPopup
sameLine >> smallButton "Click me" >>= \case
True -> putStrLn "Oh hi Mark"
False -> return ()

View File

@ -80,6 +80,13 @@ module DearImGui
, endMenu
, menuItem
-- * Popups/Modals
, beginPopup
, beginPopupModal
, endPopup
, openPopup
, closeCurrentPopup
-- * Types
, ImGuiDir
, pattern ImGuiDirLeft
@ -483,6 +490,49 @@ menuItem label = liftIO do
(1 ==) <$> [C.exp| bool { MenuItem($(char* labelPtr)) } |]
-- | Returns 'True' if the popup is open, and you can start outputting to it.
--
-- Wraps @ImGui::BeginPopup()@
beginPopup :: MonadIO m => String -> m Bool
beginPopup popupId = liftIO do
withCString popupId \popupIdPtr ->
(1 ==) <$> [C.exp| bool { BeginPopup($(char* popupIdPtr)) } |]
-- | Returns 'True' if the modal is open, and you can start outputting to it.
--
-- Wraps @ImGui::BeginPopupModal()@
beginPopupModal :: MonadIO m => String -> m Bool
beginPopupModal popupId = liftIO do
withCString popupId \popupIdPtr ->
(1 ==) <$> [C.exp| bool { BeginPopupModal($(char* popupIdPtr)) } |]
-- | Only call 'endPopup' if 'beginPopup' or 'beginPopupModal' returns 'True'!
--
-- Wraps @ImGui::BeginPopupModal()@
endPopup :: MonadIO m => m ()
endPopup = liftIO do
[C.exp| void { EndPopup() } |]
-- | Call to mark popup as open (don't call every frame!).
--
-- Wraps @ImGui::OpenPopup()@
openPopup :: MonadIO m => String -> m ()
openPopup popupId = liftIO do
withCString popupId \popupIdPtr ->
[C.exp| void { OpenPopup($(char* popupIdPtr)) } |]
-- | Manually close the popup we have begin-ed into.
--
-- Wraps @ImGui::ClosePopup()@
closeCurrentPopup :: MonadIO m => m ()
closeCurrentPopup = liftIO do
[C.exp| void { CloseCurrentPopup() } |]
-- | A cardinal direction.
newtype ImGuiDir = ImGuiDir CInt