module TD.Data.AreaPosition
( AreaPosition(..)
, defaultAreaPosition
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data AreaPosition
= AreaPosition
{ AreaPosition -> Maybe Double
x_percentage :: Maybe Double
, AreaPosition -> Maybe Double
y_percentage :: Maybe Double
, AreaPosition -> Maybe Double
width_percentage :: Maybe Double
, AreaPosition -> Maybe Double
height_percentage :: Maybe Double
, AreaPosition -> Maybe Double
rotation_angle :: Maybe Double
, AreaPosition -> Maybe Double
corner_radius_percentage :: Maybe Double
}
deriving (AreaPosition -> AreaPosition -> Bool
(AreaPosition -> AreaPosition -> Bool)
-> (AreaPosition -> AreaPosition -> Bool) -> Eq AreaPosition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AreaPosition -> AreaPosition -> Bool
== :: AreaPosition -> AreaPosition -> Bool
$c/= :: AreaPosition -> AreaPosition -> Bool
/= :: AreaPosition -> AreaPosition -> Bool
Eq, Int -> AreaPosition -> ShowS
[AreaPosition] -> ShowS
AreaPosition -> String
(Int -> AreaPosition -> ShowS)
-> (AreaPosition -> String)
-> ([AreaPosition] -> ShowS)
-> Show AreaPosition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AreaPosition -> ShowS
showsPrec :: Int -> AreaPosition -> ShowS
$cshow :: AreaPosition -> String
show :: AreaPosition -> String
$cshowList :: [AreaPosition] -> ShowS
showList :: [AreaPosition] -> ShowS
Show)
instance I.ShortShow AreaPosition where
shortShow :: AreaPosition -> String
shortShow AreaPosition
{ x_percentage :: AreaPosition -> Maybe Double
x_percentage = Maybe Double
x_percentage_
, y_percentage :: AreaPosition -> Maybe Double
y_percentage = Maybe Double
y_percentage_
, width_percentage :: AreaPosition -> Maybe Double
width_percentage = Maybe Double
width_percentage_
, height_percentage :: AreaPosition -> Maybe Double
height_percentage = Maybe Double
height_percentage_
, rotation_angle :: AreaPosition -> Maybe Double
rotation_angle = Maybe Double
rotation_angle_
, corner_radius_percentage :: AreaPosition -> Maybe Double
corner_radius_percentage = Maybe Double
corner_radius_percentage_
}
= String
"AreaPosition"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"x_percentage" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
x_percentage_
, String
"y_percentage" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
y_percentage_
, String
"width_percentage" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
width_percentage_
, String
"height_percentage" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
height_percentage_
, String
"rotation_angle" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
rotation_angle_
, String
"corner_radius_percentage" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
corner_radius_percentage_
]
instance AT.FromJSON AreaPosition where
parseJSON :: Value -> Parser AreaPosition
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"areaPosition" -> Value -> Parser AreaPosition
parseAreaPosition Value
v
String
_ -> Parser AreaPosition
forall a. Monoid a => a
mempty
where
parseAreaPosition :: A.Value -> AT.Parser AreaPosition
parseAreaPosition :: Value -> Parser AreaPosition
parseAreaPosition = String
-> (Object -> Parser AreaPosition) -> Value -> Parser AreaPosition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AreaPosition" ((Object -> Parser AreaPosition) -> Value -> Parser AreaPosition)
-> (Object -> Parser AreaPosition) -> Value -> Parser AreaPosition
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Double
x_percentage_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"x_percentage"
Maybe Double
y_percentage_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"y_percentage"
Maybe Double
width_percentage_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"width_percentage"
Maybe Double
height_percentage_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"height_percentage"
Maybe Double
rotation_angle_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"rotation_angle"
Maybe Double
corner_radius_percentage_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"corner_radius_percentage"
AreaPosition -> Parser AreaPosition
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AreaPosition -> Parser AreaPosition)
-> AreaPosition -> Parser AreaPosition
forall a b. (a -> b) -> a -> b
$ AreaPosition
{ x_percentage :: Maybe Double
x_percentage = Maybe Double
x_percentage_
, y_percentage :: Maybe Double
y_percentage = Maybe Double
y_percentage_
, width_percentage :: Maybe Double
width_percentage = Maybe Double
width_percentage_
, height_percentage :: Maybe Double
height_percentage = Maybe Double
height_percentage_
, rotation_angle :: Maybe Double
rotation_angle = Maybe Double
rotation_angle_
, corner_radius_percentage :: Maybe Double
corner_radius_percentage = Maybe Double
corner_radius_percentage_
}
parseJSON Value
_ = Parser AreaPosition
forall a. Monoid a => a
mempty
instance AT.ToJSON AreaPosition where
toJSON :: AreaPosition -> Value
toJSON AreaPosition
{ x_percentage :: AreaPosition -> Maybe Double
x_percentage = Maybe Double
x_percentage_
, y_percentage :: AreaPosition -> Maybe Double
y_percentage = Maybe Double
y_percentage_
, width_percentage :: AreaPosition -> Maybe Double
width_percentage = Maybe Double
width_percentage_
, height_percentage :: AreaPosition -> Maybe Double
height_percentage = Maybe Double
height_percentage_
, rotation_angle :: AreaPosition -> Maybe Double
rotation_angle = Maybe Double
rotation_angle_
, corner_radius_percentage :: AreaPosition -> Maybe Double
corner_radius_percentage = Maybe Double
corner_radius_percentage_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"areaPosition"
, Key
"x_percentage" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
x_percentage_
, Key
"y_percentage" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
y_percentage_
, Key
"width_percentage" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
width_percentage_
, Key
"height_percentage" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
height_percentage_
, Key
"rotation_angle" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
rotation_angle_
, Key
"corner_radius_percentage" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
corner_radius_percentage_
]
defaultAreaPosition :: AreaPosition
defaultAreaPosition :: AreaPosition
defaultAreaPosition =
AreaPosition
{ x_percentage :: Maybe Double
x_percentage = Maybe Double
forall a. Maybe a
Nothing
, y_percentage :: Maybe Double
y_percentage = Maybe Double
forall a. Maybe a
Nothing
, width_percentage :: Maybe Double
width_percentage = Maybe Double
forall a. Maybe a
Nothing
, height_percentage :: Maybe Double
height_percentage = Maybe Double
forall a. Maybe a
Nothing
, rotation_angle :: Maybe Double
rotation_angle = Maybe Double
forall a. Maybe a
Nothing
, corner_radius_percentage :: Maybe Double
corner_radius_percentage = Maybe Double
forall a. Maybe a
Nothing
}