Skip to content

Commit f6cad45

Browse files
authored
Add support for disabled blocks (#196)
1 parent 49f7bb2 commit f6cad45

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/DearImGui.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ module DearImGui
279279
, Raw.beginTooltip
280280
, Raw.endTooltip
281281

282+
-- ** Disabled blocks
283+
, withDisabled
284+
, Raw.beginDisabled
285+
, Raw.endDisabled
286+
282287
-- * Popups/Modals
283288

284289
-- ** Generic
@@ -1763,6 +1768,17 @@ setTabItemClosed tabName = liftIO do
17631768
withTooltip :: MonadUnliftIO m => m a -> m a
17641769
withTooltip = bracket_ Raw.beginTooltip Raw.endTooltip
17651770

1771+
1772+
-- | Action wrapper for disabled blocks.
1773+
--
1774+
-- See 'Raw.beginDisabled' and 'Raw.endDisabled' for more info.
1775+
withDisabled :: (MonadUnliftIO m, HasGetter ref Bool) => ref -> m a -> m a
1776+
withDisabled disabledRef action = do
1777+
disabled <- get disabledRef
1778+
if disabled then bracket_ (Raw.beginDisabled 1) Raw.endDisabled action else action
1779+
1780+
1781+
17661782
-- | Returns 'True' if the popup is open, and you can start outputting to it.
17671783
--
17681784
-- Wraps @ImGui::BeginPopup()@

src/DearImGui/Raw.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ module DearImGui.Raw
6565
, setNextWindowSizeConstraints
6666
, setNextWindowCollapsed
6767
, setNextWindowBgAlpha
68+
, beginDisabled
69+
, endDisabled
6870

6971
-- ** Child Windows
7072
, beginChild
@@ -1582,6 +1584,29 @@ setNextWindowBgAlpha alpha = liftIO do
15821584
[C.exp| void { SetNextWindowBgAlpha($(float alpha)) } |]
15831585

15841586

1587+
-- | Begin a block that may be disabled. This disables all user interactions
1588+
-- and dims item visuals.
1589+
--
1590+
-- Always call a matching 'endDisabled' for each 'beginDisabled' call.
1591+
--
1592+
-- The boolean argument is only intended to facilitate use of boolean
1593+
-- expressions. If you can avoid calling @beginDisabled 0@ altogether,
1594+
-- that should be preferred.
1595+
--
1596+
-- Wraps @ImGui::BeginDisabled()@
1597+
beginDisabled :: (MonadIO m) => CBool -> m ()
1598+
beginDisabled disabled = liftIO do
1599+
[C.exp| void { BeginDisabled($(bool disabled)) } |]
1600+
1601+
1602+
-- | Ends a block that may be disabled.
1603+
--
1604+
-- Wraps @ImGui::EndDisabled()@
1605+
endDisabled :: (MonadIO m) => m ()
1606+
endDisabled = liftIO do
1607+
[C.exp| void { EndDisabled() } |]
1608+
1609+
15851610
-- | undo a sameLine or force a new line when in an horizontal-layout context.
15861611
--
15871612
-- Wraps @ImGui::NewLine()@

0 commit comments

Comments
 (0)