module TreeBrowser(Tree(..),treeBrowserF',treeDisplayF') where
import AllFudgets hiding (Tree(..))
import qualified ReactiveF as R

data Tree leaf node
  = Leaf leaf
  | Node node [Tree leaf node]
  deriving (Int -> Tree leaf node -> ShowS
[Tree leaf node] -> ShowS
Tree leaf node -> String
(Int -> Tree leaf node -> ShowS)
-> (Tree leaf node -> String)
-> ([Tree leaf node] -> ShowS)
-> Show (Tree leaf node)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall leaf node.
(Show leaf, Show node) =>
Int -> Tree leaf node -> ShowS
forall leaf node.
(Show leaf, Show node) =>
[Tree leaf node] -> ShowS
forall leaf node.
(Show leaf, Show node) =>
Tree leaf node -> String
showList :: [Tree leaf node] -> ShowS
$cshowList :: forall leaf node.
(Show leaf, Show node) =>
[Tree leaf node] -> ShowS
show :: Tree leaf node -> String
$cshow :: forall leaf node.
(Show leaf, Show node) =>
Tree leaf node -> String
showsPrec :: Int -> Tree leaf node -> ShowS
$cshowsPrec :: forall leaf node.
(Show leaf, Show node) =>
Int -> Tree leaf node -> ShowS
Show)


--treeBrowserF = treeBrowserF standard

treeDisplayF' :: Tree leaf node -> F (Tree leaf node) (Tree leaf node)
treeDisplayF' Tree leaf node
t = ((FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx,
  FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx)
 -> Tree leaf node -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> Tree leaf node -> F (Tree leaf node) (Tree leaf node)
forall node lbl lbl i leaf.
Graphic node =>
((FlexibleDrawing -> Drawing lbl Gfx,
  FlexibleDrawing -> Drawing lbl Gfx)
 -> i -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> i -> F i (Tree leaf node)
treeBrowserF'' (FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> Tree leaf node -> Drawing (Either Bool (Tree leaf node)) Gfx
forall a a.
(Graphic a, Graphic a) =>
(FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
drawStaticTree Tree leaf node
t
treeBrowserF' :: Tree leaf node -> F (Tree leaf node) (Tree leaf node)
treeBrowserF' Tree leaf node
t = ((FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx,
  FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx)
 -> Tree leaf node -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> Tree leaf node -> F (Tree leaf node) (Tree leaf node)
forall node lbl lbl i leaf.
Graphic node =>
((FlexibleDrawing -> Drawing lbl Gfx,
  FlexibleDrawing -> Drawing lbl Gfx)
 -> i -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> i -> F i (Tree leaf node)
treeBrowserF'' (FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> Tree leaf node -> Drawing (Either Bool (Tree leaf node)) Gfx
forall a a.
(Graphic a, Graphic a) =>
(FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
drawTree Tree leaf node
t

--treeBrowserF' ::Tree n l -> F (Tree n l) ([n],Maybe l)
treeBrowserF'' :: ((FlexibleDrawing -> Drawing lbl Gfx,
  FlexibleDrawing -> Drawing lbl Gfx)
 -> i -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> i -> F i (Tree leaf node)
treeBrowserF'' (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
-> i -> Drawing (Either Bool (Tree leaf node)) Gfx
drawTree i
t =
    GCtx
-> [GCAttributes String FontSpec]
-> (GCtx -> F i (Tree leaf node))
-> F i (Tree leaf node)
forall a1 (f :: * -> * -> *) a2 i o.
(ColorGen a1, FudgetIO f, FontGen a2, Show a1, Show a2) =>
GCtx -> [GCAttributes a1 a2] -> (GCtx -> f i o) -> f i o
wCreateGCtx GCtx
rootGCtx (String -> [GCAttributes String FontSpec]
forall c. c -> [GCAttributes c FontSpec]
gcFgA String
linecolor) ((GCtx -> F i (Tree leaf node)) -> F i (Tree leaf node))
-> (GCtx -> F i (Tree leaf node)) -> F i (Tree leaf node)
forall a b. (a -> b) -> a -> b
$ \ GCtx
lgc ->
    GCtx
-> [GCAttributes String FontSpec]
-> (GCtx -> F i (Tree leaf node))
-> F i (Tree leaf node)
forall a1 (f :: * -> * -> *) a2 i o.
(ColorGen a1, FudgetIO f, FontGen a2, Show a1, Show a2) =>
GCtx -> [GCAttributes a1 a2] -> (GCtx -> f i o) -> f i o
wCreateGCtx GCtx
rootGCtx (String -> [GCAttributes String FontSpec]
forall c. c -> [GCAttributes c FontSpec]
gcFgA String
paperColor) ((GCtx -> F i (Tree leaf node)) -> F i (Tree leaf node))
-> (GCtx -> F i (Tree leaf node)) -> F i (Tree leaf node)
forall a b. (a -> b) -> a -> b
$ \ GCtx
bggc ->
    ((FlexibleDrawing -> Drawing lbl Gfx,
  FlexibleDrawing -> Drawing lbl Gfx)
 -> i -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> (GCtx, GCtx) -> i -> F i (Tree leaf node)
forall node lbl lbl p leaf.
Graphic node =>
((FlexibleDrawing -> Drawing lbl Gfx,
  FlexibleDrawing -> Drawing lbl Gfx)
 -> p -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> (GCtx, GCtx) -> p -> F p (Tree leaf node)
treeBrowserF''' (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
-> i -> Drawing (Either Bool (Tree leaf node)) Gfx
drawTree (GCtx
bggc,GCtx
lgc) i
t


treeBrowserF''' :: ((FlexibleDrawing -> Drawing lbl Gfx,
  FlexibleDrawing -> Drawing lbl Gfx)
 -> p -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> (GCtx, GCtx) -> p -> F p (Tree leaf node)
treeBrowserF''' (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
-> p -> Drawing (Either Bool (Tree leaf node)) Gfx
drawTree gcs :: (GCtx, GCtx)
gcs@(GCtx
bggc,GCtx
lgc) p
t =
   F (Either (GfxEvent [Int]) p)
  (Either
     (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
     (Tree leaf node))
-> F (GfxCommand
        [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
     (GfxEvent [Int])
-> F p (Tree leaf node)
forall a b c d. F (Either a b) (Either c d) -> F c a -> F b d
loopThroughRightF ((Either (GfxEvent [Int]) p
 -> ReactionM
      (Drawing (Either Bool (Tree leaf node)) Gfx)
      (Either
         (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
         (Tree leaf node))
      ())
-> Drawing (Either Bool (Tree leaf node)) Gfx
-> F (Either (GfxEvent [Int]) p)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
forall a t b a2. (a -> ReactionM t b a2) -> t -> F a b
R.reactiveF Either (GfxEvent [Int]) p
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
     ()
ctrl Drawing (Either Bool (Tree leaf node)) Gfx
d0) (Customiser (GraphicsF (Drawing (Either Bool (Tree leaf node)) Gfx))
-> F (GfxCommand
        [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
     (GfxEvent [Int])
forall gfx.
Graphic gfx =>
Customiser (GraphicsF gfx) -> F (GfxFCmd gfx) (GfxEvent [Int])
graphicsDispF' Customiser (GraphicsF (Drawing (Either Bool (Tree leaf node)) Gfx))
pm)
  where
    pm1 :: Graphic a => Customiser (GraphicsF a)
    pm1 :: Customiser (GraphicsF a)
pm1 = String -> Customiser (GraphicsF a)
forall xxx a.
(HasBgColorSpec xxx, Show a, ColorGen a) =>
a -> Customiser xxx
setBgColor String
bgColor Customiser (GraphicsF a)
-> Customiser (GraphicsF a) -> Customiser (GraphicsF a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sizing -> Customiser (GraphicsF a)
forall xxx. HasSizing xxx => Sizing -> Customiser xxx
setSizing Sizing
Dynamic
    pm :: Customiser (GraphicsF (Drawing (Either Bool (Tree leaf node)) Gfx))
pm = Customiser (GraphicsF (Drawing (Either Bool (Tree leaf node)) Gfx))
forall a. Graphic a => Customiser (GraphicsF a)
pm1 Customiser (GraphicsF (Drawing (Either Bool (Tree leaf node)) Gfx))
-> Customiser
     (GraphicsF (Drawing (Either Bool (Tree leaf node)) Gfx))
-> Customiser
     (GraphicsF (Drawing (Either Bool (Tree leaf node)) Gfx))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Drawing (Either Bool (Tree leaf node)) Gfx
-> Customiser
     (GraphicsF (Drawing (Either Bool (Tree leaf node)) Gfx))
forall (xxx :: * -> *) a.
HasInitDisp xxx =>
a -> Customiser (xxx a)
setInitDisp Drawing (Either Bool (Tree leaf node)) Gfx
d0
    d0 :: Drawing (Either Bool (Tree leaf node)) Gfx
d0 = (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
-> p -> Drawing (Either Bool (Tree leaf node)) Gfx
drawTree (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
forall lbl lbl.
(FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
gs p
t
    ctrl :: Either (GfxEvent [Int]) p
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
     ()
ctrl = (GfxEvent [Int]
 -> ReactionM
      (Drawing (Either Bool (Tree leaf node)) Gfx)
      (Either
         (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
         (Tree leaf node))
      ())
-> (p
    -> ReactionM
         (Drawing (Either Bool (Tree leaf node)) Gfx)
         (Either
            (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
            (Tree leaf node))
         ())
-> Either (GfxEvent [Int]) p
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
     ()
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either GfxEvent [Int]
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
     ()
forall node leaf.
Graphic node =>
GfxEvent [Int]
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
     ()
fromLoop p
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
     ()
forall a b.
p
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
     ()
fromOutside
      where
	fromOutside :: p
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
     ()
fromOutside p
t = do let d :: Drawing (Either Bool (Tree leaf node)) Gfx
d = (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
-> p -> Drawing (Either Bool (Tree leaf node)) Gfx
drawTree (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
forall lbl lbl.
(FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
gs p
t 
			   Drawing (Either Bool (Tree leaf node)) Gfx
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
     ()
forall s o. s -> ReactionM s o ()
R.set Drawing (Either Bool (Tree leaf node)) Gfx
d
			   Either
  (GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)) b
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
     ()
forall a1 a2. a1 -> ReactionM a2 a1 ()
R.put (GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)
-> Either
     (GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)) b
forall a b. a -> Either a b
toLoop (GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)
 -> Either
      (GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
-> GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)
-> Either
     (GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)) b
forall a b. (a -> b) -> a -> b
$ Drawing (Either Bool (Tree leaf node)) Gfx
-> GfxCommand [a] (Drawing (Either Bool (Tree leaf node)) Gfx)
forall gfx a. gfx -> GfxCommand [a] gfx
replaceAllGfx Drawing (Either Bool (Tree leaf node)) Gfx
d)

	fromLoop :: GfxEvent [Int]
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
     ()
fromLoop GfxEvent [Int]
gfxevent =
	  do ([Int]
path,Either Bool (Tree leaf node)
lbl) <- GfxEvent [Int]
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
     ([Int], Either Bool (Tree leaf node))
forall b leaf o.
GfxEvent [Int] -> ReactionM (Drawing b leaf) o ([Int], b)
clickedpart GfxEvent [Int]
gfxevent
	     case Either Bool (Tree leaf node)
lbl of
	       Left Bool
vis -> [Int]
-> Bool
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
     ()
forall node leaf b.
Graphic node =>
[Int]
-> Bool
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
     ()
toggle [Int]
path (Bool -> Bool
not Bool
vis)
	       Right Tree leaf node
part -> Either
  (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
  (Tree leaf node)
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
        (Tree leaf node))
     ()
forall a1 a2. a1 -> ReactionM a2 a1 ()
R.put (Tree leaf node
-> Either
     (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx))
     (Tree leaf node)
forall b a. b -> Either a b
toOutside Tree leaf node
part)

	toggle :: [Int]
-> Bool
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
     ()
toggle [Int]
path Bool
vis =
	  do ([Int]
ppath,LabelD rt :: Either Bool (Tree leaf node)
rt@(Right (Node node
n [Tree leaf node]
_))
	                   (ComposedD Int
_ (Drawing (Either Bool (Tree leaf node)) Gfx
_:[Drawing (Either Bool (Tree leaf node)) Gfx]
ds))) <- [Int]
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
     ([Int], Drawing (Either Bool (Tree leaf node)) Gfx)
forall b leaf o.
[Int] -> ReactionM (Drawing b leaf) o ([Int], Drawing b leaf)
parentpathpart [Int]
path
	     let td' :: Drawing (Either Bool (Tree leaf node)) Gfx
td' = Either Bool (Tree leaf node)
-> Drawing (Either Bool (Tree leaf node)) Gfx
-> Drawing (Either Bool (Tree leaf node)) Gfx
forall lbl leaf. lbl -> Drawing lbl leaf -> Drawing lbl leaf
LabelD Either Bool (Tree leaf node)
rt ((FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> Bool
-> node
-> [Drawing (Either Bool (Tree leaf node)) Gfx]
-> Drawing (Either Bool (Tree leaf node)) Gfx
forall a b.
Graphic a =>
(FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
-> Bool
-> a
-> [Drawing (Either Bool b) Gfx]
-> Drawing (Either Bool b) Gfx
nodeD (FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree leaf node)) Gfx)
forall lbl lbl.
(FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
gs Bool
vis node
n [Drawing (Either Bool (Tree leaf node)) Gfx]
ds)
	     (Drawing (Either Bool (Tree leaf node)) Gfx
 -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
     ()
forall t o. (t -> t) -> ReactionM t o ()
R.update ((Drawing (Either Bool (Tree leaf node)) Gfx
  -> Drawing (Either Bool (Tree leaf node)) Gfx)
 -> ReactionM
      (Drawing (Either Bool (Tree leaf node)) Gfx)
      (Either
         (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
      ())
-> (Drawing (Either Bool (Tree leaf node)) Gfx
    -> Drawing (Either Bool (Tree leaf node)) Gfx)
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
     ()
forall a b. (a -> b) -> a -> b
$ \ Drawing (Either Bool (Tree leaf node)) Gfx
d -> Drawing (Either Bool (Tree leaf node)) Gfx
-> [Int]
-> Drawing (Either Bool (Tree leaf node)) Gfx
-> Drawing (Either Bool (Tree leaf node)) Gfx
forall lbl leaf.
Drawing lbl leaf -> [Int] -> Drawing lbl leaf -> Drawing lbl leaf
replacePart Drawing (Either Bool (Tree leaf node)) Gfx
d [Int]
ppath Drawing (Either Bool (Tree leaf node)) Gfx
td'
	     Either
  (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b
-> ReactionM
     (Drawing (Either Bool (Tree leaf node)) Gfx)
     (Either
        (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
     ()
forall a1 a2. a1 -> ReactionM a2 a1 ()
R.put (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)
-> Either
     (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b
forall a b. a -> Either a b
toLoop (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)
 -> Either
      (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b)
-> GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)
-> Either
     (GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)) b
forall a b. (a -> b) -> a -> b
$ [Int]
-> Drawing (Either Bool (Tree leaf node)) Gfx
-> GfxCommand [Int] (Drawing (Either Bool (Tree leaf node)) Gfx)
forall path gfx. path -> gfx -> GfxCommand path gfx
replaceGfx [Int]
ppath Drawing (Either Bool (Tree leaf node)) Gfx
td')

    toLoop :: a -> Either a b
toLoop = a -> Either a b
forall a b. a -> Either a b
Left
    toOutside :: b -> Either a b
toOutside = b -> Either a b
forall a b. b -> Either a b
Right

    --gd = softAttribD [GCLineStyle LineOnOffDash] . g
    --gd x = g x
    gl :: FlexibleDrawing -> Drawing lbl Gfx
gl = GCtx -> Drawing lbl Gfx -> Drawing lbl Gfx
forall lbl leaf. GCtx -> Drawing lbl leaf -> Drawing lbl leaf
hardAttribD GCtx
lgc (Drawing lbl Gfx -> Drawing lbl Gfx)
-> (FlexibleDrawing -> Drawing lbl Gfx)
-> FlexibleDrawing
-> Drawing lbl Gfx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlexibleDrawing -> Drawing lbl Gfx
forall a lbl. Graphic a => a -> Drawing lbl Gfx
g
    gbg :: FlexibleDrawing -> Drawing lbl Gfx
gbg = GCtx -> Drawing lbl Gfx -> Drawing lbl Gfx
forall lbl leaf. GCtx -> Drawing lbl leaf -> Drawing lbl leaf
hardAttribD GCtx
bggc (Drawing lbl Gfx -> Drawing lbl Gfx)
-> (FlexibleDrawing -> Drawing lbl Gfx)
-> FlexibleDrawing
-> Drawing lbl Gfx
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlexibleDrawing -> Drawing lbl Gfx
forall a lbl. Graphic a => a -> Drawing lbl Gfx
g
    gs :: (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
gs = (FlexibleDrawing -> Drawing lbl Gfx
forall lbl. FlexibleDrawing -> Drawing lbl Gfx
gbg,FlexibleDrawing -> Drawing lbl Gfx
forall lbl. FlexibleDrawing -> Drawing lbl Gfx
gl)

clickedpart :: GfxEvent [Int] -> ReactionM (Drawing b leaf) o ([Int], b)
clickedpart GfxEvent [Int]
gfxevent =
  case GfxEvent [Int]
gfxevent of
    GfxButtonEvent{gfxType :: forall path. GfxEvent path -> Pressed
gfxType=Pressed
Pressed, gfxPaths :: forall path. GfxEvent path -> [(path, (Point, Rect))]
gfxPaths=([Int]
path,(Point, Rect)
_):[([Int], (Point, Rect))]
_} -> [Int] -> ReactionM (Drawing b leaf) o ([Int], b)
forall b leaf o. [Int] -> ReactionM (Drawing b leaf) o ([Int], b)
pathlbl [Int]
path
    GfxEvent [Int]
_ -> ReactionM (Drawing b leaf) o ([Int], b)
forall s o a. ReactionM s o a
R.rfail

pathlbl :: [Int] -> ReactionM (Drawing b leaf) o ([Int], b)
pathlbl [Int]
path =
  do ([Int]
lpath,LabelD b
lbl Drawing b leaf
_) <- [Int] -> ReactionM (Drawing b leaf) o ([Int], Drawing b leaf)
forall b leaf o.
[Int] -> ReactionM (Drawing b leaf) o ([Int], Drawing b leaf)
pathpart [Int]
path
     ([Int], b) -> ReactionM (Drawing b leaf) o ([Int], b)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Int]
lpath,b
lbl)

pathpart :: [Int] -> ReactionM (Drawing b leaf) o ([Int], Drawing b leaf)
pathpart [Int]
path =
  do Drawing b leaf
drawing <- ReactionM (Drawing b leaf) o (Drawing b leaf)
forall a o. ReactionM a o a
R.get
     let lpath :: [Int]
lpath = Drawing b leaf -> [Int] -> [Int]
forall b leaf. Drawing b leaf -> [Int] -> [Int]
drawingAnnotPart Drawing b leaf
drawing [Int]
path
     Drawing b leaf
part <- Maybe (Drawing b leaf)
-> ReactionM (Drawing b leaf) o (Drawing b leaf)
forall a s o. Maybe a -> ReactionM s o a
R.lift (Maybe (Drawing b leaf)
 -> ReactionM (Drawing b leaf) o (Drawing b leaf))
-> Maybe (Drawing b leaf)
-> ReactionM (Drawing b leaf) o (Drawing b leaf)
forall a b. (a -> b) -> a -> b
$ Drawing b leaf -> [Int] -> Maybe (Drawing b leaf)
forall lbl leaf.
Drawing lbl leaf -> [Int] -> Maybe (Drawing lbl leaf)
maybeDrawingPart Drawing b leaf
drawing [Int]
lpath
     ([Int], Drawing b leaf)
-> ReactionM (Drawing b leaf) o ([Int], Drawing b leaf)
forall (m :: * -> *) a. Monad m => a -> m a
return ([Int]
lpath,Drawing b leaf
part)

parentpathpart :: [Int] -> ReactionM (Drawing b leaf) o ([Int], Drawing b leaf)
parentpathpart = [Int] -> ReactionM (Drawing b leaf) o ([Int], Drawing b leaf)
forall b leaf o.
[Int] -> ReactionM (Drawing b leaf) o ([Int], Drawing b leaf)
pathpart ([Int] -> ReactionM (Drawing b leaf) o ([Int], Drawing b leaf))
-> ([Int] -> [Int])
-> [Int]
-> ReactionM (Drawing b leaf) o ([Int], Drawing b leaf)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> [Int]
up

drawStaticTree :: (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
drawStaticTree (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
gs Tree a a
t = Placer
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall lbl leaf. Placer -> Drawing lbl leaf -> Drawing lbl leaf
placedD (Int -> Placer
verticalLeftP' Int
0) (Drawing (Either Bool (Tree a a)) Gfx
 -> Drawing (Either Bool (Tree a a)) Gfx)
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall a b. (a -> b) -> a -> b
$ (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Maybe Integer
-> Tree a a
-> Drawing (Either Bool (Tree a a)) Gfx
forall a a b.
(Graphic a, Graphic a, Ord b, Num b) =>
(FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Maybe b -> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
drawTree' (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
gs Maybe Integer
forall a. Maybe a
Nothing Tree a a
t
drawTree :: (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
drawTree (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
gs Tree a a
t = Placer
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall lbl leaf. Placer -> Drawing lbl leaf -> Drawing lbl leaf
placedD (Int -> Placer
verticalLeftP' Int
0) (Drawing (Either Bool (Tree a a)) Gfx
 -> Drawing (Either Bool (Tree a a)) Gfx)
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall a b. (a -> b) -> a -> b
$ (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Maybe Int -> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
forall a a b.
(Graphic a, Graphic a, Ord b, Num b) =>
(FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Maybe b -> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
drawTree' (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
gs Maybe Int
opendepthlimit Tree a a
t

staticNodeD :: (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
-> a -> [Drawing lbl Gfx] -> Drawing lbl Gfx
staticNodeD (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
gs a
n [Drawing lbl Gfx]
ds = [Drawing lbl Gfx] -> Drawing lbl Gfx
forall lbl leaf. [Drawing lbl leaf] -> Drawing lbl leaf
boxD (Int -> [Drawing lbl Gfx] -> Drawing lbl Gfx
forall lbl leaf. Int -> [Drawing lbl leaf] -> Drawing lbl leaf
hboxD' Int
0 [Int
-> (FlexibleDrawing -> Drawing lbl Gfx,
    FlexibleDrawing -> Drawing lbl Gfx)
-> Drawing lbl Gfx
-> Drawing lbl Gfx
forall lbl leaf.
Int
-> (FlexibleDrawing -> Drawing lbl leaf,
    FlexibleDrawing -> Drawing lbl leaf)
-> Drawing lbl leaf
-> Drawing lbl leaf
sframeD Int
3 (FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
gs (a -> Drawing lbl Gfx
forall a lbl. Graphic a => a -> Drawing lbl Gfx
g a
n)]Drawing lbl Gfx -> [Drawing lbl Gfx] -> [Drawing lbl Gfx]
forall a. a -> [a] -> [a]
:[Drawing lbl Gfx]
ds)

nodeD :: (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
-> Bool
-> a
-> [Drawing (Either Bool b) Gfx]
-> Drawing (Either Bool b) Gfx
nodeD gs :: (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
gs@(FlexibleDrawing -> Drawing (Either Bool b) Gfx
gbg,FlexibleDrawing -> Drawing (Either Bool b) Gfx
gl) Bool
vis a
n [Drawing (Either Bool b) Gfx]
ds =
    Int -> [Drawing (Either Bool b) Gfx] -> Drawing (Either Bool b) Gfx
forall lbl leaf. Int -> [Drawing lbl leaf] -> Drawing lbl leaf
boxVisibleD Int
vcnt (Int -> [Drawing (Either Bool b) Gfx] -> Drawing (Either Bool b) Gfx
forall lbl leaf. Int -> [Drawing lbl leaf] -> Drawing lbl leaf
hboxD' Int
0 [Int
-> (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
    FlexibleDrawing -> Drawing (Either Bool b) Gfx)
-> Drawing (Either Bool b) Gfx
-> Drawing (Either Bool b) Gfx
forall lbl leaf.
Int
-> (FlexibleDrawing -> Drawing lbl leaf,
    FlexibleDrawing -> Drawing lbl leaf)
-> Drawing lbl leaf
-> Drawing lbl leaf
sframeD Int
3 (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
gs (a -> Drawing (Either Bool b) Gfx
forall a lbl. Graphic a => a -> Drawing lbl Gfx
g a
n),FlexibleDrawing -> Drawing (Either Bool b) Gfx
gl FlexibleDrawing
hLineFD,Drawing (Either Bool b) Gfx
markD]Drawing (Either Bool b) Gfx
-> [Drawing (Either Bool b) Gfx] -> [Drawing (Either Bool b) Gfx]
forall a. a -> [a] -> [a]
:[Drawing (Either Bool b) Gfx]
ds)
  where
    vcnt :: Int
vcnt = Int
1Int -> Int -> Int
forall a. Num a => a -> a -> a
+(if Bool
vis then [Drawing (Either Bool b) Gfx] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Drawing (Either Bool b) Gfx]
ds else Int
0)
    markD :: Drawing (Either Bool b) Gfx
markD = Either Bool b
-> Drawing (Either Bool b) Gfx -> Drawing (Either Bool b) Gfx
forall lbl leaf. lbl -> Drawing lbl leaf -> Drawing lbl leaf
labelD (Bool -> Either Bool b
forall a b. a -> Either a b
Left Bool
vis) (Drawing (Either Bool b) Gfx -> Drawing (Either Bool b) Gfx)
-> Drawing (Either Bool b) Gfx -> Drawing (Either Bool b) Gfx
forall a b. (a -> b) -> a -> b
$ Drawing (Either Bool b) Gfx -> Drawing (Either Bool b) Gfx
circleD (if Bool
vis then String -> Drawing (Either Bool b) Gfx
forall a lbl. Graphic a => a -> Drawing lbl Gfx
g String
"-" else String -> Drawing (Either Bool b) Gfx
forall a lbl. Graphic a => a -> Drawing lbl Gfx
g String
"+")

    circleD :: Drawing (Either Bool b) Gfx -> Drawing (Either Bool b) Gfx
circleD Drawing (Either Bool b) Gfx
d =
        Spacer
-> Drawing (Either Bool b) Gfx -> Drawing (Either Bool b) Gfx
forall lbl leaf. Spacer -> Drawing lbl leaf -> Drawing lbl leaf
spacedD Spacer
centerS (Drawing (Either Bool b) Gfx -> Drawing (Either Bool b) Gfx)
-> Drawing (Either Bool b) Gfx -> Drawing (Either Bool b) Gfx
forall a b. (a -> b) -> a -> b
$
	[Drawing (Either Bool b) Gfx] -> Drawing (Either Bool b) Gfx
forall lbl leaf. [Drawing lbl leaf] -> Drawing lbl leaf
stackD [FlexibleDrawing -> Drawing (Either Bool b) Gfx
gbg FlexibleDrawing
filledEllipse,FlexibleDrawing -> Drawing (Either Bool b) Gfx
gl FlexibleDrawing
ellipse,Spacer
-> Drawing (Either Bool b) Gfx -> Drawing (Either Bool b) Gfx
forall lbl leaf. Spacer -> Drawing lbl leaf -> Drawing lbl leaf
spacedD Spacer
sqpadS Drawing (Either Bool b) Gfx
d]
      where sqpadS :: Spacer
sqpadS  = (Point -> Point) -> Spacer
resizeS Point -> Point
sq Spacer -> Spacer -> Spacer
`compS` Spacer
centerS
	    sq :: Point -> Point
sq (Point Int
w Int
h) = Int -> Int -> Point
Point Int
m Int
m where m :: Int
m = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
w Int
h

sframeD :: Int
-> (FlexibleDrawing -> Drawing lbl leaf,
    FlexibleDrawing -> Drawing lbl leaf)
-> Drawing lbl leaf
-> Drawing lbl leaf
sframeD Int
sep (FlexibleDrawing -> Drawing lbl leaf,
 FlexibleDrawing -> Drawing lbl leaf)
gs Drawing lbl leaf
d = Spacer -> Drawing lbl leaf -> Drawing lbl leaf
forall lbl leaf. Spacer -> Drawing lbl leaf -> Drawing lbl leaf
spacedD (Int -> Int -> Spacer
vMarginS Int
sep Int
0) (Drawing lbl leaf -> Drawing lbl leaf)
-> Drawing lbl leaf -> Drawing lbl leaf
forall a b. (a -> b) -> a -> b
$ (FlexibleDrawing -> Drawing lbl leaf,
 FlexibleDrawing -> Drawing lbl leaf)
-> Drawing lbl leaf -> Drawing lbl leaf
forall lbl leaf.
(FlexibleDrawing -> Drawing lbl leaf,
 FlexibleDrawing -> Drawing lbl leaf)
-> Drawing lbl leaf -> Drawing lbl leaf
frameD (FlexibleDrawing -> Drawing lbl leaf,
 FlexibleDrawing -> Drawing lbl leaf)
gs Drawing lbl leaf
d

frameD :: (FlexibleDrawing -> Drawing lbl leaf,
 FlexibleDrawing -> Drawing lbl leaf)
-> Drawing lbl leaf -> Drawing lbl leaf
frameD (FlexibleDrawing -> Drawing lbl leaf
gbg,FlexibleDrawing -> Drawing lbl leaf
gl) Drawing lbl leaf
d =
   [Drawing lbl leaf] -> Drawing lbl leaf
forall lbl leaf. [Drawing lbl leaf] -> Drawing lbl leaf
stackD [FlexibleDrawing -> Drawing lbl leaf
gbg (FlexibleDrawing -> Drawing lbl leaf)
-> FlexibleDrawing -> Drawing lbl leaf
forall a b. (a -> b) -> a -> b
$ Bool -> Bool -> Int -> FlexibleDrawing
filler Bool
False Bool
False Int
1,FlexibleDrawing -> Drawing lbl leaf
gl FlexibleDrawing
frame,Int -> Drawing lbl leaf -> Drawing lbl leaf
forall lbl leaf. Int -> Drawing lbl leaf -> Drawing lbl leaf
padD Int
2 Drawing lbl leaf
d]


nodeD' :: (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
-> Maybe a
-> a
-> [Drawing (Either Bool b) Gfx]
-> Drawing (Either Bool b) Gfx
nodeD' (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
gs Maybe a
Nothing = (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
-> a
-> [Drawing (Either Bool b) Gfx]
-> Drawing (Either Bool b) Gfx
forall a lbl.
Graphic a =>
(FlexibleDrawing -> Drawing lbl Gfx,
 FlexibleDrawing -> Drawing lbl Gfx)
-> a -> [Drawing lbl Gfx] -> Drawing lbl Gfx
staticNodeD (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
gs
nodeD' (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
gs (Just a
d) = (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
-> Bool
-> a
-> [Drawing (Either Bool b) Gfx]
-> Drawing (Either Bool b) Gfx
forall a b.
Graphic a =>
(FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
-> Bool
-> a
-> [Drawing (Either Bool b) Gfx]
-> Drawing (Either Bool b) Gfx
nodeD (FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
gs (a
da -> a -> Bool
forall a. Ord a => a -> a -> Bool
>a
0)

drawTree' :: (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Maybe b -> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
drawTree' gs :: (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
gs@(FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx
_,FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx
gl) Maybe b
depth Tree a a
t =
    Spacer
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall lbl leaf. Spacer -> Drawing lbl leaf -> Drawing lbl leaf
spacedD Spacer
leftS (Drawing (Either Bool (Tree a a)) Gfx
 -> Drawing (Either Bool (Tree a a)) Gfx)
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall a b. (a -> b) -> a -> b
$
    Either Bool (Tree a a)
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall lbl leaf. lbl -> Drawing lbl leaf -> Drawing lbl leaf
labelD (Tree a a -> Either Bool (Tree a a)
forall a b. b -> Either a b
Right Tree a a
t) (Drawing (Either Bool (Tree a a)) Gfx
 -> Drawing (Either Bool (Tree a a)) Gfx)
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall a b. (a -> b) -> a -> b
$
    case Tree a a
t of
      Leaf a
l -> --hboxD' 0 [gl hLineFD,frameD gs $ g l]
		Int
-> (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
    FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall lbl leaf.
Int
-> (FlexibleDrawing -> Drawing lbl leaf,
    FlexibleDrawing -> Drawing lbl leaf)
-> Drawing lbl leaf
-> Drawing lbl leaf
sframeD Int
1 (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
gs (Drawing (Either Bool (Tree a a)) Gfx
 -> Drawing (Either Bool (Tree a a)) Gfx)
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall a b. (a -> b) -> a -> b
$ a -> Drawing (Either Bool (Tree a a)) Gfx
forall a lbl. Graphic a => a -> Drawing lbl Gfx
g a
l
      Node a
n [Tree a a]
ts -> (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Maybe b
-> a
-> [Drawing (Either Bool (Tree a a)) Gfx]
-> Drawing (Either Bool (Tree a a)) Gfx
forall a a b.
(Graphic a, Ord a, Num a) =>
(FlexibleDrawing -> Drawing (Either Bool b) Gfx,
 FlexibleDrawing -> Drawing (Either Bool b) Gfx)
-> Maybe a
-> a
-> [Drawing (Either Bool b) Gfx]
-> Drawing (Either Bool b) Gfx
nodeD' (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
gs Maybe b
depth a
n [(FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Maybe b -> [Tree a a] -> Drawing (Either Bool (Tree a a)) Gfx
drawTrees (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
gs ((b -> b) -> Maybe b -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (b -> b -> b
forall a. Num a => a -> a -> a
+(-b
1)) Maybe b
depth) [Tree a a]
ts]

drawTrees :: (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Maybe b -> [Tree a a] -> Drawing (Either Bool (Tree a a)) Gfx
drawTrees gs :: (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
gs@(FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx
_,FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx
gl) Maybe b
depth [Tree a a]
ts = Int
-> [Drawing (Either Bool (Tree a a)) Gfx]
-> Drawing (Either Bool (Tree a a)) Gfx
forall lbl leaf. Int -> [Drawing lbl leaf] -> Drawing lbl leaf
vboxlD' Int
0 ([Drawing (Either Bool (Tree a a)) Gfx]
 -> Drawing (Either Bool (Tree a a)) Gfx)
-> [Drawing (Either Bool (Tree a a)) Gfx]
-> Drawing (Either Bool (Tree a a)) Gfx
forall a b. (a -> b) -> a -> b
$ (Int -> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx)
-> [Int] -> [Tree a a] -> [Drawing (Either Bool (Tree a a)) Gfx]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Int -> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
forall a.
(Eq a, Num a) =>
a -> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
drawSubTree [Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1,Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
2..Int
0] [Tree a a]
ts
  where
    n :: Int
n = [Tree a a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Tree a a]
ts
    drawSubTree :: a -> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
drawSubTree a
i Tree a a
t = Placer
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall lbl leaf. Placer -> Drawing lbl leaf -> Drawing lbl leaf
placedD (Int -> LayoutDir -> Int -> Placer
tableP' Int
2 LayoutDir
Vertical Int
0) (Drawing (Either Bool (Tree a a)) Gfx
 -> Drawing (Either Bool (Tree a a)) Gfx)
-> Drawing (Either Bool (Tree a a)) Gfx
-> Drawing (Either Bool (Tree a a)) Gfx
forall a b. (a -> b) -> a -> b
$
		      [Drawing (Either Bool (Tree a a)) Gfx]
-> Drawing (Either Bool (Tree a a)) Gfx
forall lbl leaf. [Drawing lbl leaf] -> Drawing lbl leaf
boxD [a -> Drawing (Either Bool (Tree a a)) Gfx
forall a.
(Eq a, Num a) =>
a -> Drawing (Either Bool (Tree a a)) Gfx
fork a
i,a -> Drawing (Either Bool (Tree a a)) Gfx
forall a.
(Eq a, Num a) =>
a -> Drawing (Either Bool (Tree a a)) Gfx
line a
i,(FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
-> Maybe b -> Tree a a -> Drawing (Either Bool (Tree a a)) Gfx
drawTree' (FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx,
 FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx)
gs Maybe b
depth Tree a a
t]
    --drawSubTree i t = hboxD' 0 [fork i,drawTree' gs depth t]
    fork :: a -> Drawing (Either Bool (Tree a a)) Gfx
fork a
0 = FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx
gl FlexibleDrawing
lowerRightFD
    fork a
_ = FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx
gl FlexibleDrawing
forkRightFD
    line :: a -> Drawing (Either Bool (Tree a a)) Gfx
line a
0 = Point -> Drawing (Either Bool (Tree a a)) Gfx
forall lbl. Point -> Drawing lbl Gfx
blankD Point
0
    line a
_ = FlexibleDrawing -> Drawing (Either Bool (Tree a a)) Gfx
gl FlexibleDrawing
vLineFD


---

lowerRightFD :: FlexibleDrawing
lowerRightFD = Point -> (Rect -> [DrawCommand]) -> FlexibleDrawing
flex' (Int -> Int -> Point
pP Int
14 Int
10) Rect -> [DrawCommand]
f
  where f :: Rect -> [DrawCommand]
f (Rect Point
p Point
s) =
	    [CoordMode -> [Point] -> DrawCommand
DrawLines CoordMode
CoordModePrevious [Point
pPoint -> Point -> Point
forall a. Num a => a -> a -> a
+Int -> Int -> Point
pP Int
mw Int
0,Int -> Int -> Point
pP Int
0 Int
mh,Int -> Int -> Point
pP Int
mw Int
0]]
	  where Point Int
mw Int
mh = Rect -> Point
rectMiddle (Point -> Point -> Rect
Rect Point
0 Point
s)

forkRightFD :: FlexibleDrawing
forkRightFD = Point -> (Rect -> [DrawCommand]) -> FlexibleDrawing
flex' (Int -> Int -> Point
pP Int
14 Int
10) Rect -> [DrawCommand]
f
  where f :: Rect -> [DrawCommand]
f (Rect Point
p s :: Point
s@(Point Int
w Int
h)) =
	    [Line -> DrawCommand
DrawLine (Point -> Point -> Line
Line (Point
pPoint -> Point -> Point
forall a. Num a => a -> a -> a
+Int -> Int -> Point
pP Int
mw Int
0) (Point
pPoint -> Point -> Point
forall a. Num a => a -> a -> a
+Int -> Int -> Point
pP Int
mw Int
h)),
	     Line -> DrawCommand
DrawLine (Point -> Point -> Line
Line (Point
pPoint -> Point -> Point
forall a. Num a => a -> a -> a
+Point
m) (Point
pPoint -> Point -> Point
forall a. Num a => a -> a -> a
+Int -> Int -> Point
pP Int
w Int
mh))]
	  where m :: Point
m@(Point Int
mw Int
mh) = Rect -> Point
rectMiddle (Point -> Point -> Rect
Rect Point
0 Point
s)

vLineFD :: FlexibleDrawing
vLineFD = Point -> (Rect -> [DrawCommand]) -> FlexibleDrawing
flex' (Int -> Int -> Point
pP Int
10 Int
1) Rect -> [DrawCommand]
f
  where f :: Rect -> [DrawCommand]
f (Rect Point
p s :: Point
s@(Point Int
_ Int
h)) = [Line -> DrawCommand
DrawLine (Point -> Point -> Line
Line (Point
pPoint -> Point -> Point
forall a. Num a => a -> a -> a
+Int -> Int -> Point
pP Int
mw Int
0) (Point
pPoint -> Point -> Point
forall a. Num a => a -> a -> a
+Int -> Int -> Point
pP Int
mw Int
h))]
	  where Point Int
mw Int
_ = Rect -> Point
rectMiddle (Point -> Point -> Rect
Rect Point
0 Point
s)

hLineFD :: FlexibleDrawing
hLineFD = Point -> (Rect -> [DrawCommand]) -> FlexibleDrawing
flex' Point
10 Rect -> [DrawCommand]
f
  where f :: Rect -> [DrawCommand]
f (Rect Point
p s :: Point
s@(Point Int
w Int
_)) = [Line -> DrawCommand
DrawLine (Point -> Point -> Line
Line (Point
pPoint -> Point -> Point
forall a. Num a => a -> a -> a
+Int -> Int -> Point
pP Int
0 Int
mh) (Point
pPoint -> Point -> Point
forall a. Num a => a -> a -> a
+Int -> Int -> Point
pP Int
w Int
mh))]
	  where Point Int
_ Int
mh = Rect -> Point
rectMiddle (Point -> Point -> Rect
Rect Point
0 Point
s)

linecolor :: String
linecolor = String -> ShowS
argKey String
"linecolor" String
"blue"
opendepthlimit :: Maybe Int
opendepthlimit = String -> Maybe Int -> Maybe Int
forall p. (Read p, Show p) => String -> p -> p
argReadKey String
"opendepthlimit" (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
opendepth) -- not a good name
opendepth :: Int
opendepth = String -> Int -> Int
forall p. (Read p, Show p) => String -> p -> p
argReadKey String
"opendepth" Int
1::Int