You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Canvas.elm
+22-5Lines changed: 22 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ module Canvas
7
7
,DrawImageParams(..)
8
8
, initialize
9
9
, toHtml
10
+
, draw
10
11
, batch
11
12
, loadImage
12
13
, getImageData
@@ -21,7 +22,7 @@ module Canvas
21
22
@docs Canvas, Size, DrawOp, DrawImageParams
22
23
23
24
# Basics
24
-
@docs initialize, toHtml, batch
25
+
@docs initialize, toHtml, draw, batch
25
26
26
27
# Loading Images
27
28
@docs loadImage, Error
@@ -103,6 +104,7 @@ type DrawOp
103
104
|Clip
104
105
|ClosePath
105
106
|DrawImageCanvasDrawImageParams
107
+
|Batch(ListDrawOp)
106
108
107
109
108
110
{-| The `DrawOp` `DrawImage` takes a `Canvas` and a `DrawImageParam`. We made three different `DrawImageParam`, because there are three different sets of parameters you can give the native javascript `ctx.drawImage()`. [See here for more info](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage.)
@@ -134,11 +136,26 @@ toHtml : List (Attribute msg) -> Canvas -> Html msg
134
136
toHtml =
135
137
Native.Canvas.toHtml
136
138
137
-
138
-
{-| This is our primary way of drawing onto canvases. Give `batch` a list of `DrawOp` and you can apply those `DrawOp` to a canvas.
139
+
{-| This is our primary way of drawing onto canvases. Give `draw` a `drawOp` and apply it to a canvas.
139
140
140
141
drawLine : Point -> Point -> Canvas -> Canvas
141
142
drawLine p0 p1 =
143
+
(Canvas.batch >> Canvas.draw)
144
+
[ BeginPath
145
+
, LineWidth 2
146
+
, MoveTo p0
147
+
, LineTo p1
148
+
, Stroke
149
+
]
150
+
-}
151
+
draw:DrawOp->Canvas->Canvas
152
+
draw =
153
+
Native.Canvas.draw
154
+
155
+
{-| You dont want to apply `DrawOp` one at a time. Bundle many `DrawOp` together in one batch, using `batch`.
0 commit comments