Skip to content

Commit

Permalink
Clean CTypes from DearImGui wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwiz committed Jul 19, 2024
1 parent c2c1535 commit d10f16e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
34 changes: 29 additions & 5 deletions src/DearImGui.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ module DearImGui
, Raw.getWindowDrawList
, Raw.getWindowPos
, Raw.getWindowSize
, Raw.getWindowWidth
, Raw.getWindowHeight
, getWindowWidth
, getWindowHeight
, Raw.isWindowAppearing
, Raw.isWindowCollapsed
, Raw.isWindowFocused
Expand Down Expand Up @@ -101,7 +101,8 @@ module DearImGui
, withStyleVar
, pushStyleVar
, popStyleVar
, Raw.pushTabStop
, withTabStop
, pushTabStop
, Raw.popTabStop

, withFont
Expand Down Expand Up @@ -341,7 +342,7 @@ module DearImGui

-- ** Disabled blocks
, withDisabled
, Raw.beginDisabled
, beginDisabled
, Raw.endDisabled

-- * Popups/Modals
Expand Down Expand Up @@ -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.
--
Expand Down Expand Up @@ -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.
--
Expand Down Expand Up @@ -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`.
Expand Down
3 changes: 1 addition & 2 deletions src/DearImGui/Raw.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) } |]
Expand Down Expand Up @@ -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)) } |]
Expand Down

0 comments on commit d10f16e

Please sign in to comment.