packages feed

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

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

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

module DearImGui.Raw.ImVec2
  ( ImVec2 (..)
  , 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" "ImVec2" #-} ImVec2 = ImVec2
  { x :: Float
  , y :: Float
  }
  deriving (Eq, Show)
instance Storable ImVec2 where
  sizeOf _    = #{size ImVec2}
  alignment _ = #{alignment ImVec2}
  peek p = ImVec2 <$> #{peek ImVec2, x} p <*> #{peek ImVec2, y} p
  poke p v = do
    #{poke ImVec2, x} p v.x
    #{poke ImVec2, y} p v.y

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

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

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

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

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