{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# LANGUAGE NoImplicitPrelude #-}

-- | SDL locale services.
--
--     This provides a way to get a list of preferred locales (language plus country) for the user. There is exactly one function: @SDL_GetPreferredLocales()@, which handles all the heavy lifting, and offers documentation on all the strange ways humans might have configured their language settings. A struct to provide locale data.
--
--     Locale data is split into a spoken language, like English, and an optional country, like Canada. The language will be in ISO-639 format (so English would be \"en\"), and the country, if not NULL, will be an ISO-3166 country code (so Canada would be \"CA\").
--
--     @since 3.2.0
--
--     [See also]: 'sDL_GetPreferredLocales'
module SDL3.Sys.Bindgen.Locale (
  SDL3.Sys.Bindgen.Locale.SDL_Locale (..),
)
where

import Prelude (Eq, Int, Show, pure, (<*>), (>>), type (~))

import HsBindgen.Runtime.HasCField qualified as HasCField
import HsBindgen.Runtime.Marshal qualified as Marshal
import HsBindgen.Runtime.PtrConst qualified as PtrConst
import HsBindgen.Runtime.Struct qualified as Struct
import HsBindgen.Runtime.Support qualified as BG
import HsBindgen.Runtime.Support.CompatHasField qualified as BG.CompatHasField

-- | [C declaration]: @struct SDL_Locale@, defined at @SDL3\/SDL_locale.h 60:16@
data SDL_Locale = SDL_Locale
  { SDL_Locale -> PtrConst CChar
language :: PtrConst.PtrConst BG.CChar
  -- ^ A language name, like \"en\" for English.
  --
  --          [C declaration]: @language@, defined at @SDL3\/SDL_locale.h 62:17@
  , SDL_Locale -> PtrConst CChar
country :: PtrConst.PtrConst BG.CChar
  -- ^ A country, like \"US\" for America. Can be NULL.
  --
  --          [C declaration]: @country@, defined at @SDL3\/SDL_locale.h 63:17@
  }
  deriving stock ((forall x. SDL_Locale -> Rep SDL_Locale x)
-> (forall x. Rep SDL_Locale x -> SDL_Locale) -> Generic SDL_Locale
forall x. Rep SDL_Locale x -> SDL_Locale
forall x. SDL_Locale -> Rep SDL_Locale x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SDL_Locale -> Rep SDL_Locale x
from :: forall x. SDL_Locale -> Rep SDL_Locale x
$cto :: forall x. Rep SDL_Locale x -> SDL_Locale
to :: forall x. Rep SDL_Locale x -> SDL_Locale
BG.Generic, SDL_Locale -> SDL_Locale -> Bool
(SDL_Locale -> SDL_Locale -> Bool)
-> (SDL_Locale -> SDL_Locale -> Bool) -> Eq SDL_Locale
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SDL_Locale -> SDL_Locale -> Bool
== :: SDL_Locale -> SDL_Locale -> Bool
$c/= :: SDL_Locale -> SDL_Locale -> Bool
/= :: SDL_Locale -> SDL_Locale -> Bool
Eq, Int -> SDL_Locale -> ShowS
[SDL_Locale] -> ShowS
SDL_Locale -> String
(Int -> SDL_Locale -> ShowS)
-> (SDL_Locale -> String)
-> ([SDL_Locale] -> ShowS)
-> Show SDL_Locale
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SDL_Locale -> ShowS
showsPrec :: Int -> SDL_Locale -> ShowS
$cshow :: SDL_Locale -> String
show :: SDL_Locale -> String
$cshowList :: [SDL_Locale] -> ShowS
showList :: [SDL_Locale] -> ShowS
Show)

instance Marshal.StaticSize SDL_Locale where
  staticSizeOf :: Proxy SDL_Locale -> Int
staticSizeOf = \Proxy SDL_Locale
_ -> (Int
16 :: Int)

  staticAlignment :: Proxy SDL_Locale -> Int
staticAlignment = \Proxy SDL_Locale
_ -> (Int
8 :: Int)

instance Marshal.ReadRaw SDL_Locale where
  readRaw :: Ptr SDL_Locale -> IO SDL_Locale
readRaw =
    \Ptr SDL_Locale
ptr0 ->
      (PtrConst CChar -> PtrConst CChar -> SDL_Locale)
-> IO (PtrConst CChar -> PtrConst CChar -> SDL_Locale)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PtrConst CChar -> PtrConst CChar -> SDL_Locale
SDL_Locale
        IO (PtrConst CChar -> PtrConst CChar -> SDL_Locale)
-> IO (PtrConst CChar) -> IO (PtrConst CChar -> SDL_Locale)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Proxy "language"
-> Ptr SDL_Locale -> IO (CFieldType SDL_Locale "language")
forall a (field :: Symbol).
(HasCField a field, ReadRaw (CFieldType a field)) =>
Proxy field -> Ptr a -> IO (CFieldType a field)
HasCField.readRaw (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"language") Ptr SDL_Locale
ptr0
        IO (PtrConst CChar -> SDL_Locale)
-> IO (PtrConst CChar) -> IO SDL_Locale
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Proxy "country"
-> Ptr SDL_Locale -> IO (CFieldType SDL_Locale "country")
forall a (field :: Symbol).
(HasCField a field, ReadRaw (CFieldType a field)) =>
Proxy field -> Ptr a -> IO (CFieldType a field)
HasCField.readRaw (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"country") Ptr SDL_Locale
ptr0

instance Marshal.WriteRaw SDL_Locale where
  writeRaw :: Ptr SDL_Locale -> SDL_Locale -> IO ()
writeRaw =
    \Ptr SDL_Locale
ptr0 ->
      \SDL_Locale
s1 ->
        case SDL_Locale
s1 of
          SDL_Locale PtrConst CChar
language2 PtrConst CChar
country3 ->
            Proxy "language"
-> Ptr SDL_Locale -> CFieldType SDL_Locale "language" -> IO ()
forall a (field :: Symbol).
(HasCField a field, WriteRaw (CFieldType a field)) =>
Proxy field -> Ptr a -> CFieldType a field -> IO ()
HasCField.writeRaw (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"language") Ptr SDL_Locale
ptr0 PtrConst CChar
CFieldType SDL_Locale "language"
language2
              IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Proxy "country"
-> Ptr SDL_Locale -> CFieldType SDL_Locale "country" -> IO ()
forall a (field :: Symbol).
(HasCField a field, WriteRaw (CFieldType a field)) =>
Proxy field -> Ptr a -> CFieldType a field -> IO ()
HasCField.writeRaw (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"country") Ptr SDL_Locale
ptr0 PtrConst CChar
CFieldType SDL_Locale "country"
country3

deriving via Marshal.EquivStorable SDL_Locale instance BG.Storable SDL_Locale

deriving via Struct.IsStructViaReadRaw SDL_Locale instance Struct.IsStruct SDL_Locale

-- | A language name, like \"en\" for English.
--
--     [C declaration]: @language@, defined at @SDL3\/SDL_locale.h 62:17@
instance
  (ty ~ PtrConst.PtrConst BG.CChar)
  => BG.CompatHasField.HasField "language" SDL_Locale ty
  where
  hasField :: SDL_Locale -> (ty -> SDL_Locale, ty)
hasField =
    \SDL_Locale
x0 ->
      ( \ty
y1 ->
          SDL_Locale{language :: PtrConst CChar
language = ty
PtrConst CChar
y1, country :: PtrConst CChar
country = forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"country" SDL_Locale
x0}
      , forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"language" SDL_Locale
x0
      )

instance
  (ty ~ PtrConst.PtrConst BG.CChar)
  => BG.HasField "language" (BG.Ptr SDL_Locale) (BG.Ptr ty)
  where
  getField :: Ptr SDL_Locale -> Ptr ty
getField = Proxy "language"
-> Ptr SDL_Locale -> Ptr (CFieldType SDL_Locale "language")
forall a (field :: Symbol).
HasCField a field =>
Proxy field -> Ptr a -> Ptr (CFieldType a field)
HasCField.fromPtr (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"language")

instance HasCField.HasCField SDL_Locale "language" where
  type
    CFieldType SDL_Locale "language" =
      PtrConst.PtrConst BG.CChar

  offset# :: Proxy# SDL_Locale -> Proxy# "language" -> Int
offset# = \Proxy# SDL_Locale
_ -> \Proxy# "language"
_ -> Int
0

-- | A country, like \"US\" for America. Can be NULL.
--
--     [C declaration]: @country@, defined at @SDL3\/SDL_locale.h 63:17@
instance
  (ty ~ PtrConst.PtrConst BG.CChar)
  => BG.CompatHasField.HasField "country" SDL_Locale ty
  where
  hasField :: SDL_Locale -> (ty -> SDL_Locale, ty)
hasField =
    \SDL_Locale
x0 ->
      ( \ty
y1 ->
          SDL_Locale{country :: PtrConst CChar
country = ty
PtrConst CChar
y1, language :: PtrConst CChar
language = forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"language" SDL_Locale
x0}
      , forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"country" SDL_Locale
x0
      )

instance
  (ty ~ PtrConst.PtrConst BG.CChar)
  => BG.HasField "country" (BG.Ptr SDL_Locale) (BG.Ptr ty)
  where
  getField :: Ptr SDL_Locale -> Ptr ty
getField = Proxy "country"
-> Ptr SDL_Locale -> Ptr (CFieldType SDL_Locale "country")
forall a (field :: Symbol).
HasCField a field =>
Proxy field -> Ptr a -> Ptr (CFieldType a field)
HasCField.fromPtr (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"country")

instance HasCField.HasCField SDL_Locale "country" where
  type
    CFieldType SDL_Locale "country" =
      PtrConst.PtrConst BG.CChar

  offset# :: Proxy# SDL_Locale -> Proxy# "country" -> Int
offset# = \Proxy# SDL_Locale
_ -> \Proxy# "country"
_ -> Int
8