From b837d583a5a488b2691cca11cc4ac6fc4b202dc2 Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Fri, 25 Feb 2022 18:28:53 +0100 Subject: [PATCH] added openPopupOnItemClick (#133) --- src/DearImGui.hs | 12 ++++++++++++ src/DearImGui/Raw.hs | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/DearImGui.hs b/src/DearImGui.hs index 45a4133..5b86705 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -245,6 +245,7 @@ module DearImGui , Raw.endPopup , openPopup + , openPopupOnItemClick , Raw.closeCurrentPopup -- * Item/Widgets Utilities @@ -1486,6 +1487,17 @@ openPopup :: MonadIO m => String -> m () openPopup popupId = liftIO do withCString popupId Raw.openPopup +-- | Opens a defined popup (i.e. defined with 'withPopup') on defined action. +-- +-- Example: +-- +-- > openPopupOnItemClick "myPopup" ImGuiPopupFlags_MouseButtonRight +-- +-- Wraps @ImGui::OpenPopup()@ +openPopupOnItemClick :: MonadIO m => String -> ImGuiPopupFlags -> m () +openPopupOnItemClick popupId flags = liftIO do + withCString popupId $ \popupId' -> Raw.openPopupOnItemClick popupId' flags + withCStringOrNull :: Maybe String -> (Ptr CChar -> IO a) -> IO a withCStringOrNull Nothing k = k nullPtr diff --git a/src/DearImGui/Raw.hs b/src/DearImGui/Raw.hs index 66ca8f9..707e18b 100644 --- a/src/DearImGui/Raw.hs +++ b/src/DearImGui/Raw.hs @@ -197,6 +197,7 @@ module DearImGui.Raw , beginPopupModal , endPopup , openPopup + , openPopupOnItemClick , closeCurrentPopup -- * ID stack/scopes @@ -1252,6 +1253,13 @@ 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!). +-- +-- Wraps @ImGui::OpenPopupOnItemClick()@ +openPopupOnItemClick :: (MonadIO m) => CString -> ImGuiPopupFlags-> m () +openPopupOnItemClick popupIdPtr flags = liftIO do + [C.exp| void { OpenPopupOnItemClick($(char* popupIdPtr), $(ImGuiPopupFlags flags)) } |] + -- | Manually close the popup we have begin-ed into. --