mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2024-11-22 00:47:00 +00:00
Add isPopupOpen and wrappers (#134)
This commit is contained in:
parent
b837d583a5
commit
4517af8123
@ -64,9 +64,27 @@ mainLoop win = do
|
||||
text "Hello, ImGui!"
|
||||
|
||||
-- Add a button widget, and call 'putStrLn' when it's clicked
|
||||
button "Clickety Click" >>= \case
|
||||
False -> return ()
|
||||
True -> putStrLn "Ow!"
|
||||
clicking <- button "Clickety Click"
|
||||
when clicking $
|
||||
putStrLn "Ow!"
|
||||
|
||||
-- Attach a popup to the latest widget
|
||||
let popupId = "pop-me"
|
||||
openPopupOnItemClick popupId ImGuiPopupFlags_MouseButtonRight
|
||||
|
||||
-- Put some content into a popup window
|
||||
-- alternatively: withPopup (closes automatically)
|
||||
withPopupModalOpen popupId do
|
||||
text "pop!"
|
||||
button "ok" >>= \clicked ->
|
||||
when clicked $
|
||||
closeCurrentPopup
|
||||
|
||||
-- Query popup status
|
||||
popping <- isCurrentPopupOpen popupId
|
||||
when popping do
|
||||
sameLine
|
||||
text "Popping right now."
|
||||
|
||||
-- Show the ImGui demo window
|
||||
showDemoWindow
|
||||
|
@ -248,6 +248,10 @@ module DearImGui
|
||||
, openPopupOnItemClick
|
||||
, Raw.closeCurrentPopup
|
||||
|
||||
, isCurrentPopupOpen
|
||||
, isAnyPopupOpen
|
||||
, isAnyLevelPopupOpen
|
||||
|
||||
-- * Item/Widgets Utilities
|
||||
, Raw.isItemHovered
|
||||
, Raw.wantCaptureMouse
|
||||
@ -1496,7 +1500,27 @@ openPopup popupId = liftIO do
|
||||
-- Wraps @ImGui::OpenPopup()@
|
||||
openPopupOnItemClick :: MonadIO m => String -> ImGuiPopupFlags -> m ()
|
||||
openPopupOnItemClick popupId flags = liftIO do
|
||||
withCString popupId $ \popupId' -> Raw.openPopupOnItemClick popupId' flags
|
||||
withCString popupId $ \idPtr ->
|
||||
Raw.openPopupOnItemClick idPtr flags
|
||||
|
||||
-- | Check if the popup is open at the current 'beginPopup' level of the popup stack.
|
||||
isCurrentPopupOpen :: MonadIO m => String -> m Bool
|
||||
isCurrentPopupOpen popupId = liftIO do
|
||||
withCString popupId $ \idPtr ->
|
||||
Raw.isPopupOpen idPtr ImGuiPopupFlags_None
|
||||
|
||||
-- | Check if *any* popup is open at the current 'beginPopup' level of the popup stack.
|
||||
isAnyPopupOpen :: MonadIO m => String -> m Bool
|
||||
isAnyPopupOpen popupId = liftIO do
|
||||
withCString popupId $ \idPtr ->
|
||||
Raw.isPopupOpen idPtr ImGuiPopupFlags_AnyPopupId
|
||||
|
||||
-- | Check if *any* popup is open at any level of the popup stack.
|
||||
isAnyLevelPopupOpen :: MonadIO m => String -> m Bool
|
||||
isAnyLevelPopupOpen popupId = liftIO do
|
||||
withCString popupId $ \idPtr ->
|
||||
Raw.isPopupOpen idPtr $
|
||||
ImGuiPopupFlags_AnyPopupId .|. ImGuiPopupFlags_AnyPopupLevel
|
||||
|
||||
|
||||
withCStringOrNull :: Maybe String -> (Ptr CChar -> IO a) -> IO a
|
||||
|
@ -199,6 +199,7 @@ module DearImGui.Raw
|
||||
, openPopup
|
||||
, openPopupOnItemClick
|
||||
, closeCurrentPopup
|
||||
, isPopupOpen
|
||||
|
||||
-- * ID stack/scopes
|
||||
, pushIDInt
|
||||
@ -1253,7 +1254,10 @@ openPopup :: (MonadIO m) => CString -> m ()
|
||||
openPopup popupIdPtr = liftIO do
|
||||
[C.exp| void { OpenPopup($(char* popupIdPtr)) } |]
|
||||
|
||||
-- | Call to mark popup as open (don't call every frame!).
|
||||
|
||||
-- | helper to open popup when clicked on last item.
|
||||
--
|
||||
-- Note: actually triggers on the mouse _released_ event to be consistent with popup behaviors.
|
||||
--
|
||||
-- Wraps @ImGui::OpenPopupOnItemClick()@
|
||||
openPopupOnItemClick :: (MonadIO m) => CString -> ImGuiPopupFlags-> m ()
|
||||
@ -1269,6 +1273,18 @@ closeCurrentPopup = liftIO do
|
||||
[C.exp| void { CloseCurrentPopup() } |]
|
||||
|
||||
|
||||
-- | Query popup status
|
||||
--
|
||||
-- - return 'True' if the popup is open at the current 'beginPopup' level of the popup stack.
|
||||
-- - with 'ImGuiPopupFlags_AnyPopupId': return 'True' if any popup is open at the current 'beginPopup' level of the popup stack.
|
||||
-- - with 'ImGuiPopupFlags_AnyPopupId' | 'ImGuiPopupFlags_AnyPopupLevel': return 'True' if any popup is open.
|
||||
--
|
||||
-- Wraps @ImGui::IsPopupOpen()@
|
||||
isPopupOpen :: (MonadIO m) => CString -> ImGuiPopupFlags-> m Bool
|
||||
isPopupOpen popupIdPtr flags = liftIO do
|
||||
(0 /=) <$> [C.exp| bool { IsPopupOpen($(char* popupIdPtr), $(ImGuiPopupFlags flags)) } |]
|
||||
|
||||
|
||||
-- | Is the last item hovered? (and usable, aka not blocked by a popup, etc.).
|
||||
--
|
||||
-- Wraps @ImGui::IsItemHovered()@
|
||||
|
Loading…
Reference in New Issue
Block a user