diff --git a/src/DearImGui.hs b/src/DearImGui.hs index c117949..ef1f057 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -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()@