packages feed

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

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

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

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

import Control.Exception (bracket_)
import DearImGui.Raw (ImU32)
import DearImGui.Raw.ImVec2 (ImVec2)
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" "ImDrawVert" #-} ImDrawVert = ImDrawVert
  { pos :: ImVec2
  , uv :: ImVec2
  , col :: ImU32
  }
  deriving (Eq, Show)
instance Storable ImDrawVert where
  sizeOf _    = #{size ImDrawVert}
  alignment _ = #{alignment ImDrawVert}
  peek p = ImDrawVert <$> #{peek ImDrawVert, pos} p <*> #{peek ImDrawVert, uv} p <*> #{peek ImDrawVert, col} p
  poke p v = do
    #{poke ImDrawVert, pos} p v.pos
    #{poke ImDrawVert, uv} p v.uv
    #{poke ImDrawVert, col} p v.col

instance HasField "pos" (Ptr ImDrawVert) (Ptr ImVec2) where
  getField = #{ptr ImDrawVert, pos}

instance HasField "uv" (Ptr ImDrawVert) (Ptr ImVec2) where
  getField = #{ptr ImDrawVert, uv}

instance HasField "col" (Ptr ImDrawVert) (Ptr ImU32) where
  getField = #{ptr ImDrawVert, col}

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

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

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