mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2025-07-15 09:13:14 +02:00
Add isPopupOpen and wrappers (#134)
This commit is contained in:
committed by
GitHub
parent
b837d583a5
commit
4517af8123
@ -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()@
|
||||
|
Reference in New Issue
Block a user