on master help sign in
Add LineStyle to type aliases and add some annotations to the collage library
commit2ae0e90735f5bb941ad1a0b1a669f05fd414b123 authorevancz <info@elm-lang.org> dateSun 5 May 2013, 12:11 (14 years ago) parent6b8fada
2 files changed+27−10
compiler/Types/Alias.hs+14−7 libraries/Graphics/Collage.elm+13−3
compiler/Types/Alias.hs+14−7
@@ -11,13 +11,20 @@ import Types.Types
1111
1212builtins :: [(String,([X],Type))]
1313builtins =
14− let touch = ("t0", [time]) : map (flip (,) [int]) ["x","y","x0","y0","id"]
15− state = [("text", [string]), ("start", [int]), ("end", [int])]
16− in [ ("String", ([], listOf char))
17− , ("Time", ([], float))
18− , ("KeyCode", ([], int))
19− , ("Touch", ([], RecordT (Map.fromList touch) EmptyRecord))
20− , ("TextState", ([], RecordT (Map.fromList state) EmptyRecord))
14+ let touch = ("t0", time) : map (flip (,) int) ["x","y","x0","y0","id"]
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
22+ in [ ("String", ([], listOf char)),
23+ ("Time", ([], float)),
24+ ("KeyCode", ([], int)),
25+ ("Touch", ([], makeRecord touch)),
26+ ("TextState", ([], makeRecord state)),
27+ ("LineStyle", ([], makeRecord line))
2128 ]
2229
2330get :: [Statement] -> Map.Map String ([X],Type)
libraries/Graphics/Collage.elm+13−3
@@ -35,6 +35,7 @@ type LineStyle = {
3535 dashOffset : Int
3636 }
3737
38+defaultLine : LineStyle
3839defaultLine = {
3940 color = Color.black,
4041 width = 1,
@@ -45,8 +46,11 @@ defaultLine = {
4546 miterLimit = 10
4647 }
4748
49+solid : Color -> LineStyle
4850solid clr = { defaultLine | color <- clr }
51+dashed : Color -> LineStyle
4952dashed clr = { defaultLine | color <- clr, dashing <- [8,4] }
53+dotted : Color -> LineStyle
5054dotted clr = { defaultLine | color <- clr, dashing <- [3,3] }
5155
5256data BasicForm
@@ -90,11 +94,17 @@ groupTransform matrix fs = form (FGroup matrix fs)
9094rotate : Float -> Form -> Form
9195rotate t f = { f | theta <- f.theta + t }
9296
93−scale s f = { f | scale <- f.scale * s }
97+scale : Float -> Form -> Form
98+scale s f = { f | scale <- f.scale * s }
9499
100+move : Float -> Float -> Form -> Form
95101move x y f = { f | x <- f.x + x, y <- f.y + y }
96−moveX x f = { f | x <- f.x + x }
97−moveY y f = { f | y <- f.y + y }
102+
103+moveX : Float -> Form -> Form
104+moveX x f = { f | x <- f.x + x }
105+
106+moveY : Float -> Form -> Form
107+moveY y f = { f | y <- f.y + y }
98108
99109collage : Int -> Int -> [Form] -> Element
100110