packages feed

dear-imgui-raw-internal-1.0.0: src/DearImGui/Raw/Internal/ImGuiContextHook.hsc

{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE PatternSynonyms #-}

-- This file was generated by dear-bindings-ffi. Do not edit by hand.

module DearImGui.Raw.Internal.ImGuiContextHook
  ( Callback
  , ImGuiContextHook (..)
  , destroy
  , init
  , withDefault
  ) where

import Control.Exception (bracket_)
import DearImGui.Raw (ImGuiID)
import DearImGui.Raw.Internal.Enums.ImGuiContextHookType (ImGuiContextHookType)
import DearImGui.Raw.Internal.ImGuiContext (ImGuiContext)
import Foreign.Marshal.Alloc (alloca)
import Foreign.Ptr (FunPtr, Ptr, plusPtr)
import Foreign.Storable (Storable (..))
import GHC.Records (HasField (..))
import Prelude hiding (init)

#include "dcimgui_nodefaultargfunctions_internal.h"

-- typedefs

type Callback = FunPtr ((Ptr ImGuiContext) -> (Ptr ImGuiContextHook) -> IO ())

-- structs (opaque)

data {-# CTYPE "dcimgui_nodefaultargfunctions_internal.h" "ImGuiContextHook" #-} ImGuiContextHook = ImGuiContextHook
  { hookId :: ImGuiID
  , type_ :: ImGuiContextHookType
  , owner :: ImGuiID
  , callback :: Callback
  , userData :: Ptr ()
  }
  deriving (Eq, Show)
instance Storable ImGuiContextHook where
  sizeOf _    = #{size ImGuiContextHook}
  alignment _ = #{alignment ImGuiContextHook}
  peek p = ImGuiContextHook <$> #{peek ImGuiContextHook, HookId} p <*> #{peek ImGuiContextHook, Type} p <*> #{peek ImGuiContextHook, Owner} p <*> #{peek ImGuiContextHook, Callback} p <*> #{peek ImGuiContextHook, UserData} p
  poke p v = do
    #{poke ImGuiContextHook, HookId} p v.hookId
    #{poke ImGuiContextHook, Type} p v.type_
    #{poke ImGuiContextHook, Owner} p v.owner
    #{poke ImGuiContextHook, Callback} p v.callback
    #{poke ImGuiContextHook, UserData} p v.userData

instance HasField "hookId" (Ptr ImGuiContextHook) (Ptr ImGuiID) where
  getField = #{ptr ImGuiContextHook, HookId}

instance HasField "type_" (Ptr ImGuiContextHook) (Ptr ImGuiContextHookType) where
  getField = #{ptr ImGuiContextHook, Type}

instance HasField "owner" (Ptr ImGuiContextHook) (Ptr ImGuiID) where
  getField = #{ptr ImGuiContextHook, Owner}

instance HasField "callback" (Ptr ImGuiContextHook) (Ptr Callback) where
  getField = #{ptr ImGuiContextHook, Callback}

instance HasField "userData" (Ptr ImGuiContextHook) (Ptr (Ptr ())) where
  getField = #{ptr ImGuiContextHook, UserData}

foreign import capi unsafe "DearImGuiWrappers.h ImGuiContextHook_Init_wrap"
  init
    :: Ptr ImGuiContextHook
    -> IO ()

foreign import capi unsafe "DearImGuiWrappers.h ImGuiContextHook_Destroy_wrap"
  destroy
    :: Ptr ImGuiContextHook
    -> IO ()

withDefault :: (Ptr ImGuiContextHook -> IO a) -> IO a
withDefault k = alloca $ \p -> bracket_ (init p) (destroy p) (k p)