packages feed

dear-imgui-raw-internal-1.0.0: src/DearImGui/Raw/Internal/ImGuiInputEventKey.hsc

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

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

module DearImGui.Raw.Internal.ImGuiInputEventKey
  ( ImGuiInputEventKey (..)
  , destroy
  , init
  , withDefault
  ) where

import Control.Exception (bracket_)
import DearImGui.Raw.Enums.ImGuiKey (ImGuiKey)
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_internal.h"

-- structs (opaque)

data {-# CTYPE "dcimgui_nodefaultargfunctions_internal.h" "ImGuiInputEventKey" #-} ImGuiInputEventKey = ImGuiInputEventKey
  { key :: ImGuiKey
  , down :: CBool
  , analogValue :: Float
  }
  deriving (Eq, Show)
instance Storable ImGuiInputEventKey where
  sizeOf _    = #{size ImGuiInputEventKey}
  alignment _ = #{alignment ImGuiInputEventKey}
  peek p = ImGuiInputEventKey <$> #{peek ImGuiInputEventKey, Key} p <*> #{peek ImGuiInputEventKey, Down} p <*> #{peek ImGuiInputEventKey, AnalogValue} p
  poke p v = do
    #{poke ImGuiInputEventKey, Key} p v.key
    #{poke ImGuiInputEventKey, Down} p v.down
    #{poke ImGuiInputEventKey, AnalogValue} p v.analogValue

instance HasField "key" (Ptr ImGuiInputEventKey) (Ptr ImGuiKey) where
  getField = #{ptr ImGuiInputEventKey, Key}

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

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

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

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

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