{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module FULE.Container.Layered
( LayeredM
, Layered
, layered
) where
import Data.Functor.Identity
import Data.Maybe
import FULE.Container
import FULE.Container.Item
import FULE.Internal.Util
import FULE.LayoutOp
newtype LayeredM m k = Layered [ItemM m k]
type Layered = LayeredM Identity
instance (Monad m) => Container (LayeredM m k) k m where
minWidth :: LayeredM m k -> Proxy k -> m (Maybe Int)
minWidth (Layered [ItemM m k]
is) Proxy k
p = [Maybe Int] -> Maybe Int
getMaxSize ([Maybe Int] -> Maybe Int) -> m [Maybe Int] -> m (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ItemM m k -> m (Maybe Int)) -> [ItemM m k] -> m [Maybe Int]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (ItemM m k -> Proxy k -> m (Maybe Int)
forall c k (m :: * -> *).
Container c k m =>
c -> Proxy k -> m (Maybe Int)
`minWidth` Proxy k
p) [ItemM m k]
is
minHeight :: LayeredM m k -> Proxy k -> m (Maybe Int)
minHeight (Layered [ItemM m k]
is) Proxy k
p = [Maybe Int] -> Maybe Int
getMaxSize ([Maybe Int] -> Maybe Int) -> m [Maybe Int] -> m (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ItemM m k -> m (Maybe Int)) -> [ItemM m k] -> m [Maybe Int]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (ItemM m k -> Proxy k -> m (Maybe Int)
forall c k (m :: * -> *).
Container c k m =>
c -> Proxy k -> m (Maybe Int)
`minHeight` Proxy k
p) [ItemM m k]
is
addToLayout :: LayeredM m k -> Proxy k -> Bounds -> Maybe Int -> LayoutOp k m ()
addToLayout (Layered [ItemM m k]
is) Proxy k
proxy Bounds
bounds Maybe Int
renderGroup = do
Maybe Int
renderGroup' <- Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int)
-> StateT LayoutOpState (WriterT [ComponentInfo k] m) Int
-> StateT LayoutOpState (WriterT [ComponentInfo k] m) (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT LayoutOpState (WriterT [ComponentInfo k] m) Int
-> (Int -> StateT LayoutOpState (WriterT [ComponentInfo k] m) Int)
-> Maybe Int
-> StateT LayoutOpState (WriterT [ComponentInfo k] m) Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe StateT LayoutOpState (WriterT [ComponentInfo k] m) Int
forall (m :: * -> *) k. Monad m => LayoutOp k m Int
nextRenderGroup Int -> StateT LayoutOpState (WriterT [ComponentInfo k] m) Int
forall a. a -> StateT LayoutOpState (WriterT [ComponentInfo k] m) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Int
renderGroup
(ItemM m k -> LayoutOp k m ()) -> [ItemM m k] -> LayoutOp k m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ItemM m k
i -> ItemM m k -> Proxy k -> Bounds -> Maybe Int -> LayoutOp k m ()
forall c k (m :: * -> *).
Container c k m =>
c -> Proxy k -> Bounds -> Maybe Int -> LayoutOp k m ()
addToLayout ItemM m k
i Proxy k
proxy Bounds
bounds Maybe Int
renderGroup') [ItemM m k]
is
layered :: [ItemM m k] -> LayeredM m k
layered :: forall (m :: * -> *) k. [ItemM m k] -> LayeredM m k
layered = [ItemM m k] -> LayeredM m k
forall (m :: * -> *) k. [ItemM m k] -> LayeredM m k
Layered