Skip to content

Commit b837d58

Browse files
authored
added openPopupOnItemClick (#133)
1 parent 67e169d commit b837d58

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/DearImGui.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ module DearImGui
245245
, Raw.endPopup
246246

247247
, openPopup
248+
, openPopupOnItemClick
248249
, Raw.closeCurrentPopup
249250

250251
-- * Item/Widgets Utilities
@@ -1486,6 +1487,17 @@ openPopup :: MonadIO m => String -> m ()
14861487
openPopup popupId = liftIO do
14871488
withCString popupId Raw.openPopup
14881489

1490+
-- | Opens a defined popup (i.e. defined with 'withPopup') on defined action.
1491+
--
1492+
-- Example:
1493+
--
1494+
-- > openPopupOnItemClick "myPopup" ImGuiPopupFlags_MouseButtonRight
1495+
--
1496+
-- Wraps @ImGui::OpenPopup()@
1497+
openPopupOnItemClick :: MonadIO m => String -> ImGuiPopupFlags -> m ()
1498+
openPopupOnItemClick popupId flags = liftIO do
1499+
withCString popupId $ \popupId' -> Raw.openPopupOnItemClick popupId' flags
1500+
14891501

14901502
withCStringOrNull :: Maybe String -> (Ptr CChar -> IO a) -> IO a
14911503
withCStringOrNull Nothing k = k nullPtr

src/DearImGui/Raw.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ module DearImGui.Raw
197197
, beginPopupModal
198198
, endPopup
199199
, openPopup
200+
, openPopupOnItemClick
200201
, closeCurrentPopup
201202

202203
-- * ID stack/scopes
@@ -1252,6 +1253,13 @@ openPopup :: (MonadIO m) => CString -> m ()
12521253
openPopup popupIdPtr = liftIO do
12531254
[C.exp| void { OpenPopup($(char* popupIdPtr)) } |]
12541255

1256+
-- | Call to mark popup as open (don't call every frame!).
1257+
--
1258+
-- Wraps @ImGui::OpenPopupOnItemClick()@
1259+
openPopupOnItemClick :: (MonadIO m) => CString -> ImGuiPopupFlags-> m ()
1260+
openPopupOnItemClick popupIdPtr flags = liftIO do
1261+
[C.exp| void { OpenPopupOnItemClick($(char* popupIdPtr), $(ImGuiPopupFlags flags)) } |]
1262+
12551263

12561264
-- | Manually close the popup we have begin-ed into.
12571265
--

0 commit comments

Comments
 (0)