on master help sign in
Convert more libraries to the new doc format
commit2a18fb63020fe38d706b4928255d864def709b08 authorEvan Czaplicki <info@elm-lang.org> dateThu 12 Sep 2013, 12:11 (13 years ago) parent1f10f8d
3 files changed+97−78
libraries/Graphics/Element.elm+62−48 libraries/Signal.elm+1−3 libraries/Transform2D.elm+34−27
libraries/Graphics/Element.elm+62−48
@@ -1,5 +1,8 @@
1−
21module Graphics.Element where
2+{-| Graphical elements that snap together to build complex widgets and layouts.
3+Each Element is a rectangle with a known width and height, making them easy to
4+combine and position.
5+-}
36
47import open Basics
58import Native.Utils
@@ -22,19 +25,19 @@ type Properties = {
2225
2326type Element = { props : Properties, element : ElementPrim }
2427
25−-- Get the width of an Element
28+{-| Get the width of an Element -}
2629widthOf : Element -> Int
2730widthOf e = e.props.width
2831
29−-- Get the height of an Element
32+{-| Get the height of an Element -}
3033heightOf : Element -> Int
3134heightOf e = e.props.height
3235
33−-- Get the width and height of an Element
36+{-| Get the width and height of an Element -}
3437sizeOf : Element -> (Int,Int)
3538sizeOf e = (e.props.width, e.props.height)
3639
37−-- Create an `Element` with a given width.
40+{-| Create an `Element` with a given width. -}
3841width : Int -> Element -> Element
3942width nw e =
4043 let p = e.props
@@ -44,7 +47,7 @@ width nw e =
4447 _ -> p
4548 in { element=e.element, props={ props | width <- nw } }
4649
47−-- Create an `Element` with a given height.
50+{-| Create an `Element` with a given height. -}
4851height : Int -> Element -> Element
4952height nh e =
5053 let p = e.props
@@ -53,30 +56,32 @@ height nh e =
5356 _ -> p
5457 in { element=e.element, props={ p | height <- nh} }
5558
56−-- Create an `Element` with a new width and height.
59+{-| Create an `Element` with a new width and height. -}
5760size : Int -> Int -> Element -> Element
5861size w h e = height h (width w e)
5962
60−-- Create an `Element` with a given opacity. Opacity is a number between 0 and 1
61−-- where 0 means totally clear.
63+{-| Create an `Element` with a given opacity. Opacity is a number between 0 and 1
64+where 0 means totally clear.
65+-}
6266opacity : Float -> Element -> Element
6367opacity o e = let p = e.props in { element=e.element, props={p| opacity <- o} }
6468
65−-- Create an `Element` with a given background color.
69+{-| Create an `Element` with a given background color. -}
6670color : Color -> Element -> Element
6771color c e = let p = e.props in
6872 { element = e.element
6973 , props = { p | color <- Just c}
7074 }
7175
72−-- Create an `Element` with a tag. This lets you link directly to it.
73−-- The element `(tag "all-about-badgers" thirdParagraph)` can be reached
74−-- with a link lik this: `/facts-about-animals.elm#all-about-badgers`
76+{-| Create an `Element` with a tag. This lets you link directly to it.
77+The element `(tag "all-about-badgers" thirdParagraph)` can be reached
78+with a link lik this: `/facts-about-animals.elm#all-about-badgers`
79+-}
7580tag : String -> Element -> Element
7681tag name e = let p = e.props in
7782 { element=e.element, props={p | tag <- JS.fromString name} }
7883
79−-- Create an `Element` that is a hyper-link.
84+{-| Create an `Element` that is a hyper-link. -}
8085link : String -> Element -> Element
8186link href e = let p = e.props in
8287 { element=e.element, props={p | href <- JS.fromString href} }
@@ -95,20 +100,22 @@ data ElementPrim
95100
96101data ImageStyle = Plain | Fitted | Cropped (Int,Int) | Tiled
97102
98−-- Create an image given a width, height, and image source.
103+{-| Create an image given a width, height, and image source. -}
99104image : Int -> Int -> String -> Element
100105image w h src = newElement w h (Image Plain w h (JS.fromString src))
101106
102−-- Create a fitted image given a width, height, and image source.
103−-- This will crop the picture to best fill the given dimensions.
107+{-| Create a fitted image given a width, height, and image source.
108+This will crop the picture to best fill the given dimensions.
109+-}
104110fittedImage : Int -> Int -> String -> Element
105111fittedImage w h src = newElement w h (Image Fitted w h (JS.fromString src))
106112
107−-- Create a cropped image. Take a rectangle out of the picture starting
108−-- at the given top left coordinate. If you have a 140-by-140 image,
109−-- the following will cut a 100-by-100 square out of the middle of it.
110−--
111−-- croppedImage (20,20) 100 100 "yogi.jpg"
113+{-| Create a cropped image. Take a rectangle out of the picture starting
114+at the given top left coordinate. If you have a 140-by-140 image,
115+the following will cut a 100-by-100 square out of the middle of it.
116+
117+ croppedImage (20,20) 100 100 "yogi.jpg"
118+-}
112119croppedImage : (Int,Int) -> Int -> Int -> String -> Element
113120croppedImage pos w h src =
114121 newElement w h (Image (Cropped pos) w h (JS.fromString src))
@@ -121,31 +128,34 @@ data Three = P | Z | N
121128data Pos = Absolute Int | Relative Float
122129type Position = { horizontal : Three, vertical : Three, x : Pos, y : Pos }
123130
124−-- Put an element in a container. This lets you position the element really
125−-- easily, and there are tons of ways to set the `Position`.
126−-- To center `element` exactly in a 300-by-300 square you would say:
127−--
128−-- container 300 300 middle element
129−--
130−-- By setting the color of the container, you can create borders.
131+{-| Put an element in a container. This lets you position the element really
132+easily, and there are tons of ways to set the `Position`.
133+To center `element` exactly in a 300-by-300 square you would say:
134+
135+ container 300 300 middle element
136+
137+By setting the color of the container, you can create borders.
138+-}
131139container : Int -> Int -> Position -> Element -> Element
132140container w h pos e = newElement w h (Container pos e)
133141
134−-- Create an empty box. This is useful for getting your spacing right and
135−-- for making borders.
142+{-| Create an empty box. This is useful for getting your spacing right and
143+for making borders.
144+-}
136145spacer : Int -> Int -> Element
137146spacer w h = newElement w h Spacer
138147
139148data Direction = DUp | DDown | DLeft | DRight | DIn | DOut
140149
141−-- Have a list of elements flow in a particular direction.
142−-- The `Direction` starts from the first element in the list.
143−--
144−-- flow right [a,b,c]
145−--
146−-- +---+---+---+
147−-- | a | b | c |
148−-- +---+---+---+
150+{-| Have a list of elements flow in a particular direction.
151+The `Direction` starts from the first element in the list.
152+
153+ flow right [a,b,c]
154+
155+ +---+---+---+
156+ | a | b | c |
157+ +---+---+---+
158+-}
149159flow : Direction -> [Element] -> Element
150160flow dir es =
151161 let ws = List.map widthOf es
@@ -161,33 +171,37 @@ flow dir es =
161171 DIn -> newFlow (List.maximum ws) (List.maximum hs)
162172 DOut -> newFlow (List.maximum ws) (List.maximum hs)
163173
164−-- Stack elements vertically. To put `a` above `b` you would say:
165−--
166−-- a `above` b
174+{-| Stack elements vertically. To put `a` above `b` you would say:
175+
176+ a `above` b
177+-}
167178above : Element -> Element -> Element
168179above hi lo =
169180 newElement (max (widthOf hi) (widthOf lo))
170181 (heightOf hi + heightOf lo)
171182 (Flow DDown [hi,lo])
172183
173−-- Stack elements vertically. To put `a` below `b` you would say:
174−--
175−-- a `below` b
184+{-| Stack elements vertically. To put `a` below `b` you would say:
185+
186+ a `below` b
187+-}
176188below : Element -> Element -> Element
177189below lo hi =
178190 newElement (max (widthOf hi) (widthOf lo))
179191 (heightOf hi + heightOf lo)
180192 (Flow DDown [hi,lo])
181193
182−-- Put elements beside each other horizontally.
194+{-| Put elements beside each other horizontally.
195+-}
183196beside : Element -> Element -> Element
184197beside lft rht =
185198 newElement (widthOf lft + widthOf rht)
186199 (max (heightOf lft) (heightOf rht))
187200 (Flow right [lft,rht])
188201
189−-- Layer elements on top of each other, starting from the bottom.
190−-- `(layers == flow outward)`
202+{-| Layer elements on top of each other, starting from the bottom.
203+`(layers == flow outward)`
204+-}
191205layers : [Element] -> Element
192206layers es =
193207 let ws = List.map widthOf es
libraries/Signal.elm+1−3
@@ -1,4 +1,4 @@
1−
1+module Signal where
22{-| The library for general signal manipulation. Includes lift functions up to
33`lift8` and infix lift operators `<~` and `~`, combinations, filters, and
44past-dependence.
@@ -28,7 +28,6 @@ the [`Time`](/docs/Signal/Time.elm) library.
2828@docs lift3, lift4, lift5, lift6, lift7, lift8
2929
3030-}
31−module Signal where
3231
3332import Native.Signal
3433import List (foldr)
@@ -161,7 +160,6 @@ The following expressions are equivalent:
161160 scene <~ Window.dimensions ~ Mouse.position
162161 lift2 scene Window.dimensions Mouse.position
163162-}
164−
165163(~) : Signal (a -> b) -> Signal a -> Signal b
166164sf ~ s = Native.Signal.lift2 (\f x -> f x) sf s
167165
libraries/Transform2D.elm+34−27
@@ -1,44 +1,51 @@
1−
21module Transform2D where
2+{-| A library for performing [2D matrix transformations](http://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations).
3+It is used primarily with the `groupTransform` function from `Graphics.Collage` and
4+allows you to do things like rotation, scaling, translation, shearing, and reflection.
5+-}
36
47import Native.Transform2D
58
69data Transform2D = Transform2D
710
8−-- Create an identity transform. Transforming by the identity does
9−-- not change anything, but it can come in handy as a default or
10−-- base case.
11−--
12−-- / 1 0 \\
13−-- \\ 0 1 /
11+{-| Create an identity transform. Transforming by the identity does
12+not change anything, but it can come in handy as a default or
13+base case.
14+
15+ / 1 0 \\
16+ \\ 0 1 /
17+-}
1418identity : Transform2D
1519identity = Native.Transform2D.identity
1620
17−-- Creates an arbitrary transformation matrix. This lets you create scales,
18−-- shears, reflections, translations, or any other 2D transform.
19−--
20−-- matrix a b c d dx dy
21−--
22−-- / a b \\
23−-- \\ c d /
24−--
25−-- And `dx` and `dy` are the translation values.
21+{-| Creates a transformation matrix. This lets you create transforms
22+such as scales, shears, reflections, and translations.
23+
24+ matrix a b c d dx dy
25+
26+ / a b \\
27+ \\ c d /
28+
29+And `dx` and `dy` are the translation values.
30+-}
2631matrix : Float -> Float -> Float -> Float -> Float -> Float -> Transform2D
2732matrix = Native.Transform2D.matrix
2833
29−-- Creates a [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix).
30−-- Given an angle t, it creates a counterclockwise rotation matrix:
31−--
32−-- / cos t -sin t \\
33−-- \\ sin t cos t /
34+{-| Creates a [rotation matrix](http://en.wikipedia.org/wiki/Rotation_matrix).
35+Given an angle t, it creates a counterclockwise rotation matrix:
36+
37+ / cos t -sin t \\
38+ \\ sin t cos t /
39+-}
3440rotation : Float -> Transform2D
3541rotation = Native.Transform2D.rotation
3642
37−-- Multiplies two transforms together:
38−--
39−-- multiply a b
40−--
41−-- / a11 a12 \\ . / b11 b12 \\
42−-- \\ a21 a22 / \\ b21 b22 /
43+{-| Multiplies two transforms together:
44+
45+ multiply a b
46+
47+ / a11 a12 \\ . / b11 b12 \\
48+ \\ a21 a22 / \\ b21 b22 /
49+-}
4350multiply : Transform2D -> Transform2D -> Transform2D
4451multiply = Native.Transform2D.multiply