Implement simple indenting in selection menu

This commit is contained in:
2024-09-12 18:14:52 +01:00
parent 4dedba8d30
commit e69abf1715
8 changed files with 226 additions and 217 deletions
+36
View File
@@ -2,6 +2,9 @@ module Dodge.DoubleTree where
import Dodge.Data.DoubleTree
ldtToDT :: LabelDoubleTree b a -> DoubleTree a
ldtToDT (LDT x l r) = DT x (map (ldtToDT . snd) l) (map (ldtToDT . snd) r)
-- conceptually, in a tree growing from left to right,
-- bottom -> top is equated with left -> right.
-- this does not match with thinking of a list as top -> bottom, so take care
@@ -15,6 +18,30 @@ dtIL nt (DT x l r) = map doindent (concat (headMap (dtIL DTBottomNode) (dtIL DTM
where
doindent (a,b,c) = (a,b+1,c)
ldtToIndentList :: LabelDoubleTree b a -> [(a,Int,LabelDoubleTreeNodeType b)]
ldtToIndentList = ldtIL LDTRootNode
ldtIL :: LabelDoubleTreeNodeType b -> LabelDoubleTree b a -> [(a,Int,LabelDoubleTreeNodeType b)]
ldtIL nt (LDT x l r) = map doindent
(concat
(headMap
(\(lab,c) -> ldtIL (LDTBottomNode lab) c)
(\(lab,c) -> ldtIL (LDTMidBelowNode lab) c)
l
)
)
++ [(x,0,nt)]
++ map doindent
(concat
(lastMap
(\(lab,c) -> ldtIL (LDTTopNode lab) c)
(\(lab,c) -> ldtIL (LDTMidAboveNode lab) c)
r
)
)
where
doindent (a,b,c) = (a,b+1,c)
headMap :: (a -> b) -> (a -> b) -> [a] -> [b]
headMap f g (x:xs) = f x : map g xs
headMap _ _ [] = []
@@ -24,3 +51,12 @@ lastMap _ _ [] = []
lastMap f _ (x:[]) = [f x]
lastMap f g (x:xs) = g x : lastMap f g xs
prettyDT :: (a -> String) -> DoubleTree a -> [String]
prettyDT f (DT x l r) = concatMap (map ('/':) . prettyDT f) r
++ (f x : concatMap (map ('\\':) . prettyDT f) l)
prettyLDT :: (a -> String) -> LabelDoubleTree b a -> [String]
prettyLDT f (LDT x l r) = concatMap (map ('/':) . prettyLDT f . snd) r
++ (f x : concatMap (map ('\\':) . prettyLDT f . snd) l)