File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,12 @@ Opaque object describing a gradient.
6565canvasElementToImageSource :: CanvasElement -> CanvasImageSource
6666```
6767
68+ #### ` withImage `
69+
70+ ``` purescript
71+ withImage :: forall eff a. String -> (CanvasImageSource -> Eff eff Unit) -> Eff eff Unit
72+ ```
73+
6874#### ` getCanvasElementById `
6975
7076``` purescript
Original file line number Diff line number Diff line change @@ -7,6 +7,20 @@ exports.canvasElementToImageSource = function(e) {
77 return e ;
88} ;
99
10+ exports . withImage = function ( src ) {
11+ return function ( f ) {
12+ return function ( ) {
13+ var img = new Image ( ) ;
14+ img . src = src ;
15+ img . addEventListener ( "load" , function ( ) {
16+ f ( img ) ( ) ;
17+ } , false ) ;
18+
19+ return { } ;
20+ }
21+ } ;
22+ } ;
23+
1024exports . getCanvasElementByIdImpl = function ( id , Just , Nothing ) {
1125 return function ( ) {
1226 var el = document . getElementById ( id ) ;
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ module Graphics.Canvas
8080 , restore
8181 , withContext
8282
83+ , withImage
8384 , getImageData
8485 , getImageDataWidth
8586 , getImageDataHeight
@@ -132,6 +133,9 @@ foreign import data CanvasGradient :: *
132133
133134foreign import canvasElementToImageSource :: CanvasElement -> CanvasImageSource
134135
136+ -- | Wrapper for asynchronously loading a image file by path and use it in callback, e.g. drawImage
137+ foreign import withImage :: forall eff a . String -> (CanvasImageSource -> Eff eff Unit ) -> Eff eff Unit
138+
135139foreign import getCanvasElementByIdImpl ::
136140 forall r eff . Fn3 String
137141 (CanvasElement -> r )
You can’t perform that action at this time.
0 commit comments