Wrap GetCurrentContext and SetCurrentContext (#94)

This commit is contained in:
Alexander Bondarenko 2021-09-12 13:23:23 +03:00 committed by GitHub
parent 24519778e6
commit c219f8eb4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 3 deletions

View File

@ -20,6 +20,8 @@ module DearImGui
Raw.Context(..)
, Raw.createContext
, Raw.destroyContext
, Raw.getCurrentContext
, Raw.setCurrentContext
-- * Main
, Raw.newFrame

View File

@ -33,5 +33,6 @@ imguiContext = mempty
[ ( TypeName "ImVec2", [t| ImVec2 |] )
, ( TypeName "ImVec3", [t| ImVec3 |] )
, ( TypeName "ImVec4", [t| ImVec4 |] )
, ( TypeName "ImGuiContext", [t| ImGuiContext |] )
]
}

View File

@ -20,6 +20,8 @@ module DearImGui.Raw
Context(..)
, createContext
, destroyContext
, getCurrentContext
, setCurrentContext
-- * Main
, newFrame
@ -234,19 +236,30 @@ Cpp.using "namespace ImGui"
-- | Wraps @ImGuiContext*@.
newtype Context = Context (Ptr ())
newtype Context = Context (Ptr ImGuiContext)
-- | Wraps @ImGui::CreateContext()@.
createContext :: (MonadIO m) => m Context
createContext = liftIO do
Context <$> [C.exp| void* { CreateContext() } |]
Context <$> [C.exp| ImGuiContext* { CreateContext() } |]
-- | Wraps @ImGui::DestroyContext()@.
destroyContext :: (MonadIO m) => Context -> m ()
destroyContext (Context contextPtr) = liftIO do
[C.exp| void { DestroyContext((ImGuiContext*)$(void* contextPtr)); } |]
[C.exp| void { DestroyContext($(ImGuiContext* contextPtr)); } |]
-- | Wraps @ImGui::GetCurrentContext()@.
getCurrentContext :: MonadIO m => m Context
getCurrentContext = liftIO do
Context <$> [C.exp| ImGuiContext* { GetCurrentContext() } |]
-- | Wraps @ImGui::SetCurrentContext()@.
setCurrentContext :: MonadIO m => Context -> m ()
setCurrentContext (Context contextPtr) = liftIO do
[C.exp| void { SetCurrentContext($(ImGuiContext* contextPtr)) } |]
-- | Start a new Dear ImGui frame, you can submit any command from this point

View File

@ -69,3 +69,8 @@ instance Storable ImVec4 where
z <- peek (castPtr ptr `plusPtr` (sizeOf x * 2))
w <- peek (castPtr ptr `plusPtr` (sizeOf x * 3))
return ImVec4{ x, y, z, w }
--------------------------------------------------------------------------------
-- | DearImGui context handle.
data ImGuiContext