From 5634b6f67d0c5f2d94b5b8b475efbcc3ca195e1a Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Mon, 5 Apr 2021 20:16:09 +0300 Subject: [PATCH] Extract raw C bindings (#44) The original DearImGui interface hasn't changed. --- dear-imgui.cabal | 1 + src/DearImGui.hs | 664 ++++++++------------------------ src/DearImGui/Raw.hs | 875 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1027 insertions(+), 513 deletions(-) create mode 100644 src/DearImGui/Raw.hs diff --git a/dear-imgui.cabal b/dear-imgui.cabal index d2fb301..5b26a4f 100644 --- a/dear-imgui.cabal +++ b/dear-imgui.cabal @@ -68,6 +68,7 @@ library src exposed-modules: DearImGui + DearImGui.Raw other-modules: DearImGui.Context DearImGui.Enums diff --git a/src/DearImGui.hs b/src/DearImGui.hs index 925e20b..0912f02 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -16,33 +16,33 @@ Main ImGui module, exporting the functions to create a GUI. module DearImGui ( -- * Context Creation and Access - Context(..) - , createContext - , destroyContext + Raw.Context(..) + , Raw.createContext + , Raw.destroyContext -- * Main - , newFrame - , endFrame - , render - , DrawData(..) - , getDrawData - , checkVersion + , Raw.newFrame + , Raw.endFrame + , Raw.render + , Raw.DrawData(..) + , Raw.getDrawData + , Raw.checkVersion -- * Demo, Debug, Information - , showDemoWindow - , showMetricsWindow - , showAboutWindow - , showUserGuide + , Raw.showDemoWindow + , Raw.showMetricsWindow + , Raw.showAboutWindow + , Raw.showUserGuide , getVersion -- * Styles - , styleColorsDark - , styleColorsLight - , styleColorsClassic + , Raw.styleColorsDark + , Raw.styleColorsLight + , Raw.styleColorsClassic -- * Windows , begin - , end + , Raw.end , setNextWindowPos , setNextWindowSize , setNextWindowContentSize @@ -52,28 +52,29 @@ module DearImGui -- * Child Windows , beginChild - , endChild + , Raw.endChild -- * Parameter stacks , pushStyleColor - , popStyleColor + , Raw.popStyleColor , pushStyleVar , popStyleVar -- * Cursor/Layout - , separator - , sameLine - , newLine - , spacing + , Raw.separator + , Raw.sameLine + , Raw.newLine + , Raw.spacing , dummy , indent , unindent + , setNextItemWidth , pushItemWidth - , popItemWidth - , beginGroup - , endGroup + , Raw.popItemWidth + , Raw.beginGroup + , Raw.endGroup , setCursorPos - , alignTextToFramePadding + , Raw.alignTextToFramePadding -- * Widgets -- ** Text @@ -85,11 +86,11 @@ module DearImGui , arrowButton , checkbox , progressBar - , bullet + , Raw.bullet -- ** Combo Box , beginCombo - , endCombo + , Raw.endCombo , combo -- ** Drag Sliders @@ -114,7 +115,7 @@ module DearImGui -- * Trees , treeNode , treePush - , treePop + , Raw.treePop -- ** Selectables , selectable @@ -126,35 +127,35 @@ module DearImGui , plotHistogram -- ** Menus - , beginMenuBar - , endMenuBar - , beginMainMenuBar - , endMainMenuBar + , Raw.beginMenuBar + , Raw.endMenuBar + , Raw.beginMainMenuBar + , Raw.endMainMenuBar , beginMenu - , endMenu + , Raw.endMenu , menuItem -- ** Tabs, tab bar , beginTabBar - , endTabBar + , Raw.endTabBar , beginTabItem - , endTabItem + , Raw.endTabItem , tabItemButton , setTabItemClosed -- * Tooltips - , beginTooltip - , endTooltip + , Raw.beginTooltip + , Raw.endTooltip -- * Popups/Modals , beginPopup , beginPopupModal - , endPopup + , Raw.endPopup , openPopup - , closeCurrentPopup + , Raw.closeCurrentPopup -- * Item/Widgets Utilities - , isItemHovered + , Raw.isItemHovered -- * Types , module DearImGui.Enums @@ -166,25 +167,13 @@ module DearImGui import Control.Monad ( when ) import Data.Bool -import Data.Coerce - ( coerce ) -import Data.Int - ( Int32 ) import Foreign import Foreign.C -- dear-imgui -import DearImGui.Context - ( imguiContext ) import DearImGui.Enums import DearImGui.Structs --- inline-c -import qualified Language.C.Inline as C - --- inline-c-cpp -import qualified Language.C.Inline.Cpp as Cpp - -- managed import qualified Control.Monad.Managed as Managed @@ -196,127 +185,14 @@ import Data.StateVar import Control.Monad.IO.Class ( MonadIO, liftIO ) - -C.context (Cpp.cppCtx <> C.bsCtx <> imguiContext) -C.include "imgui.h" -Cpp.using "namespace ImGui" - - --- | Wraps @ImGuiContext*@. -newtype Context = Context (Ptr ()) - - --- | Wraps @ImGui::CreateContext()@. -createContext :: MonadIO m => m Context -createContext = liftIO do - Context <$> [C.exp| void* { CreateContext() } |] - - --- | Wraps @ImGui::DestroyContext()@. -destroyContext :: MonadIO m => Context -> m () -destroyContext (Context contextPtr) = liftIO do - [C.exp| void { DestroyContext((ImGuiContext*)$(void* contextPtr)); } |] - - --- | Start a new Dear ImGui frame, you can submit any command from this point --- until 'render'/'endFrame'. --- --- Wraps @ImGui::NewFrame()@. -newFrame :: MonadIO m => m () -newFrame = liftIO do - [C.exp| void { ImGui::NewFrame(); } |] - - --- | Ends the Dear ImGui frame. automatically called by 'render'. If you don't --- need to render data (skipping rendering) you may call 'endFrame' without --- 'render'... but you'll have wasted CPU already! If you don't need to render, --- better to not create any windows and not call 'newFrame' at all! -endFrame :: MonadIO m => m () -endFrame = liftIO do - [C.exp| void { ImGui::EndFrame(); } |] - - --- | Ends the Dear ImGui frame, finalize the draw data. You can then get call --- 'getDrawData'. -render :: MonadIO m => m () -render = liftIO do - [C.exp| void { ImGui::Render(); } |] - - --- | Wraps @ImDrawData*@. -newtype DrawData = DrawData (Ptr ()) - - --- | Valid after 'render' and until the next call to 'newFrame'. This is what --- you have to render. -getDrawData :: MonadIO m => m DrawData -getDrawData = liftIO do - DrawData <$> [C.exp| void* { ImGui::GetDrawData() } |] - - --- | Wraps @IMGUI_CHECKVERSION()@ -checkVersion :: MonadIO m => m () -checkVersion = liftIO do - [C.exp| void { IMGUI_CHECKVERSION(); } |] - - --- | Create demo window. Demonstrate most ImGui features. Call this to learn --- about the library! Try to make it always available in your application! -showDemoWindow :: MonadIO m => m () -showDemoWindow = liftIO do - [C.exp| void { ImGui::ShowDemoWindow(); } |] - - --- | Create Metrics/Debugger window. Display Dear ImGui internals: windows, draw --- commands, various internal state, etc. -showMetricsWindow :: MonadIO m => m () -showMetricsWindow = liftIO do - [C.exp| void { ImGui::ShowMetricsWindow(); } |] - - --- | Create About window. display Dear ImGui version, credits and build/system --- information. -showAboutWindow :: MonadIO m => m () -showAboutWindow = liftIO do - [C.exp| void { ShowAboutWindow(); } |] - - --- | Add basic help/info block (not a window): how to manipulate ImGui as a --- end-user (mouse/keyboard controls). -showUserGuide :: MonadIO m => m () -showUserGuide = liftIO do - [C.exp| void { ShowUserGuide() } |] +import qualified DearImGui.Raw as Raw -- | Get the compiled version string e.g. "1.80 WIP" (essentially the value for -- @IMGUI_VERSION@ from the compiled version of @imgui.cpp@). getVersion :: MonadIO m => m String getVersion = liftIO do - peekCString =<< [C.exp| const char* { GetVersion() } |] - - --- | New, recommended style (default). --- --- Wraps @ImGui::StyleColorsDark()@. -styleColorsDark :: MonadIO m => m () -styleColorsDark = liftIO do - [C.exp| void { StyleColorsDark(); } |] - - --- | Best used with borders and a custom, thicker font. --- --- Wraps @ImGui::StyleColorsLight()@. -styleColorsLight :: MonadIO m => m () -styleColorsLight = liftIO do - [C.exp| void { StyleColorsLight(); } |] - - --- | Classic ImGui style. --- --- Wraps @ImGui::StyleColorsClasic()@. -styleColorsClassic :: MonadIO m => m () -styleColorsClassic = liftIO do - [C.exp| void { StyleColorsClassic(); } |] + peekCString =<< Raw.getVersion -- | Push window to the stack and start appending to it. @@ -328,46 +204,13 @@ styleColorsClassic = liftIO do -- Wraps @ImGui::Begin()@. begin :: MonadIO m => String -> m Bool begin name = liftIO do - withCString name \namePtr -> - (0 /=) <$> [C.exp| bool { ImGui::Begin($(char* namePtr)) } |] - - --- | Pop window from the stack. --- --- Wraps @ImGui::End()@. -end :: MonadIO m => m () -end = liftIO do - [C.exp| void { ImGui::End(); } |] + withCString name Raw.begin -- | Wraps @ImGui::BeginChild()@. beginChild :: MonadIO m => String -> m Bool beginChild name = liftIO do - withCString name \namePtr -> - (0 /=) <$> [C.exp| bool { ImGui::BeginChild($(char* namePtr)) } |] - - --- | Wraps @ImGui::EndChild()@. -endChild :: MonadIO m => m () -endChild = liftIO do - [C.exp| void { ImGui::EndChild(); } |] - - --- | Separator, generally horizontal. inside a menu bar or in horizontal layout --- mode, this becomes a vertical separator. --- --- Wraps @ImGui::Separator()@ -separator :: MonadIO m => m () -separator = liftIO do - [C.exp| void { Separator(); } |] - - --- | Call between widgets or groups to layout them horizontally. --- --- Wraps @ImGui::SameLine@. -sameLine :: MonadIO m => m () -sameLine = liftIO do - [C.exp| void { SameLine(); } |] + withCString name Raw.beginChild -- | Formatted text. @@ -375,8 +218,7 @@ sameLine = liftIO do -- Wraps @ImGui::Text()@. text :: MonadIO m => String -> m () text t = liftIO do - withCString t \textPtr -> - [C.exp| void { Text("%s", $(char* textPtr)) } |] + withCString t Raw.text -- | A button. Returns 'True' when clicked. @@ -384,8 +226,7 @@ text t = liftIO do -- Wraps @ImGui::Button()@. button :: MonadIO m => String -> m Bool button label = liftIO do - withCString label \labelPtr -> - (0 /=) <$> [C.exp| bool { Button($(char* labelPtr)) } |] + withCString label Raw.button -- | Button with @FramePadding=(0,0)@ to easily embed within text. @@ -393,8 +234,7 @@ button label = liftIO do -- Wraps @ImGui::SmallButton()@. smallButton :: MonadIO m => String -> m Bool smallButton label = liftIO do - withCString label \labelPtr -> - (0 /=) <$> [C.exp| bool { SmallButton($(char* labelPtr)) } |] + withCString label Raw.smallButton -- | Square button with an arrow shape. @@ -403,16 +243,16 @@ smallButton label = liftIO do arrowButton :: MonadIO m => String -> ImGuiDir -> m Bool arrowButton strId dir = liftIO do withCString strId \strIdPtr -> - (0 /=) <$> [C.exp| bool { ArrowButton($(char* strIdPtr), $(ImGuiDir dir)) } |] + Raw.arrowButton strIdPtr dir -- | Wraps @ImGui::Checkbox()@. checkbox :: (HasSetter ref Bool, HasGetter ref Bool, MonadIO m) => String -> ref -> m Bool checkbox label ref = liftIO do currentValue <- get ref - with (bool 0 1 currentValue :: CBool) \boolPtr -> do + with (bool 0 1 currentValue) \boolPtr -> do changed <- withCString label \labelPtr -> - (0 /=) <$> [C.exp| bool { Checkbox($(char* labelPtr), $(bool* boolPtr)) } |] + Raw.checkbox labelPtr boolPtr when changed do newValue <- peek boolPtr @@ -424,17 +264,7 @@ checkbox label ref = liftIO do progressBar :: MonadIO m => Float -> Maybe String -> m () progressBar progress overlay = liftIO do withCStringOrNull overlay \overlayPtr -> - [C.exp| void { ProgressBar($(float c'progress), ImVec2(-FLT_MIN, 0), $(char* overlayPtr)) } |] - where - c'progress :: CFloat - c'progress = realToFrac progress - - --- | Draw a small circle + keep the cursor on the same line. Advance cursor x --- position by 'getTreeNodeToLabelSpacing', same distance that 'treeNode' uses. -bullet :: MonadIO m => m () -bullet = liftIO do - [C.exp| void { Bullet() } |] + Raw.progressBar (CFloat progress) overlayPtr -- | Begin creating a combo box with a given label and preview value. @@ -447,15 +277,7 @@ beginCombo :: MonadIO m => String -> String -> m Bool beginCombo label previewValue = liftIO $ withCString label \labelPtr -> withCString previewValue \previewValuePtr -> - (0 /=) <$> [C.exp| bool { BeginCombo($(char* labelPtr), $(char* previewValuePtr)) } |] - - --- | Only call 'endCombo' if 'beginCombo' returns 'True'! --- --- Wraps @ImGui::EndCombo()@. -endCombo :: MonadIO m => m () -endCombo = liftIO do - [C.exp| void { EndCombo() } |] + Raw.beginCombo labelPtr previewValuePtr -- | Wraps @ImGui::Combo()@. @@ -470,13 +292,13 @@ combo label selectedIndex items = liftIO $ Managed.with m return iPtr <- Managed.managed $ with (fromIntegral i) liftIO $ withArrayLen cStrings \len itemsPtr -> do - let len' = fromIntegral len - [C.exp| bool { Combo($(char* labelPtr), $(int* iPtr), $(char** itemsPtr), $(int len')) }|] >>= \case - 0 -> return False - _ -> do - i' <- peek iPtr - selectedIndex $=! fromIntegral i' - return True + changed <- Raw.combo labelPtr iPtr itemsPtr (fromIntegral len) + + when changed do + i' <- peek iPtr + selectedIndex $=! fromIntegral i' + + return changed -- | Wraps @ImGui::DragFloat()@ @@ -485,18 +307,13 @@ dragFloat desc ref speed minValue maxValue = liftIO do currentValue <- get ref with (realToFrac currentValue) \floatPtr -> do changed <- withCString desc \descPtr -> - (0 /=) <$> [C.exp| bool { DragFloat( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] + Raw.dragFloat descPtr floatPtr (CFloat speed) (CFloat minValue) (CFloat maxValue) when changed do newValue <- peek floatPtr ref $=! realToFrac newValue return changed - where - min', max', speed' :: CFloat - min' = realToFrac minValue - max' = realToFrac maxValue - speed' = realToFrac speed -- | Wraps @ImGui::DragFloat2()@ @@ -505,19 +322,13 @@ dragFloat2 desc ref speed minValue maxValue = liftIO do (x, y) <- get ref withArray [ realToFrac x, realToFrac y ] \floatPtr -> do changed <- withCString desc \descPtr -> - (0 /=) <$> [C.exp| bool { DragFloat2( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] + Raw.dragFloat2 descPtr floatPtr (CFloat speed) (CFloat minValue) (CFloat maxValue) when changed do [x', y'] <- peekArray 2 floatPtr ref $=! (realToFrac x', realToFrac y') return changed - where - min', max', speed' :: CFloat - min' = realToFrac minValue - max' = realToFrac maxValue - speed' = realToFrac speed - -- | Wraps @ImGui::DragFloat3()@ dragFloat3 :: (MonadIO m, HasSetter ref (Float, Float, Float), HasGetter ref (Float, Float, Float)) => String -> ref -> Float -> Float -> Float -> m Bool @@ -525,18 +336,13 @@ dragFloat3 desc ref speed minValue maxValue = liftIO do (x, y, z) <- get ref withArray [ realToFrac x, realToFrac y, realToFrac z ] \floatPtr -> do changed <- withCString desc \descPtr -> - (0 /=) <$> [C.exp| bool { DragFloat3( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] + Raw.dragFloat3 descPtr floatPtr (CFloat speed) (CFloat minValue) (CFloat maxValue) when changed do [x', y', z'] <- peekArray 3 floatPtr ref $=! (realToFrac x', realToFrac y', realToFrac z') return changed - where - min', max', speed' :: CFloat - min' = realToFrac minValue - max' = realToFrac maxValue - speed' = realToFrac speed -- | Wraps @ImGui::DragFloat4()@ @@ -545,18 +351,13 @@ dragFloat4 desc ref speed minValue maxValue = liftIO do (x, y, z, u) <- get ref withArray [ realToFrac x, realToFrac y, realToFrac z, realToFrac u ] \floatPtr -> do changed <- withCString desc \descPtr -> - (0 /=) <$> [C.exp| bool { DragFloat4( $(char* descPtr), $(float *floatPtr), $(float speed'), $(float min'), $(float max')) } |] + Raw.dragFloat4 descPtr floatPtr (CFloat speed) (CFloat minValue) (CFloat maxValue) when changed do [x', y', z', u'] <- peekArray 4 floatPtr ref $=! (realToFrac x', realToFrac y', realToFrac z', realToFrac u') return changed - where - min', max', speed' :: CFloat - min' = realToFrac minValue - max' = realToFrac maxValue - speed' = realToFrac speed -- | Wraps @ImGui::SliderFloat()@ @@ -565,17 +366,13 @@ sliderFloat desc ref minValue maxValue = liftIO do currentValue <- get ref with (realToFrac currentValue) \floatPtr -> do changed <- withCString desc \descPtr -> - (0 /=) <$> [C.exp| bool { SliderFloat( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] + Raw.sliderFloat descPtr floatPtr (CFloat minValue) (CFloat maxValue) when changed do newValue <- peek floatPtr ref $=! realToFrac newValue return changed - where - min', max' :: CFloat - min' = realToFrac minValue - max' = realToFrac maxValue -- | Wraps @ImGui::SliderFloat2()@ @@ -584,17 +381,13 @@ sliderFloat2 desc ref minValue maxValue = liftIO do (x, y) <- get ref withArray [ realToFrac x, realToFrac y ] \floatPtr -> do changed <- withCString desc \descPtr -> - (0 /=) <$> [C.exp| bool { SliderFloat2( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] + Raw.sliderFloat descPtr floatPtr (CFloat minValue) (CFloat maxValue) when changed do [x', y'] <- peekArray 2 floatPtr ref $=! (realToFrac x', realToFrac y') return changed - where - min', max' :: CFloat - min' = realToFrac minValue - max' = realToFrac maxValue -- | Wraps @ImGui::SliderFloat3()@ @@ -603,17 +396,13 @@ sliderFloat3 desc ref minValue maxValue = liftIO do (x, y, z) <- get ref withArray [ realToFrac x, realToFrac y, realToFrac z ] \floatPtr -> do changed <- withCString desc \descPtr -> - (0 /=) <$> [C.exp| bool { SliderFloat3( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] + Raw.sliderFloat descPtr floatPtr (CFloat minValue) (CFloat maxValue) when changed do [x', y', z'] <- peekArray 3 floatPtr ref $=! (realToFrac x', realToFrac y', realToFrac z') return changed - where - min', max' :: CFloat - min' = realToFrac minValue - max' = realToFrac maxValue -- | Wraps @ImGui::SliderFloat4()@ @@ -622,32 +411,28 @@ sliderFloat4 desc ref minValue maxValue = liftIO do (x, y, z, u) <- get ref withArray [ realToFrac x, realToFrac y, realToFrac z, realToFrac u ] \floatPtr -> do changed <- withCString desc \descPtr -> - (0 /=) <$> [C.exp| bool { SliderFloat4( $(char* descPtr), $(float *floatPtr), $(float min'), $(float max')) } |] + Raw.sliderFloat descPtr floatPtr (CFloat minValue) (CFloat maxValue) when changed do [x', y', z', u'] <- peekArray 4 floatPtr ref $=! (realToFrac x', realToFrac y', realToFrac z', realToFrac u') return changed - where - min', max' :: CFloat - min' = realToFrac minValue - max' = realToFrac maxValue -- | Wraps @ImGui::InputText()@. -inputText :: (MonadIO m, HasSetter ref String, HasGetter ref String) => String -> ref -> Int -> m Bool +inputText :: (MonadIO m, HasSetter ref String, HasGetter ref String) => String -> ref -> Int -> m Bool inputText desc ref refSize = liftIO do input <- get ref withCString input \ refPtr -> do withCString desc \ descPtr -> do let refSize' :: CInt refSize' = fromIntegral refSize - changed <- - (0 /= ) <$> [C.exp| - bool { InputText( $(char* descPtr), $(char* refPtr), $(int refSize') ) } - |] - (peekCString $ coerce refPtr) >>= ($=!) ref + changed <- Raw.inputText descPtr refPtr refSize' + + when changed do + peekCString refPtr >>= ($=!) ref + return changed @@ -657,7 +442,7 @@ colorPicker3 desc ref = liftIO do ImVec3{x, y, z} <- get ref withArray (realToFrac <$> [x, y, z]) \refPtr -> do changed <- withCString desc \descPtr -> - (0 /= ) <$> [C.exp| bool { ColorPicker3( $(char* descPtr), $(float *refPtr) ) } |] + Raw.colorPicker3 descPtr refPtr when changed do [x', y', z'] <- peekArray 3 refPtr @@ -674,7 +459,7 @@ colorButton desc ref = liftIO do currentValue <- get ref with currentValue \refPtr -> do changed <- withCString desc \descPtr -> - (0 /=) <$> [C.exp| bool { ColorButton( $(char* descPtr), *$(ImVec4 *refPtr) ) } |] + Raw.colorButton descPtr refPtr when changed do newValue <- peek refPtr @@ -682,31 +467,24 @@ colorButton desc ref = liftIO do return changed + -- | Wraps @ImGui::TreeNode()@. treeNode :: MonadIO m => String -> m Bool treeNode label = liftIO do - withCString label \labelPtr -> - (0 /=) <$> [C.exp| bool { TreeNode($(char* labelPtr)) } |] + withCString label Raw.treeNode -- | Wraps @ImGui::TreePush()@. treePush :: MonadIO m => String -> m () treePush label = liftIO do - withCString label \labelPtr -> - [C.exp| void { TreePush($(char* labelPtr)) } |] - - --- | Wraps @ImGui::TreePop()@. -treePop :: MonadIO m => m () -treePop = liftIO do - [C.exp| void { TreePop() } |] + withCString label Raw.treePush -- | Wraps @ImGui::Selectable()@. selectable :: MonadIO m => String -> m Bool selectable label = liftIO do - withCString label \labelPtr -> - (0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |] + withCString label Raw.selectable + listBox :: (MonadIO m, HasGetter ref Int, HasSetter ref Int) => String -> ref -> [String] -> m Bool listBox label selectedIndex items = liftIO $ Managed.with m return @@ -719,55 +497,21 @@ listBox label selectedIndex items = liftIO $ Managed.with m return iPtr <- Managed.managed $ with (fromIntegral i) liftIO $ withArrayLen cStrings \len itemsPtr -> do - let len' = fromIntegral len - [C.exp| bool { ListBox($(char* labelPtr), $(int* iPtr), $(char** itemsPtr), $(int len')) }|] >>= \case - 0 -> return False - _ -> do - i' <- peek iPtr - selectedIndex $=! fromIntegral i' - return True + changed <- Raw.listBox labelPtr iPtr itemsPtr (fromIntegral len) + + when changed do + i' <- peek iPtr + selectedIndex $=! fromIntegral i' + + return changed -- | Wraps @ImGui::PlotHistogram()@. plotHistogram :: MonadIO m => String -> [CFloat] -> m () plotHistogram label values = liftIO $ withArrayLen values \len valuesPtr -> - withCString label \labelPtr -> do - let c'len = fromIntegral len - [C.exp| void { PlotHistogram($(char* labelPtr), $(float* valuesPtr), $(int c'len)) } |] - - --- | Append to menu-bar of current window (requires 'ImGuiWindowFlagsMenuBar' --- flag set on parent window). --- --- Wraps @ImGui::BeginMenuBar()@. -beginMenuBar :: MonadIO m => m Bool -beginMenuBar = liftIO do - (0 /=) <$> [C.exp| bool { BeginMenuBar() } |] - - --- | Only call 'endMenuBar' if 'beginMenuBar' returns true! --- --- Wraps @ImGui::EndMenuBar()@. -endMenuBar :: MonadIO m => m () -endMenuBar = liftIO do - [C.exp| void { EndMenuBar(); } |] - - --- | Create and append to a full screen menu-bar. --- --- Wraps @ImGui::BeginMainMenuBar()@. -beginMainMenuBar :: MonadIO m => m Bool -beginMainMenuBar = liftIO do - (0 /=) <$> [C.exp| bool { BeginMainMenuBar() } |] - - --- | Only call 'endMainMenuBar' if 'beginMainMenuBar' returns true! --- --- Wraps @ImGui::EndMainMenuBar()@. -endMainMenuBar :: MonadIO m => m () -endMainMenuBar = liftIO do - [C.exp| void { EndMainMenuBar(); } |] + withCString label \labelPtr -> + Raw.plotHistogram labelPtr valuesPtr (fromIntegral len) -- | Create a sub-menu entry. @@ -775,16 +519,7 @@ endMainMenuBar = liftIO do -- Wraps @ImGui::BeginMenu()@. beginMenu :: MonadIO m => String -> m Bool beginMenu label = liftIO do - withCString label \labelPtr -> - (0 /=) <$> [C.exp| bool { BeginMenu($(char* labelPtr)) } |] - - --- | Only call 'endMenu' if 'beginMenu' returns true! --- --- Wraps @ImGui::EndMenu()@. -endMenu :: MonadIO m => m () -endMenu = liftIO do - [C.exp| void { EndMenu(); } |] + withCString label Raw.beginMenu -- | Return true when activated. Shortcuts are displayed for convenience but not @@ -793,8 +528,8 @@ endMenu = liftIO do -- Wraps @ImGui::MenuItem()@ menuItem :: MonadIO m => String -> m Bool menuItem label = liftIO do - withCString label \labelPtr -> - (0 /=) <$> [C.exp| bool { MenuItem($(char* labelPtr)) } |] + withCString label Raw.menuItem + -- | Create a @TabBar@ and start appending to it. -- @@ -802,14 +537,8 @@ menuItem label = liftIO do beginTabBar :: MonadIO m => String -> ImGuiTabBarFlags -> m Bool beginTabBar tabBarID flags = liftIO do withCString tabBarID \ptr -> - (0 /=) <$> [C.exp| bool { BeginTabBar($(char* ptr), $(ImGuiTabBarFlags flags) ) } |] + Raw.beginTabBar ptr flags --- | Finish appending elements to a tab bar. Only call if 'beginTabBar' returns @True@. --- --- Wraps @ImGui::EndTabBar@. -endTabBar :: MonadIO m => m () -endTabBar = liftIO do - [C.exp| void { EndTabBar(); } |] -- | Create a new tab. Returns @True@ if the tab is selected. -- @@ -817,27 +546,25 @@ endTabBar = liftIO do beginTabItem :: ( MonadIO m, HasGetter ref Bool, HasSetter ref Bool ) => String -> ref -> ImGuiTabBarFlags -> m Bool beginTabItem tabName ref flags = liftIO do currentValue <- get ref - with ( bool 0 1 currentValue :: CBool ) \ refPtr -> do - open <- withCString tabName \ ptrName -> - (0 /=) <$> [C.exp| bool { BeginTabItem($(char* ptrName), $(bool* refPtr), $(ImGuiTabBarFlags flags) ) } |] + with (bool 0 1 currentValue) \refPtr -> do + open <- withCString tabName \ptrName -> + Raw.beginTabItem ptrName refPtr flags + newValue <- (0 /=) <$> peek refPtr - ref $=! newValue + when (newValue /= currentValue) do + ref $=! newValue + pure open --- | Finish appending elements to a tab. Only call if 'beginTabItem' returns @True@. --- --- Wraps @ImGui::EndTabItem@. -endTabItem :: MonadIO m => m () -endTabItem = liftIO do - [C.exp| void { EndTabItem(); } |] -- | Create a tab that behaves like a button. Returns @True@ when clicked. Cannot be selected in the tab bar. -- -- Wraps @ImGui.TabItemButton@. tabItemButton :: MonadIO m => String -> ImGuiTabItemFlags -> m Bool tabItemButton tabName flags = liftIO do - withCString tabName \ namePtr -> - (0 /=) <$> [C.exp| bool { TabItemButton($(char* namePtr), $(ImGuiTabItemFlags flags) ) } |] + withCString tabName \namePtr -> + Raw.tabItemButton namePtr flags + -- | Notify the tab bar (or the docking system) that a tab/window is about to close. -- Useful to reduce visual flicker on reorderable tab bars. @@ -845,22 +572,7 @@ tabItemButton tabName flags = liftIO do -- __For tab-bar__: call after 'beginTabBar' and before tab submission. Otherwise, call with a window name. setTabItemClosed :: MonadIO m => String -> m () setTabItemClosed tabName = liftIO do - withCString tabName \ namePtr -> - [C.exp| void { SetTabItemClosed($(char* namePtr)); } |] - --- | Begin/append a tooltip window to create full-featured tooltip (with any --- kind of items). --- --- Wraps @ImGui::BeginTooltip()@ -beginTooltip :: MonadIO m => m () -beginTooltip = liftIO do - [C.exp| void { BeginTooltip() } |] - - --- | Wraps @ImGui::EndTooltip()@ -endTooltip :: MonadIO m => m () -endTooltip = liftIO do - [C.exp| void { EndTooltip() } |] + withCString tabName Raw.setTabItemClosed -- | Returns 'True' if the popup is open, and you can start outputting to it. @@ -868,8 +580,7 @@ endTooltip = liftIO do -- Wraps @ImGui::BeginPopup()@ beginPopup :: MonadIO m => String -> m Bool beginPopup popupId = liftIO do - withCString popupId \popupIdPtr -> - (0 /=) <$> [C.exp| bool { BeginPopup($(char* popupIdPtr)) } |] + withCString popupId Raw.beginPopup -- | Returns 'True' if the modal is open, and you can start outputting to it. @@ -877,16 +588,7 @@ beginPopup popupId = liftIO do -- Wraps @ImGui::BeginPopupModal()@ beginPopupModal :: MonadIO m => String -> m Bool beginPopupModal popupId = liftIO do - withCString popupId \popupIdPtr -> - (0 /=) <$> [C.exp| bool { BeginPopupModal($(char* popupIdPtr)) } |] - - --- | Only call 'endPopup' if 'beginPopup' or 'beginPopupModal' returns 'True'! --- --- Wraps @ImGui::BeginPopupModal()@ -endPopup :: MonadIO m => m () -endPopup = liftIO do - [C.exp| void { EndPopup() } |] + withCString popupId Raw.beginPopupModal -- | Call to mark popup as open (don't call every frame!). @@ -894,24 +596,7 @@ endPopup = liftIO do -- Wraps @ImGui::OpenPopup()@ openPopup :: MonadIO m => String -> m () openPopup popupId = liftIO do - withCString popupId \popupIdPtr -> - [C.exp| void { OpenPopup($(char* popupIdPtr)) } |] - - --- | Manually close the popup we have begin-ed into. --- --- Wraps @ImGui::ClosePopup()@ -closeCurrentPopup :: MonadIO m => m () -closeCurrentPopup = liftIO do - [C.exp| void { CloseCurrentPopup() } |] - - --- | Is the last item hovered? (and usable, aka not blocked by a popup, etc.). --- --- Wraps @ImGui::IsItemHovered()@ -isItemHovered :: MonadIO m => m Bool -isItemHovered = liftIO do - (0 /=) <$> [C.exp| bool { IsItemHovered() } |] + withCString popupId Raw.openPopup withCStringOrNull :: Maybe String -> (Ptr CChar -> IO a) -> IO a @@ -930,18 +615,18 @@ setNextWindowPos posRef cond pivotMaybe = liftIO do Just pivotRef -> do pivot <- get pivotRef with pivot $ \pivotPtr -> - [C.exp| void { SetNextWindowPos(*$(ImVec2 *posPtr), $(ImGuiCond cond), *$(ImVec2 *pivotPtr)) } |] + Raw.setNextWindowPos posPtr cond pivotPtr Nothing -> - [C.exp| void { SetNextWindowPos(*$(ImVec2 *posPtr), $(ImGuiCond cond)) } |] + Raw.setNextWindowPos posPtr cond nullPtr --- | Set next window size. Call before `begin` +-- | Set next window size. Call before `begin` -- -- Wraps @ImGui::SetNextWindowSize()@ setNextWindowSize :: (MonadIO m, HasGetter ref ImVec2) => ref -> ImGuiCond -> m () setNextWindowSize sizeRef cond = liftIO do size' <- get sizeRef - with size' $ - \sizePtr ->[C.exp| void { SetNextWindowSize(*$(ImVec2 *sizePtr), $(ImGuiCond cond)) } |] + with size' \sizePtr -> + Raw.setNextWindowSize sizePtr cond -- | Set next window content size (~ scrollable client area, which enforce the range of scrollbars). Not including window decorations (title bar, menu bar, etc.) nor WindowPadding. call before `begin` -- @@ -949,8 +634,8 @@ setNextWindowSize sizeRef cond = liftIO do setNextWindowContentSize :: (MonadIO m, HasGetter ref ImVec2) => ref -> m () setNextWindowContentSize sizeRef = liftIO do size' <- get sizeRef - with size' $ - \sizePtr ->[C.exp| void { SetNextWindowContentSize(*$(ImVec2 *sizePtr)) } |] + with size' Raw.setNextWindowContentSize + -- | Set next window size limits. use -1,-1 on either X/Y axis to preserve the current size. Sizes will be rounded down. -- @@ -959,145 +644,98 @@ setNextWindowSizeConstraints :: (MonadIO m, HasGetter ref ImVec2) => ref -> ref setNextWindowSizeConstraints sizeMinRef sizeMaxRef = liftIO do sizeMin <- get sizeMinRef sizeMax <- get sizeMaxRef - with sizeMin $ - \sizeMinPtr -> - with sizeMax $ \sizeMaxPtr -> - [C.exp| void { SetNextWindowSizeConstraints(*$(ImVec2 *sizeMinPtr), *$(ImVec2 *sizeMaxPtr)) } |] + with sizeMin \sizeMinPtr -> + with sizeMax \sizeMaxPtr -> + Raw.setNextWindowSizeConstraints sizeMinPtr sizeMaxPtr + -- | Set next window collapsed state. call before `begin` -- -- Wraps @ImGui::SetNextWindowCollapsed()@ setNextWindowCollapsed :: (MonadIO m) => Bool -> ImGuiCond -> m () setNextWindowCollapsed b cond = liftIO do - let b' = bool 0 1 b - [C.exp| void { SetNextWindowCollapsed($(bool b'), $(ImGuiCond cond)) } |] + Raw.setNextWindowCollapsed (bool 0 1 b) cond + -- | Set next window background color alpha. helper to easily override the Alpha component of `ImGuiCol_WindowBg`, `ChildBg`, `PopupBg`. you may also use `ImGuiWindowFlags_NoBackground`. -- -- Wraps @ImGui::SetNextWindowBgAlpha()@ setNextWindowBgAlpha :: (MonadIO m) => Float -> m () -setNextWindowBgAlpha f = liftIO do - let f' = coerce f - [C.exp| void { SetNextWindowBgAlpha($(float f')) } |] +setNextWindowBgAlpha alpha = liftIO do + Raw.setNextWindowBgAlpha (CFloat alpha) --- | undo a sameLine or force a new line when in an horizontal-layout context. --- --- Wraps @ImGui::NewLine()@ -newLine :: (MonadIO m) => m () -newLine = liftIO do - [C.exp| void { NewLine() } |] - --- | Add vertical spacing. --- --- Wraps @ImGui::Spacing()@ -spacing :: (MonadIO m) => m () -spacing = liftIO do - [C.exp| void { Spacing() } |] -- | Add a dummy item of given size. unlike `invisibleButton`, `dummy` won't take the mouse click or be navigable into. -- -- Wraps @ImGui::Dummy()@ dummy :: (MonadIO m, HasGetter ref ImVec2) => ref -> m () -dummy sizeRef = liftIO do +dummy sizeRef = liftIO do size' <- get sizeRef - with size' $ \ sizePtr -> [C.exp| void { Dummy(*$(ImVec2 *sizePtr)) } |] + with size' Raw.dummy + -- | Move content position toward the right, by indent_w, or style.IndentSpacing if indent_w <= 0 -- -- Wraps @ImGui::Indent()@ indent :: (MonadIO m) => Float -> m () indent indent_w = liftIO do - let indent_w' = coerce indent_w - [C.exp| void { Indent($(float indent_w')) } |] + Raw.indent (CFloat indent_w) + -- | Move content position back to the left, by indent_w, or style.IndentSpacing if indent_w <= 0 -- -- Wraps @ImGui::Unindent()@ unindent :: (MonadIO m) => Float -> m () unindent f = liftIO do - let f' = coerce f - [C.exp| void { Unindent($(float f')) } |] + Raw.unindent (CFloat f) + -- | Affect large frame+labels widgets only. -- -- Wraps @ImGui::SetNextItemWidth()@ setNextItemWidth :: (MonadIO m) => Float -> m () setNextItemWidth itemWidth = liftIO do - let itemWidth' = coerce itemWidth - [C.exp| void { SetNextItemWidth($(float itemWidth')) } |] + Raw.setNextItemWidth (CFloat itemWidth) + -- Wraps @ImGui::PushItemWidth()@ pushItemWidth :: (MonadIO m) => Float -> m () pushItemWidth itemWidth = liftIO do - let itemWidth' = coerce itemWidth - [C.exp| void { PushItemWidth($(float itemWidth')) } |] + Raw.pushItemWidth (CFloat itemWidth) --- Wraps @ImGui::PopItemWidth()@ -popItemWidth :: (MonadIO m) => m () -popItemWidth = liftIO do - [C.exp| void { PopItemWidth() } |] - --- | lock horizontal starting position --- --- Wraps @ImGui::BeginGroup()@ -beginGroup :: (MonadIO m) => m () -beginGroup = liftIO do - [C.exp| void { BeginGroup() } |] - --- | unlock horizontal starting position + capture the whole group bounding box into one "item" (so you can use `isItemHovered` or layout primitives such as `sameLine` on whole group, etc.) --- --- Wraps @ImGui::EndGroup()@ -endGroup :: (MonadIO m) => m () -endGroup = liftIO do - [C.exp| void { EndGroup() } |] - --- | Vertically align upcoming text baseline to FramePadding.y so that it will align properly to regularly framed items (call if you have text on a line before a framed item) --- --- Wraps @ImGui::AlignTextToFramePadding()@ -alignTextToFramePadding :: (MonadIO m) => m () -alignTextToFramePadding = liftIO do - [C.exp| void { AlignTextToFramePadding() } |] -- | Set cursor position in window-local coordinates --- +-- -- Wraps @ImGui::SetCursorPos()@ setCursorPos :: (MonadIO m, HasGetter ref ImVec2) => ref -> m () -setCursorPos posRef = liftIO do +setCursorPos posRef = liftIO do pos <- get posRef - with pos $ \ posPtr -> [C.exp| void { SetCursorPos(*$(ImVec2 *posPtr)) } |] + with pos Raw.setCursorPos + -- | 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 () -pushStyleColor col colorRef = liftIO do +pushStyleColor col colorRef = liftIO do color <- get colorRef - with color $ \ colorPtr -> [C.exp| void { PushStyleColor($(ImGuiCol col), *$(ImVec4 *colorPtr)) } |] + with color \colorPtr -> + Raw.pushStyleColor col colorPtr --- | Remove style color modifications from the shared stack --- --- Wraps @ImGui::PopStyleColor()@ -popStyleColor :: (MonadIO m) => Int32 -> m () -popStyleColor n = liftIO do - let - m :: CInt - m = coerce n - [C.exp| void { PopStyleColor($(int m)) } |] -- | 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 () -pushStyleVar style valRef = liftIO do +pushStyleVar style valRef = liftIO do val <- get valRef - with val $ \ valPtr -> [C.exp| void { PushStyleVar($(ImGuiStyleVar style), *$(ImVec2 *valPtr)) } |] + with val \valPtr -> + Raw.pushStyleVar style valPtr + -- | Remove style variable modifications from the shared stack --- +-- -- Wraps @ImGui::PopStyleVar()@ -popStyleVar :: (MonadIO m) => Int32 -> m () +popStyleVar :: (MonadIO m) => Int -> m () popStyleVar n = liftIO do - let - m :: CInt - m = coerce n - [C.exp| void { PopStyleVar($(int m)) } |] + Raw.popStyleVar (fromIntegral n) diff --git a/src/DearImGui/Raw.hs b/src/DearImGui/Raw.hs new file mode 100644 index 0000000..9badd48 --- /dev/null +++ b/src/DearImGui/Raw.hs @@ -0,0 +1,875 @@ +{-# LANGUAGE BlockArguments #-} +{-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE TemplateHaskell #-} + +{-| +Module: DearImGui + +Main ImGui module, exporting the functions to create a GUI. +-} + +module DearImGui.Raw + ( -- * Context Creation and Access + Context(..) + , createContext + , destroyContext + + -- * Main + , newFrame + , endFrame + , render + , DrawData(..) + , getDrawData + , checkVersion + + -- * Demo, Debug, Information + , showDemoWindow + , showMetricsWindow + , showAboutWindow + , showUserGuide + , getVersion + + -- * Styles + , styleColorsDark + , styleColorsLight + , styleColorsClassic + + -- * Windows + , begin + , end + , setNextWindowPos + , setNextWindowSize + , setNextWindowContentSize + , setNextWindowSizeConstraints + , setNextWindowCollapsed + , setNextWindowBgAlpha + + -- * Child Windows + , beginChild + , endChild + + -- * Parameter stacks + , pushStyleColor + , popStyleColor + , pushStyleVar + , popStyleVar + + -- * Cursor/Layout + , separator + , sameLine + , newLine + , spacing + , dummy + , indent + , unindent + , setNextItemWidth + , pushItemWidth + , popItemWidth + , beginGroup + , endGroup + , setCursorPos + , alignTextToFramePadding + + -- * Widgets + -- ** Text + , text + + -- ** Main + , button + , smallButton + , arrowButton + , checkbox + , progressBar + , bullet + + -- ** Combo Box + , beginCombo + , endCombo + , combo + + -- ** Drag Sliders + , dragFloat + , dragFloat2 + , dragFloat3 + , dragFloat4 + + -- ** Slider + , sliderFloat + , sliderFloat2 + , sliderFloat3 + , sliderFloat4 + + -- ** Text Input + , inputText + + -- * Color Editor/Picker + , colorPicker3 + , colorButton + + -- * Trees + , treeNode + , treePush + , treePop + + -- ** Selectables + , selectable + + -- ** List Boxes + , listBox + + -- * Data Plotting + , plotHistogram + + -- ** Menus + , beginMenuBar + , endMenuBar + , beginMainMenuBar + , endMainMenuBar + , beginMenu + , endMenu + , menuItem + + -- ** Tabs, tab bar + , beginTabBar + , endTabBar + , beginTabItem + , endTabItem + , tabItemButton + , setTabItemClosed + + -- * Tooltips + , beginTooltip + , endTooltip + + -- * Popups/Modals + , beginPopup + , beginPopupModal + , endPopup + , openPopup + , closeCurrentPopup + + -- * Item/Widgets Utilities + , isItemHovered + + -- * Types + , module DearImGui.Enums + , module DearImGui.Structs + ) + where + +-- base +import Control.Monad.IO.Class + ( MonadIO, liftIO ) +import Foreign +import Foreign.C + +-- dear-imgui +import DearImGui.Context + ( imguiContext ) +import DearImGui.Enums +import DearImGui.Structs + +-- inline-c +import qualified Language.C.Inline as C + +-- inline-c-cpp +import qualified Language.C.Inline.Cpp as Cpp + +C.context (Cpp.cppCtx <> C.bsCtx <> imguiContext) +C.include "imgui.h" +Cpp.using "namespace ImGui" + + +-- | Wraps @ImGuiContext*@. +newtype Context = Context (Ptr ()) + + +-- | Wraps @ImGui::CreateContext()@. +createContext :: (MonadIO m) => m Context +createContext = liftIO do + Context <$> [C.exp| void* { CreateContext() } |] + + +-- | Wraps @ImGui::DestroyContext()@. +destroyContext :: (MonadIO m) => Context -> m () +destroyContext (Context contextPtr) = liftIO do + [C.exp| void { DestroyContext((ImGuiContext*)$(void* contextPtr)); } |] + + +-- | Start a new Dear ImGui frame, you can submit any command from this point +-- until 'render'/'endFrame'. +-- +-- Wraps @ImGui::NewFrame()@. +newFrame :: (MonadIO m) => m () +newFrame = liftIO do + [C.exp| void { NewFrame(); } |] + + +-- | Ends the Dear ImGui frame. automatically called by 'render'. If you don't +-- need to render data (skipping rendering) you may call 'endFrame' without +-- 'render'... but you'll have wasted CPU already! If you don't need to render, +-- better to not create any windows and not call 'newFrame' at all! +endFrame :: (MonadIO m) => m () +endFrame = liftIO do + [C.exp| void { EndFrame(); } |] + + +-- | Ends the Dear ImGui frame, finalize the draw data. You can then get call +-- 'getDrawData'. +render :: (MonadIO m) => m () +render = liftIO do + [C.exp| void { Render(); } |] + + +-- | Wraps @ImDrawData*@. +newtype DrawData = DrawData (Ptr ()) + + +-- | Valid after 'render' and until the next call to 'newFrame'. This is what +-- you have to render. +getDrawData :: (MonadIO m) => m DrawData +getDrawData = liftIO do + DrawData <$> [C.exp| void* { GetDrawData() } |] + + +-- | Wraps @IMGUI_CHECKVERSION()@ +checkVersion :: (MonadIO m) => m () +checkVersion = liftIO do + [C.exp| void { IMGUI_CHECKVERSION(); } |] + + +-- | Create demo window. Demonstrate most ImGui features. Call this to learn +-- about the library! Try to make it always available in your application! +showDemoWindow :: (MonadIO m) => m () +showDemoWindow = liftIO do + [C.exp| void { ShowDemoWindow(); } |] + + +-- | Create Metrics/Debugger window. Display Dear ImGui internals: windows, draw +-- commands, various internal state, etc. +showMetricsWindow :: (MonadIO m) => m () +showMetricsWindow = liftIO do + [C.exp| void { ShowMetricsWindow(); } |] + + +-- | Create About window. display Dear ImGui version, credits and build/system +-- information. +showAboutWindow :: (MonadIO m) => m () +showAboutWindow = liftIO do + [C.exp| void { ShowAboutWindow(); } |] + + +-- | Add basic help/info block (not a window): how to manipulate ImGui as a +-- end-user (mouse/keyboard controls). +showUserGuide :: (MonadIO m) => m () +showUserGuide = liftIO do + [C.exp| void { ShowUserGuide() } |] + + +-- | Get the compiled version string e.g. "1.80 WIP" (essentially the value for +-- @IMGUI_VERSION@ from the compiled version of @imgui.cpp@). +getVersion :: (MonadIO m) => m CString +getVersion = liftIO do + [C.exp| const char* { GetVersion() } |] + + +-- | New, recommended style (default). +-- +-- Wraps @ImGui::StyleColorsDark()@. +styleColorsDark :: (MonadIO m) => m () +styleColorsDark = liftIO do + [C.exp| void { StyleColorsDark(); } |] + + +-- | Best used with borders and a custom, thicker font. +-- +-- Wraps @ImGui::StyleColorsLight()@. +styleColorsLight :: (MonadIO m) => m () +styleColorsLight = liftIO do + [C.exp| void { StyleColorsLight(); } |] + + +-- | Classic ImGui style. +-- +-- Wraps @ImGui::StyleColorsClasic()@. +styleColorsClassic :: (MonadIO m) => m () +styleColorsClassic = liftIO do + [C.exp| void { StyleColorsClassic(); } |] + + +-- | Push window to the stack and start appending to it. +-- +-- Returns 'False' to indicate the window is collapsed or fully clipped, so you +-- may early out and omit submitting anything to the window. Always call a +-- matching 'end' for each 'begin' call, regardless of its return value! +-- +-- Wraps @ImGui::Begin()@. +begin :: (MonadIO m) => CString -> m Bool +begin namePtr = liftIO do + (0 /=) <$> [C.exp| bool { Begin($(char* namePtr)) } |] + + +-- | Pop window from the stack. +-- +-- Wraps @ImGui::End()@. +end :: (MonadIO m) => m () +end = liftIO do + [C.exp| void { End(); } |] + + +-- | Wraps @ImGui::BeginChild()@. +beginChild :: (MonadIO m) => CString -> m Bool +beginChild namePtr = liftIO do + (0 /=) <$> [C.exp| bool { BeginChild($(char* namePtr)) } |] + + +-- | Wraps @ImGui::EndChild()@. +endChild :: (MonadIO m) => m () +endChild = liftIO do + [C.exp| void { EndChild(); } |] + + +-- | Separator, generally horizontal. inside a menu bar or in horizontal layout +-- mode, this becomes a vertical separator. +-- +-- Wraps @ImGui::Separator()@ +separator :: (MonadIO m) => m () +separator = liftIO do + [C.exp| void { Separator(); } |] + + +-- | Call between widgets or groups to layout them horizontally. +-- +-- Wraps @ImGui::SameLine@. +sameLine :: (MonadIO m) => m () +sameLine = liftIO do + [C.exp| void { SameLine(); } |] + + +-- | Formatted text. +-- +-- Wraps @ImGui::Text()@. +text :: (MonadIO m) => CString -> m () +text textPtr = liftIO do + [C.exp| void { Text("%s", $(char* textPtr)) } |] + + +-- | A button. Returns 'True' when clicked. +-- +-- Wraps @ImGui::Button()@. +button :: (MonadIO m) => CString -> m Bool +button labelPtr = liftIO do + (0 /=) <$> [C.exp| bool { Button($(char* labelPtr)) } |] + + +-- | Button with @FramePadding=(0,0)@ to easily embed within text. +-- +-- Wraps @ImGui::SmallButton()@. +smallButton :: (MonadIO m) => CString -> m Bool +smallButton labelPtr = liftIO do + (0 /=) <$> [C.exp| bool { SmallButton($(char* labelPtr)) } |] + + +-- | Square button with an arrow shape. +-- +-- Wraps @ImGui::ArrowButton()@. +arrowButton :: (MonadIO m) => CString -> ImGuiDir -> m Bool +arrowButton strIdPtr dir = liftIO do + (0 /=) <$> [C.exp| bool { ArrowButton($(char* strIdPtr), $(ImGuiDir dir)) } |] + + +-- | Wraps @ImGui::Checkbox()@. +checkbox :: (MonadIO m) => CString -> Ptr CBool -> m Bool +checkbox labelPtr boolPtr = liftIO do + (0 /=) <$> [C.exp| bool { Checkbox($(char* labelPtr), $(bool* boolPtr)) } |] + + +-- TODO: publish ImVec2(-FLT_MIN, 0) +-- | Wraps @ImGui::ProgressBar()@. +progressBar :: (MonadIO m) => CFloat -> CString -> m () +progressBar progress overlayPtr = liftIO do + [C.exp| void { ProgressBar($(float progress), ImVec2(-FLT_MIN, 0), $(char* overlayPtr)) } |] + + +-- | Draw a small circle + keep the cursor on the same line. Advance cursor x +-- position by 'getTreeNodeToLabelSpacing', same distance that 'treeNode' uses. +bullet :: (MonadIO m) => m () +bullet = liftIO do + [C.exp| void { Bullet() } |] + + +-- | Begin creating a combo box with a given label and preview value. +-- +-- Returns 'True' if the combo box is open. In this state, you should populate +-- the contents of the combo box - for example, by calling 'selectable'. +-- +-- Wraps @ImGui::BeginCombo()@. +beginCombo :: (MonadIO m) => CString -> CString -> m Bool +beginCombo labelPtr previewValuePtr = liftIO do + (0 /=) <$> [C.exp| bool { BeginCombo($(char* labelPtr), $(char* previewValuePtr)) } |] + + +-- | Only call 'endCombo' if 'beginCombo' returns 'True'! +-- +-- Wraps @ImGui::EndCombo()@. +endCombo :: (MonadIO m) => m () +endCombo = liftIO do + [C.exp| void { EndCombo() } |] + + +-- | Wraps @ImGui::Combo()@. +combo :: (MonadIO m) => CString -> Ptr CInt -> Ptr CString -> CInt -> m Bool +combo labelPtr iPtr itemsPtr itemsLen = liftIO do + (0 /=) <$> [C.exp| bool { Combo($(char* labelPtr), $(int* iPtr), $(char** itemsPtr), $(int itemsLen)) }|] + + +-- | Wraps @ImGui::DragFloat()@ +dragFloat :: (MonadIO m) => CString -> Ptr CFloat -> CFloat -> CFloat -> CFloat -> m Bool +dragFloat descPtr floatPtr speed minValue maxValue = liftIO do + (0 /=) <$> [C.exp| bool { DragFloat( $(char* descPtr), $(float* floatPtr), $(float speed), $(float minValue), $(float maxValue)) } |] + + +-- | Wraps @ImGui::DragFloat2()@ +dragFloat2 :: (MonadIO m) => CString -> Ptr CFloat -> CFloat -> CFloat -> CFloat -> m Bool +dragFloat2 descPtr floatPtr speed minValue maxValue = liftIO do + (0 /=) <$> [C.exp| bool { DragFloat2( $(char* descPtr), $(float* floatPtr), $(float speed), $(float minValue), $(float maxValue)) } |] + + +-- | Wraps @ImGui::DragFloat3()@ +dragFloat3 :: (MonadIO m) => CString -> Ptr CFloat -> CFloat -> CFloat -> CFloat -> m Bool +dragFloat3 descPtr floatPtr speed minValue maxValue = liftIO do + (0 /=) <$> [C.exp| bool { DragFloat3( $(char* descPtr), $(float* floatPtr), $(float speed), $(float minValue), $(float maxValue)) } |] + + +-- | Wraps @ImGui::DragFloat4()@ +dragFloat4 :: (MonadIO m) => CString -> Ptr CFloat -> CFloat -> CFloat -> CFloat -> m Bool +dragFloat4 descPtr floatPtr speed minValue maxValue = liftIO do + (0 /=) <$> [C.exp| bool { DragFloat4( $(char* descPtr), $(float* floatPtr), $(float speed), $(float minValue), $(float maxValue)) } |] + + +-- | Wraps @ImGui::SliderFloat()@ +sliderFloat :: (MonadIO m) => CString -> Ptr CFloat -> CFloat -> CFloat -> m Bool +sliderFloat descPtr floatPtr minValue maxValue = liftIO do + (0 /=) <$> [C.exp| bool { SliderFloat( $(char* descPtr), $(float* floatPtr), $(float minValue), $(float maxValue)) } |] + + +-- | Wraps @ImGui::SliderFloat2()@ +sliderFloat2 :: (MonadIO m) => CString -> Ptr CFloat -> CFloat -> CFloat -> m Bool +sliderFloat2 descPtr floatPtr minValue maxValue = liftIO do + (0 /=) <$> [C.exp| bool { SliderFloat2( $(char* descPtr), $(float* floatPtr), $(float minValue), $(float maxValue)) } |] + + +-- | Wraps @ImGui::SliderFloat3()@ +sliderFloat3 :: (MonadIO m) => CString -> Ptr CFloat -> CFloat -> CFloat -> m Bool +sliderFloat3 descPtr floatPtr minValue maxValue = liftIO do + (0 /=) <$> [C.exp| bool { SliderFloat3( $(char* descPtr), $(float* floatPtr), $(float minValue), $(float maxValue)) } |] + + +-- | Wraps @ImGui::SliderFloat4()@ +sliderFloat4 :: (MonadIO m) => CString -> Ptr CFloat -> CFloat -> CFloat -> m Bool +sliderFloat4 descPtr floatPtr minValue maxValue = liftIO do + (0 /=) <$> [C.exp| bool { SliderFloat4( $(char* descPtr), $(float* floatPtr), $(float minValue), $(float maxValue)) } |] + + +-- | Wraps @ImGui::InputText()@. +inputText :: (MonadIO m) => CString -> CString -> CInt -> m Bool +inputText descPtr refPtr refSize = liftIO do + (0 /= ) <$> [C.exp| bool { InputText( $(char* descPtr), $(char* refPtr), $(int refSize) ) } |] + + +-- | Wraps @ImGui::ColorPicker3()@. +colorPicker3 :: (MonadIO m) => CString -> Ptr CFloat -> m Bool +colorPicker3 descPtr refPtr = liftIO do + (0 /= ) <$> [C.exp| bool { ColorPicker3( $(char* descPtr), $(float* refPtr) ) } |] + + +-- | Display a color square/button, hover for details, return true when pressed. +-- +-- Wraps @ImGui::ColorButton()@. +colorButton :: (MonadIO m) => CString -> Ptr ImVec4 -> m Bool +colorButton descPtr refPtr = liftIO do + (0 /=) <$> [C.exp| bool { ColorButton( $(char* descPtr), *$(ImVec4* refPtr) ) } |] + + +-- | Wraps @ImGui::TreeNode()@. +treeNode :: (MonadIO m) => CString -> m Bool +treeNode labelPtr = liftIO do + (0 /=) <$> [C.exp| bool { TreeNode($(char* labelPtr)) } |] + + +-- | Wraps @ImGui::TreePush()@. +treePush :: (MonadIO m) => CString -> m () +treePush labelPtr = liftIO do + [C.exp| void { TreePush($(char* labelPtr)) } |] + + +-- | Wraps @ImGui::TreePop()@. +treePop :: (MonadIO m) => m () +treePop = liftIO do + [C.exp| void { TreePop() } |] + + +-- | Wraps @ImGui::Selectable()@. +selectable :: (MonadIO m) => CString -> m Bool +selectable labelPtr = liftIO do + (0 /=) <$> [C.exp| bool { Selectable($(char* labelPtr)) } |] + + +-- | Wraps @ImGui::ListBox()@. +listBox :: (MonadIO m) => CString -> Ptr CInt -> Ptr CString -> CInt -> m Bool +listBox labelPtr iPtr itemsPtr itemsLen = liftIO do + (0 /=) <$> [C.exp| bool { ListBox($(char* labelPtr), $(int* iPtr), $(char** itemsPtr), $(int itemsLen)) }|] + + +-- | Wraps @ImGui::PlotHistogram()@. +plotHistogram :: (MonadIO m) => CString -> Ptr CFloat -> CInt -> m () +plotHistogram labelPtr valuesPtr valuesLen = liftIO do + [C.exp| void { PlotHistogram($(char* labelPtr), $(float* valuesPtr), $(int valuesLen)) } |] + + +-- | Append to menu-bar of current window (requires 'ImGuiWindowFlagsMenuBar' +-- flag set on parent window). +-- +-- Wraps @ImGui::BeginMenuBar()@. +beginMenuBar :: (MonadIO m) => m Bool +beginMenuBar = liftIO do + (0 /=) <$> [C.exp| bool { BeginMenuBar() } |] + + +-- | Only call 'endMenuBar' if 'beginMenuBar' returns true! +-- +-- Wraps @ImGui::EndMenuBar()@. +endMenuBar :: (MonadIO m) => m () +endMenuBar = liftIO do + [C.exp| void { EndMenuBar(); } |] + + +-- | Create and append to a full screen menu-bar. +-- +-- Wraps @ImGui::BeginMainMenuBar()@. +beginMainMenuBar :: (MonadIO m) => m Bool +beginMainMenuBar = liftIO do + (0 /=) <$> [C.exp| bool { BeginMainMenuBar() } |] + + +-- | Only call 'endMainMenuBar' if 'beginMainMenuBar' returns true! +-- +-- Wraps @ImGui::EndMainMenuBar()@. +endMainMenuBar :: (MonadIO m) => m () +endMainMenuBar = liftIO do + [C.exp| void { EndMainMenuBar(); } |] + + +-- | Create a sub-menu entry. +-- +-- Wraps @ImGui::BeginMenu()@. +beginMenu :: (MonadIO m) => CString -> m Bool +beginMenu labelPtr = liftIO do + (0 /=) <$> [C.exp| bool { BeginMenu($(char* labelPtr)) } |] + + +-- | Only call 'endMenu' if 'beginMenu' returns true! +-- +-- Wraps @ImGui::EndMenu()@. +endMenu :: (MonadIO m) => m () +endMenu = liftIO do + [C.exp| void { EndMenu(); } |] + + +-- | Return true when activated. Shortcuts are displayed for convenience but not +-- processed by ImGui at the moment +-- +-- Wraps @ImGui::MenuItem()@ +menuItem :: (MonadIO m) => CString -> m Bool +menuItem labelPtr = liftIO do + (0 /=) <$> [C.exp| bool { MenuItem($(char* labelPtr)) } |] + + +-- | Create a @TabBar@ and start appending to it. +-- +-- Wraps @ImGui::BeginTabBar@. +beginTabBar :: (MonadIO m) => CString -> ImGuiTabBarFlags -> m Bool +beginTabBar tabBarID flags = liftIO do + (0 /=) <$> [C.exp| bool { BeginTabBar($(char* tabBarID), $(ImGuiTabBarFlags flags) ) } |] + + +-- | Finish appending elements to a tab bar. Only call if 'beginTabBar' returns @True@. +-- +-- Wraps @ImGui::EndTabBar@. +endTabBar :: (MonadIO m) => m () +endTabBar = liftIO do + [C.exp| void { EndTabBar(); } |] + + +-- | Create a new tab. Returns @True@ if the tab is selected. +-- +-- Wraps @ImGui::BeginTabItem@. +beginTabItem :: (MonadIO m) => CString -> Ptr CBool -> ImGuiTabBarFlags -> m Bool +beginTabItem namePtr refPtr flags = liftIO do + (0 /=) <$> [C.exp| bool { BeginTabItem($(char* namePtr), $(bool* refPtr), $(ImGuiTabBarFlags flags) ) } |] + + +-- | Finish appending elements to a tab. Only call if 'beginTabItem' returns @True@. +-- +-- Wraps @ImGui::EndTabItem@. +endTabItem :: (MonadIO m) => m () +endTabItem = liftIO do + [C.exp| void { EndTabItem(); } |] + + +-- | Create a tab that behaves like a button. Returns @True@ when clicked. Cannot be selected in the tab bar. +-- +-- Wraps @ImGui.TabItemButton@. +tabItemButton :: (MonadIO m) => CString -> ImGuiTabItemFlags -> m Bool +tabItemButton namePtr flags = liftIO do + (0 /=) <$> [C.exp| bool { TabItemButton($(char* namePtr), $(ImGuiTabItemFlags flags) ) } |] + + +-- | Notify the tab bar (or the docking system) that a tab/window is about to close. +-- Useful to reduce visual flicker on reorderable tab bars. +-- +-- __For tab-bar__: call after 'beginTabBar' and before tab submission. Otherwise, call with a window name. +setTabItemClosed :: (MonadIO m) => CString -> m () +setTabItemClosed namePtr = liftIO do + [C.exp| void { SetTabItemClosed($(char* namePtr)); } |] + + +-- | Begin/append a tooltip window to create full-featured tooltip (with any +-- kind of items). +-- +-- Wraps @ImGui::BeginTooltip()@ +beginTooltip :: (MonadIO m) => m () +beginTooltip = liftIO do + [C.exp| void { BeginTooltip() } |] + + +-- | Wraps @ImGui::EndTooltip()@ +endTooltip :: (MonadIO m) => m () +endTooltip = liftIO do + [C.exp| void { EndTooltip() } |] + + +-- | Returns 'True' if the popup is open, and you can start outputting to it. +-- +-- Wraps @ImGui::BeginPopup()@ +beginPopup :: (MonadIO m) => CString -> m Bool +beginPopup popupIdPtr = liftIO do + (0 /=) <$> [C.exp| bool { BeginPopup($(char* popupIdPtr)) } |] + + +-- | Returns 'True' if the modal is open, and you can start outputting to it. +-- +-- Wraps @ImGui::BeginPopupModal()@ +beginPopupModal :: (MonadIO m) => CString -> m Bool +beginPopupModal popupIdPtr = liftIO do + (0 /=) <$> [C.exp| bool { BeginPopupModal($(char* popupIdPtr)) } |] + + +-- | Only call 'endPopup' if 'beginPopup' or 'beginPopupModal' returns 'True'! +-- +-- Wraps @ImGui::BeginPopupModal()@ +endPopup :: (MonadIO m) => m () +endPopup = liftIO do + [C.exp| void { EndPopup() } |] + + +-- | Call to mark popup as open (don't call every frame!). +-- +-- Wraps @ImGui::OpenPopup()@ +openPopup :: (MonadIO m) => CString -> m () +openPopup popupIdPtr = liftIO do + [C.exp| void { OpenPopup($(char* popupIdPtr)) } |] + + +-- | Manually close the popup we have begin-ed into. +-- +-- Wraps @ImGui::ClosePopup()@ +closeCurrentPopup :: (MonadIO m) => m () +closeCurrentPopup = liftIO do + [C.exp| void { CloseCurrentPopup() } |] + + +-- | Is the last item hovered? (and usable, aka not blocked by a popup, etc.). +-- +-- Wraps @ImGui::IsItemHovered()@ +isItemHovered :: (MonadIO m) => m Bool +isItemHovered = liftIO do + (0 /=) <$> [C.exp| bool { IsItemHovered() } |] + + +-- | Set next window position. Call before `begin` Use pivot=(0.5,0.5) to center on given point, etc. +-- +-- Wraps @ImGui::SetNextWindowPos()@ +setNextWindowPos :: (MonadIO m) => Ptr ImVec2 -> ImGuiCond -> Ptr ImVec2 -> m () +setNextWindowPos posPtr cond pivotPtr = liftIO do + [C.exp| void { SetNextWindowPos(*$(ImVec2* posPtr), $(ImGuiCond cond), *$(ImVec2* pivotPtr)) } |] + + +-- | Set next window size. Call before `begin` +-- +-- Wraps @ImGui::SetNextWindowSize()@ +setNextWindowSize :: (MonadIO m) => Ptr ImVec2 -> ImGuiCond -> m () +setNextWindowSize sizePtr cond = liftIO do + [C.exp| void { SetNextWindowSize(*$(ImVec2* sizePtr), $(ImGuiCond cond)) } |] + + +-- | Set next window content size (~ scrollable client area, which enforce the range of scrollbars). Not including window decorations (title bar, menu bar, etc.) nor WindowPadding. call before `begin` +-- +-- Wraps @ImGui::SetNextWindowContentSize()@ +setNextWindowContentSize :: (MonadIO m) => Ptr ImVec2 -> m () +setNextWindowContentSize sizePtr = liftIO do + [C.exp| void { SetNextWindowContentSize(*$(ImVec2* sizePtr)) } |] + + +-- | Set next window size limits. use -1,-1 on either X/Y axis to preserve the current size. Sizes will be rounded down. +-- +-- Wraps @ImGui::SetNextWindowContentSize()@ +setNextWindowSizeConstraints :: (MonadIO m) => Ptr ImVec2 -> Ptr ImVec2 -> m () +setNextWindowSizeConstraints sizeMinPtr sizeMaxPtr = liftIO do + [C.exp| void { SetNextWindowSizeConstraints(*$(ImVec2* sizeMinPtr), *$(ImVec2* sizeMaxPtr)) } |] + + +-- | Set next window collapsed state. call before `begin` +-- +-- Wraps @ImGui::SetNextWindowCollapsed()@ +setNextWindowCollapsed :: (MonadIO m) => CBool -> ImGuiCond -> m () +setNextWindowCollapsed b cond = liftIO do + [C.exp| void { SetNextWindowCollapsed($(bool b), $(ImGuiCond cond)) } |] + + +-- | Set next window background color alpha. helper to easily override the Alpha component of `ImGuiCol_WindowBg`, `ChildBg`, `PopupBg`. you may also use `ImGuiWindowFlags_NoBackground`. +-- +-- Wraps @ImGui::SetNextWindowBgAlpha()@ +setNextWindowBgAlpha :: (MonadIO m) => CFloat -> m () +setNextWindowBgAlpha alpha = liftIO do + [C.exp| void { SetNextWindowBgAlpha($(float alpha)) } |] + + +-- | undo a sameLine or force a new line when in an horizontal-layout context. +-- +-- Wraps @ImGui::NewLine()@ +newLine :: (MonadIO m) => m () +newLine = liftIO do + [C.exp| void { NewLine() } |] + + +-- | Add vertical spacing. +-- +-- Wraps @ImGui::Spacing()@ +spacing :: (MonadIO m) => m () +spacing = liftIO do + [C.exp| void { Spacing() } |] + + +-- | Add a dummy item of given size. unlike `invisibleButton`, `dummy` won't take the mouse click or be navigable into. +-- +-- Wraps @ImGui::Dummy()@ +dummy :: (MonadIO m) => Ptr ImVec2 -> m () +dummy sizePtr = liftIO do + [C.exp| void { Dummy(*$(ImVec2* sizePtr)) } |] + + +-- | Move content position toward the right, by indent_w, or style.IndentSpacing if indent_w <= 0 +-- +-- Wraps @ImGui::Indent()@ +indent :: (MonadIO m) => CFloat -> m () +indent indent_w = liftIO do + [C.exp| void { Indent($(float indent_w)) } |] + + +-- | Move content position back to the left, by indent_w, or style.IndentSpacing if indent_w <= 0 +-- +-- Wraps @ImGui::Unindent()@ +unindent :: (MonadIO m) => CFloat -> m () +unindent indent_w = liftIO do + [C.exp| void { Unindent($(float indent_w)) } |] + + +-- | Affect large frame+labels widgets only. +-- +-- Wraps @ImGui::SetNextItemWidth()@ +setNextItemWidth :: (MonadIO m) => CFloat -> m () +setNextItemWidth itemWidth = liftIO do + [C.exp| void { SetNextItemWidth($(float itemWidth)) } |] + + +-- Wraps @ImGui::PushItemWidth()@ +pushItemWidth :: (MonadIO m) => CFloat -> m () +pushItemWidth itemWidth = liftIO do + [C.exp| void { PushItemWidth($(float itemWidth)) } |] + + +-- Wraps @ImGui::PopItemWidth()@ +popItemWidth :: (MonadIO m) => m () +popItemWidth = liftIO do + [C.exp| void { PopItemWidth() } |] + + +-- | lock horizontal starting position +-- +-- Wraps @ImGui::BeginGroup()@ +beginGroup :: (MonadIO m) => m () +beginGroup = liftIO do + [C.exp| void { BeginGroup() } |] + + +-- | unlock horizontal starting position + capture the whole group bounding box into one "item" (so you can use `isItemHovered` or layout primitives such as `sameLine` on whole group, etc.) +-- +-- Wraps @ImGui::EndGroup()@ +endGroup :: (MonadIO m) => m () +endGroup = liftIO do + [C.exp| void { EndGroup() } |] + + +-- | Vertically align upcoming text baseline to FramePadding.y so that it will align properly to regularly framed items (call if you have text on a line before a framed item) +-- +-- Wraps @ImGui::AlignTextToFramePadding()@ +alignTextToFramePadding :: (MonadIO m) => m () +alignTextToFramePadding = liftIO do + [C.exp| void { AlignTextToFramePadding() } |] + + +-- | Set cursor position in window-local coordinates +-- +-- Wraps @ImGui::SetCursorPos()@ +setCursorPos :: (MonadIO m) => Ptr ImVec2 -> m () +setCursorPos posPtr = liftIO do + [C.exp| void { SetCursorPos(*$(ImVec2* posPtr)) } |] + + +-- | 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) => ImGuiCol -> Ptr ImVec4 -> m () +pushStyleColor col colorPtr = liftIO do + [C.exp| void { PushStyleColor($(ImGuiCol col), *$(ImVec4 *colorPtr)) } |] + + +-- | Remove style color modifications from the shared stack +-- +-- Wraps @ImGui::PopStyleColor()@ +popStyleColor :: (MonadIO m) => CInt -> m () +popStyleColor n = liftIO do + [C.exp| void { PopStyleColor($(int n)) } |] + + +-- | 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) => ImGuiStyleVar -> Ptr ImVec2 -> m () +pushStyleVar style valPtr = liftIO do + [C.exp| void { PushStyleVar($(ImGuiStyleVar style), *$(ImVec2* valPtr)) } |] + + +-- | Remove style variable modifications from the shared stack +-- +-- Wraps @ImGui::PopStyleVar()@ +popStyleVar :: (MonadIO m) => CInt -> m () +popStyleVar n = liftIO do + [C.exp| void { PopStyleVar($(int n)) } |]