on master help sign in
Add type annotations to more library files.
commit5b62c530d580749197c3e41f64a7136ab72a6454 authorevancz <info@elm-lang.org> dateMon 8 Apr 2013, 01:49 (14 years ago) parent5d536d1
4 files changed+126−30
libraries/Graphics/Color.elm+53−25 libraries/Graphics/Element.elm+65−2 libraries/List.elm+3−3 libraries/Prelude.elm+5
libraries/Graphics/Color.elm+53−25
@@ -12,56 +12,84 @@ module Graphics.Color (rgba,rgb,hsva,hsv,
1212data Color = Color Int Int Int Float
1313
1414-- Create RGB colors with an alpha component for transparency. The alpha component is specified with numbers between 0 and 1.
15+rgba : Int -> Int -> Int -> Float -> Color
1516rgba = Color
1617
1718-- Create RGB colors from numbers between 0 and 255 inclusive.
19+rgb : Int -> Int -> Int -> Color
1820rgb r g b = Color r g b 1
1921
20−red = Color 255 0 0 1
21−lime = Color 0 255 0 1
22−blue = Color 0 0 255 1
22+red : Color
23+red = Color 255 0 0 1
24+lime : Color
25+lime = Color 0 255 0 1
26+blue : Color
27+blue = Color 0 0 255 1
2328
29+yellow : Color
2430yellow = Color 255 255 0 1
31+cyan : Color
2532cyan = Color 0 255 255 1
33+magenta : Color
2634magenta = Color 255 0 255 1
2735
28−black = Color 0 0 0 1
29−white = Color 255 255 255 1
30−
31−gray = Color 128 128 128 1
32−grey = Color 128 128 128 1
33−
34−maroon = Color 128 0 0 1
35−navy = Color 0 0 128 1
36−green = Color 0 128 0 1
37−
38−teal = Color 0 128 128 1
39−purple = Color 128 0 128 1
40−
41−forestGreen = Color 34 139 34 1
36+black : Color
37+black = Color 0 0 0 1
38+white : Color
39+white = Color 255 255 255 1
40+
41+gray : Color
42+gray = Color 128 128 128 1
43+grey : Color
44+grey = Color 128 128 128 1
45+
46+maroon : Color
47+maroon = Color 128 0 0 1
48+navy : Color
49+navy = Color 0 0 128 1
50+green : Color
51+green = Color 0 128 0 1
52+
53+teal : Color
54+teal = Color 0 128 128 1
55+purple : Color
56+purple = Color 128 0 128 1
57+
58+violet : Color
4259violet = Color 238 130 238 1
60+forestGreen : Color
61+forestGreen = Color 34 139 34 1
4362
44−-- Produce a &ldquo;complementary color&rdquo;. The two colors will accent each other.
63+-- Produce a &ldquo;complementary color&rdquo;.
64+-- The two colors will accent each other.
4565complement : Color -> Color
4666
47−-- Create HSV colors with an alpha component for transparency. The alpha component is specified with numbers between 0 and 1.
67+-- Create HSV colors with an alpha component for transparency.
68+-- The alpha component is specified with numbers between 0 and 1.
4869hsva : Int -> Float -> Float -> Float -> Color
4970
5071-- Create HSV colors. HSV stands for hue-saturation-value.
5172--
52−-- Hue is a degree from 0 to 360 representing a color wheel: red at 0&deg;, green at 120&deg;, blue at 240&deg;, and red again at 360&deg;.
53−-- This makes it easy to cycle through colors and compute color complements, triads, tetrads, etc.
73+-- Hue is a degree from 0 to 360 representing a color wheel: red at 0&deg;,
74+-- green at 120&deg;, blue at 240&deg;, and red again at 360&deg;.
75+-- This makes it easy to cycle through colors and compute color complements,
76+-- triads, tetrads, etc.
5477--
55−-- Saturation is a number between 1 and 0 where lowering this number makes your color more grey. This can help you tone a color down.
78+-- Saturation is a number between 1 and 0 where lowering this number makes
79+-- your color more grey. This can help you tone a color down.
5680--
57−-- Value is also a number between 1 and 0. Lowering this number makes your color more black.
81+-- Value is also a number between 1 and 0. Lowering this number makes your
82+-- color more black.
5883--
5984-- Look up the &ldquo;HSV cylinder&rdquo; for more information.
6085hsv : Int -> Float -> Float -> Color
6186
6287data Gradient
63− = Linear [(Float,Color)] (Float,Float) (Float,Float)
64− | Radial [(Float,Color)] (Float,Float) Float (Float,Float) Float
88+ = Linear (Float,Float) (Float,Float) [(Float,Color)]
89+ | Radial (Float,Float) Float (Float,Float) Float [(Float,Color)]
6590
91+linear : (Number,Number) -> (Number,Number) -> [(Float,Color)] -> Gradient
6692linear = Linear
93+radial : (Number,Number) -> Number ->
94+ (Number,Number) -> Number -> [(Float,Color)] -> Gradient
6795radial = Radial
libraries/Graphics/Element.elm+65−2
@@ -30,26 +30,42 @@ type Properties = {
3030
3131type Element = { props : Properties, element : ElementPrim }
3232
33+widthOf : Element -> Int
3334widthOf e = e.props.width
35+
36+heightOf : Element -> Int
3437heightOf e = e.props.height
38+
39+sizeOf : Element -> Int
3540sizeOf e = (e.props.width, e.props.height)
3641
42+width : Int -> Element -> Element
3743width nw e = let p = e.props
3844 props = case e.element of
3945 Image _ w h _ -> {p| height <- h/w*nw }
4046 RawHtml html -> {p| height <- htmlHeight nw html }
4147 _ -> p
4248 in { element=e.element, props={props| width <- nw} }
49+
50+height : Int -> Element -> Element
4351height nh e = let p = e.props
4452 props = case e.element of
4553 Image _ w h _ -> {p| width <- w/h*nh }
4654 _ -> p
4755 in { element=e.element, props={p| height <- nh} }
56+
57+opacity : Float -> Element -> Element
4858opacity o e = let p = e.props in { element=e.element, props={p| opacity <- o} }
59+
60+color : Color -> Element -> Element
4961color c e = let p = e.props in
5062 { element=e.element, props={p| color <- Just c} }
63+
64+tag : String -> Element -> Element
5165tag name e = let p = e.props in
5266 { element=e.element, props={p| tag <- JS.fromString name} }
67+
68+link : String -> Element -> Element
5369link href e = let p = e.props in
5470 { element=e.element, props={p| href <- JS.fromString href} }
5571
@@ -67,8 +83,13 @@ data ElementPrim
6783
6884data ImageStyle = Plain | Fitted | Cropped (Int,Int)
6985
86+image : Int -> Int -> String -> Element
7087image w h src = newElement w h (Image Plain w h (JS.fromString src))
88+
89+fittedImage : Int -> Int -> String -> Element
7190fittedImage w h src = newElement w h (Image Fitted w h (JS.fromString src))
91+
92+croppedImage : Int -> Int -> (Int,Int) -> String -> Element
7293croppedImage w h pos src =
7394 newElement w h (Image (Cropped pos) w h (JS.fromString src))
7495
@@ -76,11 +97,15 @@ data Three = P | Z | N
7697data Pos = Absolute Int | Relative Float
7798type Position = { horizontal : Three, vertical : Three, x : Pos, y : Pos }
7899
100+container : Int -> Int -> Position -> Element -> Element
79101container w h pos e = newElement w h (Container pos e)
102+
103+spacer : Int -> Int -> Element
80104spacer w h = newElement w h Spacer
81105
82106data Direction = DUp | DDown | DLeft | DRight | DIn | DOut
83107
108+flow : Direction -> [Element] -> Element
84109flow dir es =
85110 let ws = List.map widthOf es
86111 hs = List.map heightOf es
@@ -95,19 +120,25 @@ flow dir es =
95120 DIn -> newFlow (List.maximum ws) (List.maximum hs)
96121 DOut -> newFlow (List.maximum ws) (List.maximum hs)
97122
123+above : Element -> Element -> Element
98124above hi lo =
99125 newElement (max (widthOf hi) (widthOf lo))
100126 (heightOf hi + heightOf lo)
101127 (Flow DDown [hi,lo])
128+
129+below : Element -> Element -> Element
102130below lo hi =
103131 newElement (max (widthOf hi) (widthOf lo))
104132 (heightOf hi + heightOf lo)
105133 (Flow DDown [hi,lo])
134+
135+beside : Element -> Element -> Element
106136beside lft rht =
107137 newElement (widthOf lft + widthOf rht)
108138 (max (heightOf lft) (heightOf rht))
109139 (Flow right [lft,rht])
110140
141+layers : [Element] -> Element
111142layers es =
112143 let ws = List.map widthOf es
113144 hs = List.map heightOf es
@@ -116,31 +147,63 @@ layers es =
116147
117148-- Repetitive things --
118149
150+absolute : Pos
119151absolute = Absolute
152+relative : Pos
120153relative = Relative
121154
122−middle = { horizontal = Z, vertical = Z, x = Relative 0.5, y = Relative 0.5 }
123−topLeft = { horizontal = N, vertical = P, x = Absolute 0, y = Absolute 0 }
155+middle : Position
156+middle = { horizontal=Z, vertical=Z, x=Relative 0.5, y=Relative 0.5 }
157+topLeft : Position
158+topLeft = { horizontal=N, vertical=P, x=Absolute 0, y=Absolute 0 }
159+topRight : Position
124160topRight = { topLeft | horizontal <- P }
161+bottomLeft : Position
125162bottomLeft = { topLeft | vertical <- N }
163+bottomRight : Position
126164bottomRight = { bottomLeft | horizontal <- P }
165+midLeft : Position
127166midLeft = { middle | horizontal <- N, x <- Absolute 0 }
167+midRight : Position
128168midRight = { midLeft | horizontal <- P }
169+midTop : Position
129170midTop = { middle | vertical <- P, y <- Absolute 0 }
171+midBottom : Position
130172midBottom = { midTop | vertical <- N }
173+
174+middleAt : Pos -> Pos -> Position
131175middleAt x y = { horizontal = Z, vertical = Z, x = x, y = y }
176+topLeftAt : Pos -> Pos -> Position
132177topLeftAt x y = { horizontal = N, vertical = P, x = x, y = y }
178+topRightAt : Pos -> Pos -> Position
133179topRightAt x y = { horizontal = P, vertical = P, x = x, y = y }
180+bottomLeftAt : Pos -> Pos -> Position
134181bottomLeftAt x y = { horizontal = N, vertical = N, x = x, y = y }
182+bottomRightAt : Pos -> Pos -> Position
135183bottomRightAt x y = { horizontal = P, vertical = N, x = x, y = y }
184+midLeftAt : Pos -> Pos -> Position
136185midLeftAt x y = { horizontal = N, vertical = Z, x = x, y = y }
186+midRightAt : Pos -> Pos -> Position
137187midRightAt x y = { horizontal = P, vertical = Z, x = x, y = y }
188+midTopAt : Pos -> Pos -> Position
138189midTopAt x y = { horizontal = Z, vertical = P, x = x, y = y }
190+midBottomAt : Pos -> Pos -> Position
139191midBottomAt x y = { horizontal = Z, vertical = N, x = x, y = y }
140192
193+up : Direction
141194up = DUp
195+
196+down : Direction
142197down = DDown
198+
199+left : Direction
143200left = DLeft
201+
202+right : Direction
144203right = DRight
204+
205+inward : Direction
145206inward = DIn
207+
208+outward : Direction
146209outward = DOut
libraries/List.elm+3−3
@@ -9,7 +9,7 @@ import Native.List as L
99(::) : a -> [a] -> [a]
1010
1111-- Appends two lists.
12−-- (++) : [a] -> [a] -> [a]
12+(++) : Appendable a -> Appendable a -> Appendable a
1313
1414-- Extract the first element of a list. List must be non-empty.
1515head : [a] -> a
@@ -63,10 +63,10 @@ and : [Bool] -> Bool
6363or : [Bool] -> Bool
6464
6565-- Flatten a list of lists.
66−concat : [[a]] -> [a]
66+concat : [Appendable a] -> Appendable a
6767
6868-- Map a given function onto a list and flatten the resulting lists. (concatMap f xs == concat (map f xs))
69−concatMap : (a -> [b]) -> [a] -> [b]
69+concatMap : (a -> Appendable b) -> [a] -> Appendable b
7070concatMap f = L.concat . L.map f
7171
7272-- Get the sum of the list elements.
libraries/Prelude.elm+5
@@ -12,6 +12,11 @@ degrees d = d * Math.PI / 180
1212turns : Float -> Float
1313turns r = 2 * Math.PI * r
1414
15+(+) : Number -> Number -> Number
16+(-) : Number -> Number -> Number
17+(*) : Number -> Number -> Number
18+(/) : Float -> Float -> Float
19+
1520-- Integer division, remainder is discarded.
1621div : Int -> Int -> Int
1722