packages feed

dear-imgui-raw-implot-1.0.0: src/DearImGui/Raw/ImPlot/Rect.hsc

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

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

module DearImGui.Raw.ImPlot.Rect
  ( Rect (..)
  , c_contains
  , contains
  , containsDouble
  , destroy
  , init
  , withDefault
  ) where

import Control.Exception (bracket_)
import DearImGui.Raw.ImPlot.Point (Point)
import DearImGui.Raw.ImPlot.Range (Range)
import Foreign.C.Types
import Foreign.Marshal.Alloc (alloca)
import Foreign.Marshal.Utils (with)
import Foreign.Ptr (Ptr, plusPtr)
import Foreign.Storable (Storable (..))
import GHC.Records (HasField (..))
import Prelude hiding (init)

#include "dcimgui_implot.h"

-- structs (opaque)

-- by-value
data {-# CTYPE "dcimgui_implot.h" "ImPlotRect" #-} Rect = Rect
  { x :: Range
  , y :: Range
  }
  deriving (Eq, Show)
instance Storable Rect where
  sizeOf _    = #{size ImPlotRect}
  alignment _ = #{alignment ImPlotRect}
  peek p = Rect <$> #{peek ImPlotRect, X} p <*> #{peek ImPlotRect, Y} p
  poke p v = do
    #{poke ImPlotRect, X} p v.x
    #{poke ImPlotRect, Y} p v.y

instance HasField "x" (Ptr Rect) (Ptr Range) where
  getField = #{ptr ImPlotRect, X}

instance HasField "y" (Ptr Rect) (Ptr Range) where
  getField = #{ptr ImPlotRect, Y}

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

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

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

-- functions

foreign import capi unsafe "DearImGuiWrappers.h ImPlotRect_Contains_wrap"
  c_contains
    :: (Ptr Rect) -- ^ self
    -> (Ptr Point) -- ^ p
    -> IO CBool

contains
  :: (Ptr Rect) -- ^ self
  -> Point -- ^ p
  -> IO CBool
contains self p =
  with p $ \pPtr -> c_contains self pPtr

-- C: bool Contains(const ImPlotRect* self, double x, double y)
foreign import capi unsafe "dcimgui_implot.h ImPlotRect_ContainsDouble"
  containsDouble
    :: (Ptr Rect) -- ^ self
    -> Double -- ^ x
    -> Double -- ^ y
    -> IO CBool