mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2024-11-22 16:57:00 +00:00
Add remaining popup wrappers (#136)
- BeginPopupContextItem - BeginPopupContextWindow - BeginPopupContextVoid For #132
This commit is contained in:
parent
4517af8123
commit
fc307a4d6e
@ -67,25 +67,12 @@ mainLoop win = do
|
|||||||
clicking <- button "Clickety Click"
|
clicking <- button "Clickety Click"
|
||||||
when clicking $
|
when clicking $
|
||||||
putStrLn "Ow!"
|
putStrLn "Ow!"
|
||||||
|
itemContextPopup do
|
||||||
-- 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!"
|
text "pop!"
|
||||||
button "ok" >>= \clicked ->
|
button "ok" >>= \clicked ->
|
||||||
when clicked $
|
when clicked $
|
||||||
closeCurrentPopup
|
closeCurrentPopup
|
||||||
|
|
||||||
-- Query popup status
|
|
||||||
popping <- isCurrentPopupOpen popupId
|
|
||||||
when popping do
|
|
||||||
sameLine
|
|
||||||
text "Popping right now."
|
|
||||||
|
|
||||||
-- Show the ImGui demo window
|
-- Show the ImGui demo window
|
||||||
showDemoWindow
|
showDemoWindow
|
||||||
|
|
||||||
|
@ -234,20 +234,42 @@ module DearImGui
|
|||||||
, Raw.endTooltip
|
, Raw.endTooltip
|
||||||
|
|
||||||
-- * Popups/Modals
|
-- * Popups/Modals
|
||||||
|
|
||||||
|
-- ** Generic
|
||||||
, withPopup
|
, withPopup
|
||||||
, withPopupOpen
|
, withPopupOpen
|
||||||
, beginPopup
|
, beginPopup
|
||||||
|
, Raw.endPopup
|
||||||
|
|
||||||
|
-- ** Modal
|
||||||
, withPopupModal
|
, withPopupModal
|
||||||
, withPopupModalOpen
|
, withPopupModalOpen
|
||||||
, beginPopupModal
|
, beginPopupModal
|
||||||
|
|
||||||
, Raw.endPopup
|
-- ** Item context
|
||||||
|
, itemContextPopup
|
||||||
|
, withPopupContextItemOpen
|
||||||
|
, withPopupContextItem
|
||||||
|
, beginPopupContextItem
|
||||||
|
|
||||||
|
-- ** Window context
|
||||||
|
, windowContextPopup
|
||||||
|
, withPopupContextWindowOpen
|
||||||
|
, withPopupContextWindow
|
||||||
|
, beginPopupContextWindow
|
||||||
|
|
||||||
|
-- ** Void context
|
||||||
|
, voidContextPopup
|
||||||
|
, withPopupContextVoidOpen
|
||||||
|
, withPopupContextVoid
|
||||||
|
, beginPopupContextVoid
|
||||||
|
|
||||||
|
-- ** Manual
|
||||||
, openPopup
|
, openPopup
|
||||||
, openPopupOnItemClick
|
, openPopupOnItemClick
|
||||||
, Raw.closeCurrentPopup
|
, Raw.closeCurrentPopup
|
||||||
|
|
||||||
|
-- ** Queries
|
||||||
, isCurrentPopupOpen
|
, isCurrentPopupOpen
|
||||||
, isAnyPopupOpen
|
, isAnyPopupOpen
|
||||||
, isAnyLevelPopupOpen
|
, isAnyLevelPopupOpen
|
||||||
@ -1484,6 +1506,52 @@ withPopupModalOpen :: MonadUnliftIO m => String -> m () -> m ()
|
|||||||
withPopupModalOpen popupId action =
|
withPopupModalOpen popupId action =
|
||||||
withPopupModal popupId (`when` action)
|
withPopupModal popupId (`when` action)
|
||||||
|
|
||||||
|
beginPopupContextItem :: MonadIO m => Maybe String -> ImGuiPopupFlags -> m Bool
|
||||||
|
beginPopupContextItem itemId flags = liftIO do
|
||||||
|
withCStringOrNull itemId \popupIdPtr ->
|
||||||
|
Raw.beginPopupContextItem popupIdPtr flags
|
||||||
|
|
||||||
|
withPopupContextItem :: MonadUnliftIO m => Maybe String -> ImGuiPopupFlags -> (Bool -> m a) -> m a
|
||||||
|
withPopupContextItem popupId flags = bracket (beginPopupContextItem popupId flags) (`when` Raw.endPopup)
|
||||||
|
|
||||||
|
withPopupContextItemOpen :: MonadUnliftIO m => Maybe String -> ImGuiPopupFlags -> m () -> m ()
|
||||||
|
withPopupContextItemOpen popupId flags action = withPopupContextItem popupId flags (`when` action)
|
||||||
|
|
||||||
|
-- | Attach item context popup to right mouse button click on a last item.
|
||||||
|
itemContextPopup :: MonadUnliftIO m => m () -> m ()
|
||||||
|
itemContextPopup = withPopupContextItemOpen Nothing ImGuiPopupFlags_MouseButtonRight
|
||||||
|
|
||||||
|
beginPopupContextWindow :: MonadIO m => Maybe String -> ImGuiPopupFlags -> m Bool
|
||||||
|
beginPopupContextWindow popupId flags = liftIO do
|
||||||
|
withCStringOrNull popupId \popupIdPtr ->
|
||||||
|
Raw.beginPopupContextWindow popupIdPtr flags
|
||||||
|
|
||||||
|
withPopupContextWindow :: MonadUnliftIO m => Maybe String -> ImGuiPopupFlags -> (Bool -> m a) -> m a
|
||||||
|
withPopupContextWindow popupId flags = bracket (beginPopupContextWindow popupId flags) (`when` Raw.endPopup)
|
||||||
|
|
||||||
|
withPopupContextWindowOpen :: MonadUnliftIO m => Maybe String -> ImGuiPopupFlags -> m () -> m ()
|
||||||
|
withPopupContextWindowOpen popupId flags action = withPopupContextWindow popupId flags (`when` action)
|
||||||
|
|
||||||
|
-- | Attach item context popup to right mouse button click on a current window.
|
||||||
|
windowContextPopup :: MonadUnliftIO m => m () -> m ()
|
||||||
|
windowContextPopup = withPopupContextWindowOpen Nothing ImGuiPopupFlags_MouseButtonRight
|
||||||
|
|
||||||
|
beginPopupContextVoid :: MonadIO m => Maybe String -> ImGuiPopupFlags -> m Bool
|
||||||
|
beginPopupContextVoid popupId flags = liftIO do
|
||||||
|
withCStringOrNull popupId \popupIdPtr ->
|
||||||
|
Raw.beginPopupContextVoid popupIdPtr flags
|
||||||
|
|
||||||
|
withPopupContextVoid :: MonadUnliftIO m => Maybe String -> ImGuiPopupFlags -> (Bool -> m a) -> m a
|
||||||
|
withPopupContextVoid popupId flags = bracket (beginPopupContextVoid popupId flags) (`when` Raw.endPopup)
|
||||||
|
|
||||||
|
withPopupContextVoidOpen :: MonadUnliftIO m => Maybe String -> ImGuiPopupFlags -> m () -> m ()
|
||||||
|
withPopupContextVoidOpen popupId flags action = withPopupContextVoid popupId flags (`when` action)
|
||||||
|
|
||||||
|
-- | Attach item context popup to right mouse button click outside of any windows.
|
||||||
|
voidContextPopup :: MonadUnliftIO m => m () -> m ()
|
||||||
|
voidContextPopup = withPopupContextWindowOpen Nothing ImGuiPopupFlags_MouseButtonRight
|
||||||
|
|
||||||
|
|
||||||
-- | Call to mark popup as open (don't call every frame!).
|
-- | Call to mark popup as open (don't call every frame!).
|
||||||
--
|
--
|
||||||
-- Wraps @ImGui::OpenPopup()@
|
-- Wraps @ImGui::OpenPopup()@
|
||||||
|
@ -199,6 +199,9 @@ module DearImGui.Raw
|
|||||||
, openPopup
|
, openPopup
|
||||||
, openPopupOnItemClick
|
, openPopupOnItemClick
|
||||||
, closeCurrentPopup
|
, closeCurrentPopup
|
||||||
|
, beginPopupContextItem
|
||||||
|
, beginPopupContextWindow
|
||||||
|
, beginPopupContextVoid
|
||||||
, isPopupOpen
|
, isPopupOpen
|
||||||
|
|
||||||
-- * ID stack/scopes
|
-- * ID stack/scopes
|
||||||
@ -1255,7 +1258,7 @@ openPopup popupIdPtr = liftIO do
|
|||||||
[C.exp| void { OpenPopup($(char* popupIdPtr)) } |]
|
[C.exp| void { OpenPopup($(char* popupIdPtr)) } |]
|
||||||
|
|
||||||
|
|
||||||
-- | helper to open popup when clicked on last item.
|
-- | Open popup when clicked on last item.
|
||||||
--
|
--
|
||||||
-- Note: actually triggers on the mouse _released_ event to be consistent with popup behaviors.
|
-- Note: actually triggers on the mouse _released_ event to be consistent with popup behaviors.
|
||||||
--
|
--
|
||||||
@ -1272,6 +1275,24 @@ closeCurrentPopup :: (MonadIO m) => m ()
|
|||||||
closeCurrentPopup = liftIO do
|
closeCurrentPopup = liftIO do
|
||||||
[C.exp| void { CloseCurrentPopup() } |]
|
[C.exp| void { CloseCurrentPopup() } |]
|
||||||
|
|
||||||
|
-- | Open+begin popup when clicked on last item.
|
||||||
|
--
|
||||||
|
-- Use str_id==NULL to associate the popup to previous item.
|
||||||
|
--
|
||||||
|
-- If you want to use that on a non-interactive item such as 'text' you need to pass in an explicit ID here.
|
||||||
|
beginPopupContextItem :: (MonadIO m) => CString -> ImGuiPopupFlags-> m Bool
|
||||||
|
beginPopupContextItem popupIdPtr flags = liftIO do
|
||||||
|
(0 /=) <$> [C.exp| bool { BeginPopupContextItem($(char* popupIdPtr), $(ImGuiPopupFlags flags)) } |]
|
||||||
|
|
||||||
|
-- | Open+begin popup when clicked on current window.
|
||||||
|
beginPopupContextWindow :: (MonadIO m) => CString -> ImGuiPopupFlags-> m Bool
|
||||||
|
beginPopupContextWindow popupIdPtr flags = liftIO do
|
||||||
|
(0 /=) <$> [C.exp| bool { BeginPopupContextWindow($(char* popupIdPtr), $(ImGuiPopupFlags flags)) } |]
|
||||||
|
|
||||||
|
-- | Open+begin popup when clicked in void (where there are no windows).
|
||||||
|
beginPopupContextVoid :: (MonadIO m) => CString -> ImGuiPopupFlags-> m Bool
|
||||||
|
beginPopupContextVoid popupIdPtr flags = liftIO do
|
||||||
|
(0 /=) <$> [C.exp| bool { BeginPopupContextVoid($(char* popupIdPtr), $(ImGuiPopupFlags flags)) } |]
|
||||||
|
|
||||||
-- | Query popup status
|
-- | Query popup status
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user