{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- A render node repeating its single child node.

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

module GI.Gsk.Objects.RepeatNode
    ( 

-- * Exported types
    RepeatNode(..)                          ,
    IsRepeatNode                            ,
    toRepeatNode                            ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [draw]("GI.Gsk.Objects.RenderNode#g:method:draw"), [ref]("GI.Gsk.Objects.RenderNode#g:method:ref"), [serialize]("GI.Gsk.Objects.RenderNode#g:method:serialize"), [unref]("GI.Gsk.Objects.RenderNode#g:method:unref"), [writeToFile]("GI.Gsk.Objects.RenderNode#g:method:writeToFile").
-- 
-- ==== Getters
-- [getBounds]("GI.Gsk.Objects.RenderNode#g:method:getBounds"), [getChild]("GI.Gsk.Objects.RepeatNode#g:method:getChild"), [getChildBounds]("GI.Gsk.Objects.RepeatNode#g:method:getChildBounds"), [getNodeType]("GI.Gsk.Objects.RenderNode#g:method:getNodeType").
-- 
-- ==== Setters
-- /None/.

#if defined(ENABLE_OVERLOADING)
    ResolveRepeatNodeMethod                 ,
#endif

-- ** getChild #method:getChild#

#if defined(ENABLE_OVERLOADING)
    RepeatNodeGetChildMethodInfo            ,
#endif
    repeatNodeGetChild                      ,


-- ** getChildBounds #method:getChildBounds#

#if defined(ENABLE_OVERLOADING)
    RepeatNodeGetChildBoundsMethodInfo      ,
#endif
    repeatNodeGetChildBounds                ,


-- ** new #method:new#

    repeatNodeNew                           ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
import qualified GHC.Records as R

import qualified GI.Graphene.Structs.Rect as Graphene.Rect
import {-# SOURCE #-} qualified GI.Gsk.Objects.RenderNode as Gsk.RenderNode

-- | Memory-managed wrapper type.
newtype RepeatNode = RepeatNode (SP.ManagedPtr RepeatNode)
    deriving (RepeatNode -> RepeatNode -> Bool
(RepeatNode -> RepeatNode -> Bool)
-> (RepeatNode -> RepeatNode -> Bool) -> Eq RepeatNode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RepeatNode -> RepeatNode -> Bool
$c/= :: RepeatNode -> RepeatNode -> Bool
== :: RepeatNode -> RepeatNode -> Bool
$c== :: RepeatNode -> RepeatNode -> Bool
Eq)

instance SP.ManagedPtrNewtype RepeatNode where
    toManagedPtr :: RepeatNode -> ManagedPtr RepeatNode
toManagedPtr (RepeatNode ManagedPtr RepeatNode
p) = ManagedPtr RepeatNode
p

foreign import ccall "gsk_repeat_node_get_type"
    c_gsk_repeat_node_get_type :: IO B.Types.GType

instance B.Types.TypedObject RepeatNode where
    glibType :: IO GType
glibType = IO GType
c_gsk_repeat_node_get_type

-- | Type class for types which can be safely cast to `RepeatNode`, for instance with `toRepeatNode`.
class (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf RepeatNode o) => IsRepeatNode o
instance (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf RepeatNode o) => IsRepeatNode o

instance O.HasParentTypes RepeatNode
type instance O.ParentTypes RepeatNode = '[Gsk.RenderNode.RenderNode]

-- | Cast to `RepeatNode`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toRepeatNode :: (MIO.MonadIO m, IsRepeatNode o) => o -> m RepeatNode
toRepeatNode :: forall (m :: * -> *) o.
(MonadIO m, IsRepeatNode o) =>
o -> m RepeatNode
toRepeatNode = IO RepeatNode -> m RepeatNode
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO RepeatNode -> m RepeatNode)
-> (o -> IO RepeatNode) -> o -> m RepeatNode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr RepeatNode -> RepeatNode) -> o -> IO RepeatNode
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
B.ManagedPtr.unsafeCastTo ManagedPtr RepeatNode -> RepeatNode
RepeatNode

--- XXX Missing getter and/or setter, so no GValue instance could be generated.
#if defined(ENABLE_OVERLOADING)
type family ResolveRepeatNodeMethod (t :: Symbol) (o :: *) :: * where
    ResolveRepeatNodeMethod "draw" o = Gsk.RenderNode.RenderNodeDrawMethodInfo
    ResolveRepeatNodeMethod "ref" o = Gsk.RenderNode.RenderNodeRefMethodInfo
    ResolveRepeatNodeMethod "serialize" o = Gsk.RenderNode.RenderNodeSerializeMethodInfo
    ResolveRepeatNodeMethod "unref" o = Gsk.RenderNode.RenderNodeUnrefMethodInfo
    ResolveRepeatNodeMethod "writeToFile" o = Gsk.RenderNode.RenderNodeWriteToFileMethodInfo
    ResolveRepeatNodeMethod "getBounds" o = Gsk.RenderNode.RenderNodeGetBoundsMethodInfo
    ResolveRepeatNodeMethod "getChild" o = RepeatNodeGetChildMethodInfo
    ResolveRepeatNodeMethod "getChildBounds" o = RepeatNodeGetChildBoundsMethodInfo
    ResolveRepeatNodeMethod "getNodeType" o = Gsk.RenderNode.RenderNodeGetNodeTypeMethodInfo
    ResolveRepeatNodeMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveRepeatNodeMethod t RepeatNode, O.OverloadedMethod info RepeatNode p) => OL.IsLabel t (RepeatNode -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveRepeatNodeMethod t RepeatNode, O.OverloadedMethod info RepeatNode p, R.HasField t RepeatNode p) => R.HasField t RepeatNode p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveRepeatNodeMethod t RepeatNode, O.OverloadedMethodInfo info RepeatNode) => OL.IsLabel t (O.MethodProxy info RepeatNode) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif

-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance BoxedPtr RepeatNode where
    boxedPtrCopy :: RepeatNode -> IO RepeatNode
boxedPtrCopy = RepeatNode -> IO RepeatNode
forall (m :: * -> *) a. Monad m => a -> m a
return
    boxedPtrFree :: RepeatNode -> IO ()
boxedPtrFree = \RepeatNode
_x -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- method RepeatNode::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "bounds"
--           , argType =
--               TInterface Name { namespace = "Graphene" , name = "Rect" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The bounds of the area to be painted"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "child"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "RenderNode" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The child to repeat"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "child_bounds"
--           , argType =
--               TInterface Name { namespace = "Graphene" , name = "Rect" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "The area of the child to repeat or %NULL to\n    use the child's bounds"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gsk" , name = "RepeatNode" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_repeat_node_new" gsk_repeat_node_new :: 
    Ptr Graphene.Rect.Rect ->               -- bounds : TInterface (Name {namespace = "Graphene", name = "Rect"})
    Ptr Gsk.RenderNode.RenderNode ->        -- child : TInterface (Name {namespace = "Gsk", name = "RenderNode"})
    Ptr Graphene.Rect.Rect ->               -- child_bounds : TInterface (Name {namespace = "Graphene", name = "Rect"})
    IO (Ptr RepeatNode)

-- | Creates a @GskRenderNode@ that will repeat the drawing of /@child@/ across
-- the given /@bounds@/.
repeatNodeNew ::
    (B.CallStack.HasCallStack, MonadIO m, Gsk.RenderNode.IsRenderNode a) =>
    Graphene.Rect.Rect
    -- ^ /@bounds@/: The bounds of the area to be painted
    -> a
    -- ^ /@child@/: The child to repeat
    -> Maybe (Graphene.Rect.Rect)
    -- ^ /@childBounds@/: The area of the child to repeat or 'P.Nothing' to
    --     use the child\'s bounds
    -> m RepeatNode
    -- ^ __Returns:__ A new @GskRenderNode@
repeatNodeNew :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsRenderNode a) =>
Rect -> a -> Maybe Rect -> m RepeatNode
repeatNodeNew Rect
bounds a
child Maybe Rect
childBounds = IO RepeatNode -> m RepeatNode
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO RepeatNode -> m RepeatNode) -> IO RepeatNode -> m RepeatNode
forall a b. (a -> b) -> a -> b
$ do
    Ptr Rect
bounds' <- Rect -> IO (Ptr Rect)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Rect
bounds
    Ptr RenderNode
child' <- a -> IO (Ptr RenderNode)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
child
    Ptr Rect
maybeChildBounds <- case Maybe Rect
childBounds of
        Maybe Rect
Nothing -> Ptr Rect -> IO (Ptr Rect)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Rect
forall a. Ptr a
nullPtr
        Just Rect
jChildBounds -> do
            Ptr Rect
jChildBounds' <- Rect -> IO (Ptr Rect)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Rect
jChildBounds
            Ptr Rect -> IO (Ptr Rect)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Rect
jChildBounds'
    Ptr RepeatNode
result <- Ptr Rect -> Ptr RenderNode -> Ptr Rect -> IO (Ptr RepeatNode)
gsk_repeat_node_new Ptr Rect
bounds' Ptr RenderNode
child' Ptr Rect
maybeChildBounds
    Text -> Ptr RepeatNode -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"repeatNodeNew" Ptr RepeatNode
result
    RepeatNode
result' <- ((ManagedPtr RepeatNode -> RepeatNode)
-> Ptr RepeatNode -> IO RepeatNode
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr RepeatNode -> RepeatNode
RepeatNode) Ptr RepeatNode
result
    Rect -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Rect
bounds
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
child
    Maybe Rect -> (Rect -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe Rect
childBounds Rect -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    RepeatNode -> IO RepeatNode
forall (m :: * -> *) a. Monad m => a -> m a
return RepeatNode
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method RepeatNode::get_child
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "node"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "RepeatNode" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a repeat `GskRenderNode`"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gsk" , name = "RenderNode" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_repeat_node_get_child" gsk_repeat_node_get_child :: 
    Ptr RepeatNode ->                       -- node : TInterface (Name {namespace = "Gsk", name = "RepeatNode"})
    IO (Ptr Gsk.RenderNode.RenderNode)

-- | Retrieves the child of /@node@/.
repeatNodeGetChild ::
    (B.CallStack.HasCallStack, MonadIO m, IsRepeatNode a) =>
    a
    -- ^ /@node@/: a repeat @GskRenderNode@
    -> m Gsk.RenderNode.RenderNode
    -- ^ __Returns:__ a @GskRenderNode@
repeatNodeGetChild :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsRepeatNode a) =>
a -> m RenderNode
repeatNodeGetChild a
node = IO RenderNode -> m RenderNode
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO RenderNode -> m RenderNode) -> IO RenderNode -> m RenderNode
forall a b. (a -> b) -> a -> b
$ do
    Ptr RepeatNode
node' <- a -> IO (Ptr RepeatNode)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
node
    Ptr RenderNode
result <- Ptr RepeatNode -> IO (Ptr RenderNode)
gsk_repeat_node_get_child Ptr RepeatNode
node'
    Text -> Ptr RenderNode -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"repeatNodeGetChild" Ptr RenderNode
result
    RenderNode
result' <- ((ManagedPtr RenderNode -> RenderNode)
-> Ptr RenderNode -> IO RenderNode
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newPtr ManagedPtr RenderNode -> RenderNode
Gsk.RenderNode.RenderNode) Ptr RenderNode
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
node
    RenderNode -> IO RenderNode
forall (m :: * -> *) a. Monad m => a -> m a
return RenderNode
result'

#if defined(ENABLE_OVERLOADING)
data RepeatNodeGetChildMethodInfo
instance (signature ~ (m Gsk.RenderNode.RenderNode), MonadIO m, IsRepeatNode a) => O.OverloadedMethod RepeatNodeGetChildMethodInfo a signature where
    overloadedMethod = repeatNodeGetChild

instance O.OverloadedMethodInfo RepeatNodeGetChildMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gsk.Objects.RepeatNode.repeatNodeGetChild",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gsk-4.0.4/docs/GI-Gsk-Objects-RepeatNode.html#v:repeatNodeGetChild"
        })


#endif

-- method RepeatNode::get_child_bounds
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "node"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "RepeatNode" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a repeat `GskRenderNode`"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Graphene" , name = "Rect" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_repeat_node_get_child_bounds" gsk_repeat_node_get_child_bounds :: 
    Ptr RepeatNode ->                       -- node : TInterface (Name {namespace = "Gsk", name = "RepeatNode"})
    IO (Ptr Graphene.Rect.Rect)

-- | Retrieves the bounding rectangle of the child of /@node@/.
repeatNodeGetChildBounds ::
    (B.CallStack.HasCallStack, MonadIO m, IsRepeatNode a) =>
    a
    -- ^ /@node@/: a repeat @GskRenderNode@
    -> m Graphene.Rect.Rect
    -- ^ __Returns:__ a bounding rectangle
repeatNodeGetChildBounds :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsRepeatNode a) =>
a -> m Rect
repeatNodeGetChildBounds a
node = IO Rect -> m Rect
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Rect -> m Rect) -> IO Rect -> m Rect
forall a b. (a -> b) -> a -> b
$ do
    Ptr RepeatNode
node' <- a -> IO (Ptr RepeatNode)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
node
    Ptr Rect
result <- Ptr RepeatNode -> IO (Ptr Rect)
gsk_repeat_node_get_child_bounds Ptr RepeatNode
node'
    Text -> Ptr Rect -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"repeatNodeGetChildBounds" Ptr Rect
result
    Rect
result' <- ((ManagedPtr Rect -> Rect) -> Ptr Rect -> IO Rect
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr Rect -> Rect
Graphene.Rect.Rect) Ptr Rect
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
node
    Rect -> IO Rect
forall (m :: * -> *) a. Monad m => a -> m a
return Rect
result'

#if defined(ENABLE_OVERLOADING)
data RepeatNodeGetChildBoundsMethodInfo
instance (signature ~ (m Graphene.Rect.Rect), MonadIO m, IsRepeatNode a) => O.OverloadedMethod RepeatNodeGetChildBoundsMethodInfo a signature where
    overloadedMethod = repeatNodeGetChildBounds

instance O.OverloadedMethodInfo RepeatNodeGetChildBoundsMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gsk.Objects.RepeatNode.repeatNodeGetChildBounds",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gsk-4.0.4/docs/GI-Gsk-Objects-RepeatNode.html#v:repeatNodeGetChildBounds"
        })


#endif