Skip to content

Commit 3f9f7b5

Browse files
committed
Implement appropriate Show instances for TextAlign, Composite and PatternRepeat
1 parent e86e49b commit 3f9f7b5

File tree

2 files changed

+60
-23
lines changed

2 files changed

+60
-23
lines changed

docs/Graphics/Canvas.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,17 @@ data PatternRepeat
669669

670670
Enumerates the different types of pattern repetitions.
671671

672+
##### Instances
673+
``` purescript
674+
Show PatternRepeat
675+
```
676+
677+
#### `toString`
678+
679+
``` purescript
680+
toString :: PatternRepeat -> String
681+
```
682+
672683
#### `createPattern`
673684

674685
``` purescript
@@ -680,7 +691,7 @@ Create a new canvas pattern (repeatable image).
680691
#### `setPatternFillStyle`
681692

682693
``` purescript
683-
setPatternFillStyle :: forall eff. CanvasGradient -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
694+
setPatternFillStyle :: forall eff. CanvasPattern -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
684695
```
685696

686697
Set the Context2D fillstyle to the CanvasPattern.

src/Graphics/Canvas.purs

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -228,23 +228,35 @@ data Composite
228228
| Xor
229229

230230
instance showComposite :: Show Composite where
231-
show SourceOver = "source-over"
232-
show SourceIn = "source-in"
233-
show SourceOut = "source-out"
234-
show SourceAtop = "source-atop"
235-
show DestinationOver = "destination-over"
236-
show DestinationIn = "destination-in"
237-
show DestinationOut = "destination-out"
238-
show DestinationAtop = "destination-atop"
239-
show Lighter = "lighter"
240-
show Copy = "copy"
241-
show Xor = "xor"
231+
show SourceOver = "SourceOver"
232+
show SourceIn = "SourceIn"
233+
show SourceOut = "SourceOut"
234+
show SourceAtop = "SourceAtop"
235+
show DestinationOver = "DestinationOver"
236+
show DestinationIn = "DestinationIn"
237+
show DestinationOut = "DestinationOut"
238+
show DestinationAtop = "DestinationAtop"
239+
show Lighter = "Lighter"
240+
show Copy = "Copy"
241+
show Xor = "Xor"
242242

243243
foreign import setGlobalCompositeOperationImpl :: forall eff. Context2D -> String -> Eff (canvas :: Canvas | eff) Context2D
244244

245245
-- | Set the current composite operation.
246246
setGlobalCompositeOperation :: forall eff. Context2D -> Composite -> Eff (canvas :: Canvas | eff) Context2D
247-
setGlobalCompositeOperation ctx composite = setGlobalCompositeOperationImpl ctx (show composite)
247+
setGlobalCompositeOperation ctx composite = setGlobalCompositeOperationImpl ctx (toString composite)
248+
where
249+
toString SourceOver = "source-over"
250+
toString SourceIn = "source-in"
251+
toString SourceOut = "source-out"
252+
toString SourceAtop = "source-atop"
253+
toString DestinationOver = "destination-over"
254+
toString DestinationIn = "destination-in"
255+
toString DestinationOut = "destination-out"
256+
toString DestinationAtop = "destination-atop"
257+
toString Lighter = "lighter"
258+
toString Copy = "copy"
259+
toString Xor = "xor"
248260

249261
-- | Set the current global alpha level.
250262
foreign import setGlobalAlpha :: forall eff. Context2D -> Number -> Eff (canvas :: Canvas | eff) Context2D
@@ -388,11 +400,11 @@ data TextAlign
388400
= AlignLeft | AlignRight | AlignCenter | AlignStart | AlignEnd
389401

390402
instance showTextAlign :: Show TextAlign where
391-
show AlignLeft = "left"
392-
show AlignRight = "right"
393-
show AlignCenter = "center"
394-
show AlignStart = "start"
395-
show AlignEnd = "end"
403+
show AlignLeft = "AlignLeft"
404+
show AlignRight = "AlignRight"
405+
show AlignCenter = "AlignCenter"
406+
show AlignStart = "AlignStart"
407+
show AlignEnd = "AlignEnd"
396408

397409
foreign import textAlignImpl :: forall eff. Context2D -> Eff (canvas :: Canvas | eff) String
398410

@@ -414,7 +426,13 @@ foreign import setTextAlignImpl :: forall eff. Context2D -> String -> (Eff (canv
414426
-- | Set the current text alignment.
415427
setTextAlign :: forall eff. Context2D -> TextAlign -> Eff (canvas :: Canvas | eff) Context2D
416428
setTextAlign ctx textalign =
417-
setTextAlignImpl ctx (show textalign)
429+
setTextAlignImpl ctx (toString textalign)
430+
where
431+
toString AlignLeft = "left"
432+
toString AlignRight = "right"
433+
toString AlignCenter = "center"
434+
toString AlignStart = "start"
435+
toString AlignEnd = "end"
418436

419437
-- | Text metrics:
420438
-- |
@@ -482,14 +500,22 @@ foreign import drawImageFull :: forall eff. Context2D -> CanvasImageSource -> Nu
482500
-- | Enumerates the different types of pattern repetitions.
483501
data PatternRepeat = Repeat | RepeatX | RepeatY | NoRepeat
484502

503+
instance showPatternRepeat :: Show PatternRepeat where
504+
show Repeat = "Repeat"
505+
show RepeatX = "RepeatX"
506+
show RepeatY = "RepeatY"
507+
show NoRepeat = "NoRepeat"
508+
485509
foreign import createPatternImpl :: forall eff. CanvasImageSource -> String -> Context2D -> Eff (canvas :: Canvas | eff) CanvasPattern
486510

487511
-- | Create a new canvas pattern (repeatable image).
488512
createPattern :: forall eff. CanvasImageSource -> PatternRepeat -> Context2D -> Eff (canvas :: Canvas | eff) CanvasPattern
489-
createPattern img Repeat = createPatternImpl img "repeat"
490-
createPattern img RepeatX = createPatternImpl img "repeat-x"
491-
createPattern img RepeatY = createPatternImpl img "repeat-y"
492-
createPattern img NoRepeat = createPatternImpl img "no-repeat"
513+
createPattern img repeat = createPatternImpl img (toString repeat)
514+
where
515+
toString Repeat = "repeat"
516+
toString RepeatX = "repeat-x"
517+
toString RepeatY = "repeat-y"
518+
toString NoRepeat = "no-repeat"
493519

494520
-- | Set the Context2D fillstyle to the CanvasPattern.
495521
foreign import setPatternFillStyle :: forall eff. CanvasPattern -> Context2D -> Eff (canvas :: Canvas | eff) Context2D

0 commit comments

Comments
 (0)