Add more withXXX wrappers (#82)

- withStyleColor
- withStyleVar
- withIndent
- withItemWidth

Closes #63
This commit is contained in:
Alexander Bondarenko 2021-09-01 20:23:59 +03:00 committed by GitHub
parent d3a0396623
commit 8d07a5a42b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,8 +64,11 @@ module DearImGui
, Raw.endChild
-- * Parameter stacks
, withStyleColor
, pushStyleColor
, Raw.popStyleColor
, withStyleVar
, pushStyleVar
, popStyleVar
@ -75,9 +78,13 @@ module DearImGui
, Raw.newLine
, Raw.spacing
, dummy
, withIndent
, indent
, unindent
, setNextItemWidth
, withItemWidth
, pushItemWidth
, Raw.popItemWidth
@ -1420,6 +1427,9 @@ dummy sizeRef = liftIO do
size' <- get sizeRef
with size' Raw.dummy
withIndent :: MonadUnliftIO m => Float -> m a -> m a
withIndent width =
bracket_ (indent width) (unindent width)
-- | Move content position toward the right, by indent_w, or style.IndentSpacing if indent_w <= 0
--
@ -1445,6 +1455,10 @@ setNextItemWidth itemWidth = liftIO do
Raw.setNextItemWidth (CFloat itemWidth)
withItemWidth :: MonadUnliftIO m => Float -> m a -> m a
withItemWidth width =
bracket_ (pushItemWidth width) Raw.popItemWidth
-- Wraps @ImGui::PushItemWidth()@
pushItemWidth :: (MonadIO m) => Float -> m ()
pushItemWidth itemWidth = liftIO do
@ -1504,7 +1518,13 @@ instance ToID (Ptr CChar, Int) where
instance ToID String where
pushID s = liftIO $ withCStringLen s pushID
-- | Modify a style color by pushing to the shared stack. always use this if you modify the style after `newFrame`
withStyleColor :: (MonadUnliftIO m, HasGetter ref ImVec4) => ImGuiCol -> ref -> m a -> m a
withStyleColor color ref =
bracket_ (pushStyleColor color ref) (Raw.popStyleColor 1)
-- | Modify a style color by pushing to the shared stack.
--
-- Always use this if you modify the style after `newFrame`.
--
-- Wraps @ImGui::PushStyleColor()@
pushStyleColor :: (MonadIO m, HasGetter ref ImVec4) => ImGuiCol -> ref -> m ()
@ -1513,8 +1533,13 @@ pushStyleColor col colorRef = liftIO do
with color \colorPtr ->
Raw.pushStyleColor col colorPtr
withStyleVar :: (MonadUnliftIO m, HasGetter ref ImVec2) => ImGuiStyleVar -> ref -> m a -> m a
withStyleVar style ref =
bracket_ (pushStyleVar style ref) (Raw.popStyleVar 1)
-- | Modify a style variable by pushing to the shared stack. always use this if you modify the style after `newFrame`
-- | Modify a style variable by pushing to the shared stack.
--
-- Always use this if you modify the style after `newFrame`.
--
-- Wraps @ImGui::PushStyleVar()@
pushStyleVar :: (MonadIO m, HasGetter ref ImVec2) => ImGuiStyleVar -> ref -> m ()
@ -1523,7 +1548,6 @@ pushStyleVar style valRef = liftIO do
with val \valPtr ->
Raw.pushStyleVar style valPtr
-- | Remove style variable modifications from the shared stack
--
-- Wraps @ImGui::PopStyleVar()@