Skip to content

Commit

Permalink
Add DearImGui.withCloseableWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
jship committed Dec 14, 2023
1 parent 0f63f0e commit c8f30fa
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/DearImGui.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module DearImGui
-- * Windows
, withWindow
, withWindowOpen
, withCloseableWindow
, withFullscreen
, fullscreenFlags

Expand Down Expand Up @@ -416,6 +417,26 @@ withWindowOpen :: MonadUnliftIO m => Text -> m () -> m ()
withWindowOpen name action =
withWindow name (`when` action)

-- | Append items to a closeable window unless it is collapsed or fully clipped.
--
-- You may append multiple times to the same window during the same frame
-- by calling 'withWindowOpen' in multiple places.
--
-- The 'Bool' state variable will be set to 'False' when the window's close
-- button is pressed.
withCloseableWindow :: (HasSetter ref Bool, MonadUnliftIO m) => Text -> ref -> m () -> m ()
withCloseableWindow name ref action = bracket open close (`when` action)
where
open = liftIO do
with 1 \boolPtr -> do
Text.withCString name \namePtr -> do
isVisible <- Raw.begin namePtr (Just boolPtr) Nothing
isOpen <- peek boolPtr
when (isOpen == 0) $ ref $=! False
pure isVisible

close = liftIO . const Raw.end

-- | Append items to a fullscreen window.
--
-- The action runs inside a window that is set to behave as a backdrop.
Expand Down

0 comments on commit c8f30fa

Please sign in to comment.