packages feed

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

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

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

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

import Control.Exception (bracket_)
import DearImGui.Raw.Enums.ImGuiMouseSource (ImGuiMouseSource)
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" "ImGuiInputEventMouseButton" #-} ImGuiInputEventMouseButton = ImGuiInputEventMouseButton
  { button :: CInt
  , down :: CBool
  , mouseSource :: ImGuiMouseSource
  }
  deriving (Eq, Show)
instance Storable ImGuiInputEventMouseButton where
  sizeOf _    = #{size ImGuiInputEventMouseButton}
  alignment _ = #{alignment ImGuiInputEventMouseButton}
  peek p = ImGuiInputEventMouseButton <$> #{peek ImGuiInputEventMouseButton, Button} p <*> #{peek ImGuiInputEventMouseButton, Down} p <*> #{peek ImGuiInputEventMouseButton, MouseSource} p
  poke p v = do
    #{poke ImGuiInputEventMouseButton, Button} p v.button
    #{poke ImGuiInputEventMouseButton, Down} p v.down
    #{poke ImGuiInputEventMouseButton, MouseSource} p v.mouseSource

instance HasField "button" (Ptr ImGuiInputEventMouseButton) (Ptr CInt) where
  getField = #{ptr ImGuiInputEventMouseButton, Button}

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

instance HasField "mouseSource" (Ptr ImGuiInputEventMouseButton) (Ptr ImGuiMouseSource) where
  getField = #{ptr ImGuiInputEventMouseButton, MouseSource}

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

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

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