on master help sign in
Add LineStyle to type aliases and add some annotations to the collage library
2ae0e90evancz
compiler/Types/Alias.hs+14−7
@@ -11,13 +11,20 @@ import Types.Types
11
11
12builtins :: [(String,([X],Type))]
12builtins :: [(String,([X],Type))]
13builtins =
13builtins =
14− let touch = ("t0", [time]) : map (flip (,) [int]) ["x","y","x0","y0","id"]
14+ let touch = ("t0", time) : map (flip (,) int) ["x","y","x0","y0","id"]
15− state = [("text", [string]), ("start", [int]), ("end", [int])]
15+ state = [("text", string), ("start", int), ("end", int)]
16+ line = [("color", tipe "Color"), ("width", float),
17+ ("cap", tipe "LineCap"), ("join", tipe "LineJoin"),
18+ ("miterLimit", float), ("dashing", listOf int),
19+ ("dashOffset", int)]
20+ makeRecord fields =
21+ RecordT (Map.fromList $ map (second (:[])) fields) EmptyRecord
16− in [ ("String", ([], listOf char))
22+ in [ ("String", ([], listOf char)),
17− , ("Time", ([], float))
23+ ("Time", ([], float)),
18− , ("KeyCode", ([], int))
24+ ("KeyCode", ([], int)),
19− , ("Touch", ([], RecordT (Map.fromList touch) EmptyRecord))
25+ ("Touch", ([], makeRecord touch)),
20− , ("TextState", ([], RecordT (Map.fromList state) EmptyRecord))
26+ ("TextState", ([], makeRecord state)),
27+ ("LineStyle", ([], makeRecord line))
21 ]
28 ]
22
29
23get :: [Statement] -> Map.Map String ([X],Type)
30get :: [Statement] -> Map.Map String ([X],Type)
libraries/Graphics/Collage.elm+13−3
@@ -35,6 +35,7 @@ type LineStyle = {
35 dashOffset : Int
35 dashOffset : Int
36 }
36 }
37
37
38+defaultLine : LineStyle
38defaultLine = {
39defaultLine = {
39 color = Color.black,
40 color = Color.black,
40 width = 1,
41 width = 1,
@@ -45,8 +46,11 @@ defaultLine = {
45 miterLimit = 10
46 miterLimit = 10
46 }
47 }
47
48
49+solid : Color -> LineStyle
48solid clr = { defaultLine | color <- clr }
50solid clr = { defaultLine | color <- clr }
51+dashed : Color -> LineStyle
49dashed clr = { defaultLine | color <- clr, dashing <- [8,4] }
52dashed clr = { defaultLine | color <- clr, dashing <- [8,4] }
53+dotted : Color -> LineStyle
50dotted clr = { defaultLine | color <- clr, dashing <- [3,3] }
54dotted clr = { defaultLine | color <- clr, dashing <- [3,3] }
51
55
52data BasicForm
56data BasicForm
@@ -90,11 +94,17 @@ groupTransform matrix fs = form (FGroup matrix fs)
90rotate : Float -> Form -> Form
94rotate : Float -> Form -> Form
91rotate t f = { f | theta <- f.theta + t }
95rotate t f = { f | theta <- f.theta + t }
92
96
97+scale : Float -> Form -> Form
93−scale s f = { f | scale <- f.scale * s }
98+scale s f = { f | scale <- f.scale * s }
94
99
100+move : Float -> Float -> Form -> Form
95move x y f = { f | x <- f.x + x, y <- f.y + y }
101move x y f = { f | x <- f.x + x, y <- f.y + y }
102+
103+moveX : Float -> Form -> Form
96−moveX x f = { f | x <- f.x + x }
104+moveX x f = { f | x <- f.x + x }
105+
106+moveY : Float -> Form -> Form
97−moveY y f = { f | y <- f.y + y }
107+moveY y f = { f | y <- f.y + y }
98
108
99collage : Int -> Int -> [Form] -> Element
109collage : Int -> Int -> [Form] -> Element
100
110