module LayoutF(serCompLF, compLF, listLF, untaggedListLF,
	       --rbLayoutF,
               nullLF, holeF, holeF', lF, LayoutDirection(..),orientP) where
--import TableP
import CompF
import CompOps((>^=<))
import Fudget
import FRequest
import Geometry() -- instances
import LayoutDir(Orientation(..))
import LayoutRequest
import Placers
import ListF
import NullF
import FudgetIO
import SerCompF(serCompF)
import Utils(number)
--import Xtypes
import AlignP(revP)
import Placer(placerF)

data LayoutDirection = Forward | Backward  deriving (LayoutDirection -> LayoutDirection -> Bool
(LayoutDirection -> LayoutDirection -> Bool)
-> (LayoutDirection -> LayoutDirection -> Bool)
-> Eq LayoutDirection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LayoutDirection -> LayoutDirection -> Bool
$c/= :: LayoutDirection -> LayoutDirection -> Bool
== :: LayoutDirection -> LayoutDirection -> Bool
$c== :: LayoutDirection -> LayoutDirection -> Bool
Eq, Eq LayoutDirection
Eq LayoutDirection
-> (LayoutDirection -> LayoutDirection -> Ordering)
-> (LayoutDirection -> LayoutDirection -> Bool)
-> (LayoutDirection -> LayoutDirection -> Bool)
-> (LayoutDirection -> LayoutDirection -> Bool)
-> (LayoutDirection -> LayoutDirection -> Bool)
-> (LayoutDirection -> LayoutDirection -> LayoutDirection)
-> (LayoutDirection -> LayoutDirection -> LayoutDirection)
-> Ord LayoutDirection
LayoutDirection -> LayoutDirection -> Bool
LayoutDirection -> LayoutDirection -> Ordering
LayoutDirection -> LayoutDirection -> LayoutDirection
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LayoutDirection -> LayoutDirection -> LayoutDirection
$cmin :: LayoutDirection -> LayoutDirection -> LayoutDirection
max :: LayoutDirection -> LayoutDirection -> LayoutDirection
$cmax :: LayoutDirection -> LayoutDirection -> LayoutDirection
>= :: LayoutDirection -> LayoutDirection -> Bool
$c>= :: LayoutDirection -> LayoutDirection -> Bool
> :: LayoutDirection -> LayoutDirection -> Bool
$c> :: LayoutDirection -> LayoutDirection -> Bool
<= :: LayoutDirection -> LayoutDirection -> Bool
$c<= :: LayoutDirection -> LayoutDirection -> Bool
< :: LayoutDirection -> LayoutDirection -> Bool
$c< :: LayoutDirection -> LayoutDirection -> Bool
compare :: LayoutDirection -> LayoutDirection -> Ordering
$ccompare :: LayoutDirection -> LayoutDirection -> Ordering
$cp1Ord :: Eq LayoutDirection
Ord,Int -> LayoutDirection -> ShowS
[LayoutDirection] -> ShowS
LayoutDirection -> String
(Int -> LayoutDirection -> ShowS)
-> (LayoutDirection -> String)
-> ([LayoutDirection] -> ShowS)
-> Show LayoutDirection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LayoutDirection] -> ShowS
$cshowList :: [LayoutDirection] -> ShowS
show :: LayoutDirection -> String
$cshow :: LayoutDirection -> String
showsPrec :: Int -> LayoutDirection -> ShowS
$cshowsPrec :: Int -> LayoutDirection -> ShowS
Show)

holeF' :: Size -> F hi ho
holeF' Size
s = FRequest -> F hi ho -> F hi ho
forall (f :: * -> * -> *) hi ho.
FudgetIO f =>
FRequest -> f hi ho -> f hi ho
putLow (LayoutRequest -> FRequest
layoutRequestCmd (Size -> Bool -> Bool -> LayoutRequest
plainLayout Size
s Bool
False Bool
False)) F hi ho
forall hi ho. F hi ho
nullF
holeF :: F hi ho
holeF = Size -> F hi ho
forall hi ho. Size -> F hi ho
holeF' Size
0
nullLF :: F hi ho
nullLF = F hi ho
forall hi ho. F hi ho
holeF

--listLF :: Eq a => Placer -> [(a, F b c)] -> F (a, b) (a, c)
listLF :: Placer -> [(a, F b c)] -> F (a, b) (a, c)
listLF Placer
placer [(a, F b c)]
fl = Int
-> LayoutDirection -> Placer -> F (a, b) (a, c) -> F (a, b) (a, c)
forall a b. Int -> LayoutDirection -> Placer -> F a b -> F a b
lF ([(a, F b c)] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(a, F b c)]
fl) LayoutDirection
Forward Placer
placer ([(a, F b c)] -> F (a, b) (a, c)
forall a b c. Eq a => [(a, F b c)] -> F (a, b) (a, c)
listF [(a, F b c)]
fl)

untaggedListLF :: Placer -> [F a b] -> F (Int, a) b
untaggedListLF :: Placer -> [F a b] -> F (Int, a) b
untaggedListLF Placer
layout [F a b]
fs = (Int, b) -> b
forall a b. (a, b) -> b
snd ((Int, b) -> b) -> F (Int, a) (Int, b) -> F (Int, a) b
forall a b e. (a -> b) -> F e a -> F e b
>^=< Placer -> [(Int, F a b)] -> F (Int, a) (Int, b)
forall a b c. Eq a => Placer -> [(a, F b c)] -> F (a, b) (a, c)
listLF Placer
layout (Int -> [F a b] -> [(Int, F a b)]
forall a. Int -> [a] -> [(Int, a)]
number Int
0 [F a b]
fs)

compLF :: (F a b, Orientation) -> F c d -> F (Either a c) (Either b d)
compLF = (F a b -> F c d -> F (Either a c) (Either b d))
-> (F a b, Orientation) -> F c d -> F (Either a c) (Either b d)
forall a b c d e f.
(F a b -> F c d -> F e f) -> (F a b, Orientation) -> F c d -> F e f
cLF F a b -> F c d -> F (Either a c) (Either b d)
forall a b c d. F a b -> F c d -> F (Either a c) (Either b d)
compF
serCompLF :: (F a1 f, Orientation) -> F e a1 -> F e f
serCompLF = (F a1 f -> F e a1 -> F e f)
-> (F a1 f, Orientation) -> F e a1 -> F e f
forall a b c d e f.
(F a b -> F c d -> F e f) -> (F a b, Orientation) -> F c d -> F e f
cLF F a1 f -> F e a1 -> F e f
forall a1 b a2. F a1 b -> F a2 a1 -> F a2 b
serCompF
--rbLayoutF sep = lF 3 Forward (rightBelowP sep)

cLF :: ((F a b) -> (F c d) -> F e f) -> (F a b,Orientation) -> F c d -> F e f
cLF :: (F a b -> F c d -> F e f) -> (F a b, Orientation) -> F c d -> F e f
cLF F a b -> F c d -> F e f
cF (F a b
f1,Orientation
ori) F c d
f2 = Int -> LayoutDirection -> Placer -> F e f -> F e f
forall a b. Int -> LayoutDirection -> Placer -> F a b -> F a b
lF Int
2 LayoutDirection
Forward (Orientation -> Placer
orientP Orientation
ori) (F a b -> F c d -> F e f
cF F a b
f1 F c d
f2)

lF :: Int -> LayoutDirection -> Placer -> (F a b) -> F a b
lF :: Int -> LayoutDirection -> Placer -> F a b -> F a b
lF Int
0 LayoutDirection
_ Placer
_ F a b
f = F a b
forall hi ho. F hi ho
nullLF
lF Int
nofudgets LayoutDirection
dir Placer
placer F a b
f = Placer -> F a b -> F a b
forall a b. Placer -> F a b -> F a b
placerF Placer
placer' F a b
f where 
     placer' :: Placer
placer' = if LayoutDirection
dir LayoutDirection -> LayoutDirection -> Bool
forall a. Eq a => a -> a -> Bool
== LayoutDirection
Backward then Placer -> Placer
revP Placer
placer else Placer
placer

orientP :: Orientation -> Placer
orientP :: Orientation -> Placer
orientP Orientation
ori =
   case Orientation
ori of
     Orientation
Above -> Placer
verticalP
     Orientation
Below -> Placer -> Placer
revP Placer
verticalP
     Orientation
LeftOf -> Placer
horizontalP
     Orientation
RightOf -> Placer -> Placer
revP Placer
horizontalP