mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2024-11-22 16:57:00 +00:00
Wrap ImGui popups
This commit is contained in:
parent
c4d54a6e36
commit
93b729dae3
6
Main.hs
6
Main.hs
@ -45,9 +45,13 @@ loop w checked = do
|
|||||||
text "Hello!"
|
text "Hello!"
|
||||||
|
|
||||||
button "Click me" >>= \case
|
button "Click me" >>= \case
|
||||||
True -> putStrLn "Oh hi Mark"
|
True -> openPopup "Button Popup"
|
||||||
False -> return ()
|
False -> return ()
|
||||||
|
|
||||||
|
beginPopupModal "Button Popup" >>= whenTrue do
|
||||||
|
button "Close" >>= whenTrue closeCurrentPopup
|
||||||
|
endPopup
|
||||||
|
|
||||||
sameLine >> smallButton "Click me" >>= \case
|
sameLine >> smallButton "Click me" >>= \case
|
||||||
True -> putStrLn "Oh hi Mark"
|
True -> putStrLn "Oh hi Mark"
|
||||||
False -> return ()
|
False -> return ()
|
||||||
|
@ -80,6 +80,13 @@ module DearImGui
|
|||||||
, endMenu
|
, endMenu
|
||||||
, menuItem
|
, menuItem
|
||||||
|
|
||||||
|
-- * Popups/Modals
|
||||||
|
, beginPopup
|
||||||
|
, beginPopupModal
|
||||||
|
, endPopup
|
||||||
|
, openPopup
|
||||||
|
, closeCurrentPopup
|
||||||
|
|
||||||
-- * Types
|
-- * Types
|
||||||
, ImGuiDir
|
, ImGuiDir
|
||||||
, pattern ImGuiDirLeft
|
, pattern ImGuiDirLeft
|
||||||
@ -483,6 +490,49 @@ menuItem label = liftIO do
|
|||||||
(1 ==) <$> [C.exp| bool { MenuItem($(char* labelPtr)) } |]
|
(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.
|
-- | A cardinal direction.
|
||||||
newtype ImGuiDir = ImGuiDir CInt
|
newtype ImGuiDir = ImGuiDir CInt
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user