packages feed

dear-imgui-raw-1.0.0: src/DearImGui/Raw/ImDrawChannel.hsc

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

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

module DearImGui.Raw.ImDrawChannel
  ( ImDrawChannel (..)
  , destroy
  , init
  , withDefault
  ) where

import Control.Exception (bracket_)
import DearImGui.Raw (ImDrawIdx)
import DearImGui.Raw.ImDrawCmd (ImDrawCmd)
import DearImGui.Raw.ImVector (ImVector)
import Foreign.Marshal.Alloc (alloca)
import Foreign.Ptr (Ptr, plusPtr)
import Foreign.Storable (Storable (..))
import GHC.Records (HasField (..))
import Prelude hiding (init)

#include "dcimgui_nodefaultargfunctions.h"

-- structs (opaque)

data {-# CTYPE "dcimgui_nodefaultargfunctions.h" "ImDrawChannel" #-} ImDrawChannel = ImDrawChannel
  { _CmdBuffer :: ImVector ImDrawCmd
  , _IdxBuffer :: ImVector ImDrawIdx
  }
  deriving (Eq, Show)
instance Storable ImDrawChannel where
  sizeOf _    = #{size ImDrawChannel}
  alignment _ = #{alignment ImDrawChannel}
  peek p = ImDrawChannel <$> #{peek ImDrawChannel, _CmdBuffer} p <*> #{peek ImDrawChannel, _IdxBuffer} p
  poke p v = do
    #{poke ImDrawChannel, _CmdBuffer} p v._CmdBuffer
    #{poke ImDrawChannel, _IdxBuffer} p v._IdxBuffer

instance HasField "_CmdBuffer" (Ptr ImDrawChannel) (Ptr (ImVector ImDrawCmd)) where
  getField = #{ptr ImDrawChannel, _CmdBuffer}

instance HasField "_IdxBuffer" (Ptr ImDrawChannel) (Ptr (ImVector ImDrawIdx)) where
  getField = #{ptr ImDrawChannel, _IdxBuffer}

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

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

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