packages feed

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

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

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

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

import Control.Exception (bracket_)
import Foreign.C.Types
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" "ImGuiKeyData" #-} ImGuiKeyData = ImGuiKeyData
  { down :: CBool
  , downDuration :: Float
  , downDurationPrev :: Float
  , analogValue :: Float
  }
  deriving (Eq, Show)
instance Storable ImGuiKeyData where
  sizeOf _    = #{size ImGuiKeyData}
  alignment _ = #{alignment ImGuiKeyData}
  peek p = ImGuiKeyData <$> #{peek ImGuiKeyData, Down} p <*> #{peek ImGuiKeyData, DownDuration} p <*> #{peek ImGuiKeyData, DownDurationPrev} p <*> #{peek ImGuiKeyData, AnalogValue} p
  poke p v = do
    #{poke ImGuiKeyData, Down} p v.down
    #{poke ImGuiKeyData, DownDuration} p v.downDuration
    #{poke ImGuiKeyData, DownDurationPrev} p v.downDurationPrev
    #{poke ImGuiKeyData, AnalogValue} p v.analogValue

instance HasField "down" (Ptr ImGuiKeyData) (Ptr CBool) where
  getField = #{ptr ImGuiKeyData, Down}

instance HasField "downDuration" (Ptr ImGuiKeyData) (Ptr Float) where
  getField = #{ptr ImGuiKeyData, DownDuration}

instance HasField "downDurationPrev" (Ptr ImGuiKeyData) (Ptr Float) where
  getField = #{ptr ImGuiKeyData, DownDurationPrev}

instance HasField "analogValue" (Ptr ImGuiKeyData) (Ptr Float) where
  getField = #{ptr ImGuiKeyData, AnalogValue}

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

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

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