From d10f16e7418e981fe5ad90e12253040d269b2ebc Mon Sep 17 00:00:00 2001 From: IC Rainbow Date: Fri, 19 Jul 2024 22:03:01 +0300 Subject: [PATCH] Clean CTypes from DearImGui wrappers --- ChangeLog.md | 1 + src/DearImGui.hs | 34 +++++++++++++++++++++++++++++----- src/DearImGui/Raw.hs | 3 +-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 9496347..60c3ab4 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -10,6 +10,7 @@ * Breaking: ImplVulkan moved RenderPass into InitInfo structure. + Breaking: Haskell API is now using `Either RenderPass RenderingPipelineCreateInfo` to switch between RP/dynamic rendering. - Added lots of missing widgets and their wrappers. +- Breaking: a few functions in `DearImGui` switched away from using CFloat/CBool wrappers. ## [2.2.1] diff --git a/src/DearImGui.hs b/src/DearImGui.hs index ff30d7b..2a27628 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -65,8 +65,8 @@ module DearImGui , Raw.getWindowDrawList , Raw.getWindowPos , Raw.getWindowSize - , Raw.getWindowWidth - , Raw.getWindowHeight + , getWindowWidth + , getWindowHeight , Raw.isWindowAppearing , Raw.isWindowCollapsed , Raw.isWindowFocused @@ -101,7 +101,8 @@ module DearImGui , withStyleVar , pushStyleVar , popStyleVar - , Raw.pushTabStop + , withTabStop + , pushTabStop , Raw.popTabStop , withFont @@ -341,7 +342,7 @@ module DearImGui -- ** Disabled blocks , withDisabled - , Raw.beginDisabled + , beginDisabled , Raw.endDisabled -- * Popups/Modals @@ -2179,7 +2180,12 @@ withDisabled disabledRef action = do disabled <- get disabledRef if disabled then bracket_ (Raw.beginDisabled 1) Raw.endDisabled action else action - +-- | Begin a block that may be disabled. This disables all user interactions +-- and dims item visuals. +-- +-- Always call a matching 'endDisabled' for each 'beginDisabled' call. +beginDisabled :: MonadIO m => Bool -> m () +beginDisabled = Raw.beginDisabled . bool 0 1 -- | Returns 'True' if the popup is open, and you can start outputting to it. -- @@ -2323,6 +2329,15 @@ isAnyLevelPopupOpen popupId = liftIO do Raw.isPopupOpen idPtr $ ImGuiPopupFlags_AnyPopupId .|. ImGuiPopupFlags_AnyPopupLevel +getWindowWidth :: MonadIO m => m Float +getWindowWidth = liftIO do + CFloat w <- Raw.getWindowWidth + pure w + +getWindowHeight :: MonadIO m => m Float +getWindowHeight = liftIO do + CFloat w <- Raw.getWindowHeight + pure w -- | Set next window position. Call before `begin` Use pivot=(0.5,0.5) to center on given point, etc. -- @@ -2563,6 +2578,15 @@ withStyleVar :: (MonadUnliftIO m, HasGetter ref ImVec2) => ImGuiStyleVar -> ref withStyleVar style ref = bracket_ (pushStyleVar style ref) (Raw.popStyleVar 1) +-- | Allow/disable focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets. +withTabStop :: MonadUnliftIO m => Bool -> m a -> m a +withTabStop enabled = + bracket_ (pushTabStop enabled) Raw.popTabStop + +-- | Allow/disable focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets. +pushTabStop :: (MonadIO m) => Bool -> m () +pushTabStop = Raw.pushTabStop . bool 0 1 + -- | Modify a style variable by pushing to the shared stack. -- -- Always use this if you modify the style after `newFrame`. diff --git a/src/DearImGui/Raw.hs b/src/DearImGui/Raw.hs index 714813f..fe58a12 100644 --- a/src/DearImGui/Raw.hs +++ b/src/DearImGui/Raw.hs @@ -1545,7 +1545,6 @@ getTreeNodeToLabelSpacing = liftIO do -- @p_visible != NULL && *p_visible == false @ - do not show the header at all. -- -- Do not mistake this with the Open state of the header itself, which you can adjust with SetNextItemOpen() or ImGuiTreeNodeFlags_DefaultOpen. - collapsingHeader :: (MonadIO m) => CString -> Ptr CBool -> ImGuiTreeNodeFlags -> m Bool collapsingHeader labelPtr visiblePtr flags = liftIO do (0 /=) <$> [C.exp| bool { CollapsingHeader($(char* labelPtr), $(bool* visiblePtr), $(ImGuiTreeNodeFlags flags)) } |] @@ -2296,7 +2295,7 @@ popStyleVar :: (MonadIO m) => CInt -> m () popStyleVar n = liftIO do [C.exp| void { PopStyleVar($(int n)) } |] --- | Allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets. +-- | Allow/disable focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets. pushTabStop :: (MonadIO m) => CBool -> m () pushTabStop b = liftIO do [C.exp| void { PushTabStop($(bool b)) } |]