mirror of
https://github.com/rgleichman/glance.git
synced 2024-09-11 15:05:41 +03:00
Add diagram for guard icon.
This commit is contained in:
parent
954e7c5829
commit
41df0fd9eb
36
app/Icons.hs
36
app/Icons.hs
@ -11,7 +11,8 @@ module Icons
|
||||
textBox,
|
||||
enclosure,
|
||||
lambdaRegion,
|
||||
resultIcon
|
||||
resultIcon,
|
||||
guardIcon,
|
||||
) where
|
||||
|
||||
import Diagrams.Prelude
|
||||
@ -52,8 +53,12 @@ connectMaybePorts icon0 (Just port0) icon1 Nothing =
|
||||
connectMaybePorts icon0 Nothing icon1 Nothing =
|
||||
connectOutside' arrowOptions icon0 icon1
|
||||
|
||||
-- | Make an port with an integer name. Always use <> to add a ports (not === or |||)
|
||||
--- since mempty has no size and will not be placed where you want it.
|
||||
makePort :: Int -> Diagram B
|
||||
makePort x = mempty # named x
|
||||
--makePort x = circle 0.2 # fc green # named x
|
||||
--makePort x = textBox (show x) # fc green # named x
|
||||
|
||||
|
||||
makePortDiagrams points =
|
||||
@ -123,3 +128,32 @@ lambdaRegion n dia =
|
||||
|
||||
-- RESULT ICON --
|
||||
resultIcon = unitSquare # lw none # fc lime
|
||||
|
||||
-- GUARD ICON --
|
||||
guardTriangle :: Int -> Diagram B
|
||||
guardTriangle x = triangleAndPort # alignL
|
||||
where
|
||||
triangleAndPort = polygon (with & polyType .~ PolySides [90 @@ deg, 45 @@ deg] [1, 1])
|
||||
# rotateBy (1/8)# lc white # lwG defaultLineWidth # alignT # alignR <> (makePort x # showOrigin)
|
||||
|
||||
guardLBracket :: Int -> Diagram B
|
||||
guardLBracket x = ell # alignT # alignL <> makePort x
|
||||
where
|
||||
-- todo: use a path or trail here so that the corner is rounded correctly
|
||||
ell = (hrule 1 # lc orange # lwG defaultLineWidth # alignR) <> (vrule 1 # lc orange # lwG defaultLineWidth # alignT)
|
||||
|
||||
-- | The ports of the guard icon are as follows:
|
||||
-- Port 0: The top port for the result
|
||||
-- Ports 1,3,5...: The left ports for the booleans
|
||||
-- Ports 2,4...: The right ports for the values
|
||||
guardIcon :: Int -> Diagram B
|
||||
guardIcon n = (vcat $ take n trianglesAndBrackets # alignT) <> makePort 0
|
||||
where
|
||||
--guardTriangles = vsep 0.4 (take n (map guardTriangle [0,1..]))
|
||||
trianglesWithPorts = map guardTriangle [2,4..]
|
||||
lBrackets = map guardLBracket [1,3..]
|
||||
trianglesAndBrackets =
|
||||
zipWith zipper trianglesWithPorts lBrackets
|
||||
zipper tri lBrack = verticalLine === ((lBrack ||| hrule 0.4) # alignR <> (tri # alignL))
|
||||
where
|
||||
verticalLine = vrule 0.4 # lc white # lwG defaultLineWidth
|
||||
|
@ -17,8 +17,6 @@ import Lib
|
||||
import Icons
|
||||
import Rendering
|
||||
|
||||
-- todo: Give graphviz info about the size of the nodes such that a variable scaleFactor
|
||||
-- for subDiagrams is not necessary.
|
||||
-- todo: Find out how to hide unqualified names such that recursive drawings are connected correctly
|
||||
|
||||
applyDia = apply0Dia
|
||||
@ -129,5 +127,7 @@ main1 = do
|
||||
placedNodes <- renderDrawing super2Drawing
|
||||
mainWith (placedNodes # bgFrame 0.1 black)
|
||||
|
||||
main2 = mainWith (guardIcon 3 # bgFrame 0.1 black)
|
||||
|
||||
main :: IO ()
|
||||
main = main1
|
||||
main = main2
|
||||
|
Loading…
Reference in New Issue
Block a user