packages feed

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

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

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

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

import Control.Exception (bracket_)
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)

-- by-value
data {-# CTYPE "dcimgui_nodefaultargfunctions.h" "ImVec4" #-} ImVec4 = ImVec4
  { x :: Float
  , y :: Float
  , z :: Float
  , w :: Float
  }
  deriving (Eq, Show)
instance Storable ImVec4 where
  sizeOf _    = #{size ImVec4}
  alignment _ = #{alignment ImVec4}
  peek p = ImVec4 <$> #{peek ImVec4, x} p <*> #{peek ImVec4, y} p <*> #{peek ImVec4, z} p <*> #{peek ImVec4, w} p
  poke p v = do
    #{poke ImVec4, x} p v.x
    #{poke ImVec4, y} p v.y
    #{poke ImVec4, z} p v.z
    #{poke ImVec4, w} p v.w

instance HasField "x" (Ptr ImVec4) (Ptr Float) where
  getField = #{ptr ImVec4, x}

instance HasField "y" (Ptr ImVec4) (Ptr Float) where
  getField = #{ptr ImVec4, y}

instance HasField "z" (Ptr ImVec4) (Ptr Float) where
  getField = #{ptr ImVec4, z}

instance HasField "w" (Ptr ImVec4) (Ptr Float) where
  getField = #{ptr ImVec4, w}

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

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

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