Skip to content

Commit 89d4f12

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

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
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: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,11 @@ data TextAlign
388388
= AlignLeft | AlignRight | AlignCenter | AlignStart | AlignEnd
389389

390390
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"
391+
show AlignLeft = "AlignLeft"
392+
show AlignRight = "AlignRight"
393+
show AlignCenter = "AlignCenter"
394+
show AlignStart = "AlignStart"
395+
show AlignEnd = "AlignEnd"
396396

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

@@ -414,7 +414,13 @@ foreign import setTextAlignImpl :: forall eff. Context2D -> String -> (Eff (canv
414414
-- | Set the current text alignment.
415415
setTextAlign :: forall eff. Context2D -> TextAlign -> Eff (canvas :: Canvas | eff) Context2D
416416
setTextAlign ctx textalign =
417-
setTextAlignImpl ctx (show textalign)
417+
setTextAlignImpl ctx (toString textalign)
418+
where
419+
toString AlignLeft = "left"
420+
toString AlignRight = "right"
421+
toString AlignCenter = "center"
422+
toString AlignStart = "start"
423+
toString AlignEnd = "end"
418424

419425
-- | Text metrics:
420426
-- |
@@ -482,14 +488,22 @@ foreign import drawImageFull :: forall eff. Context2D -> CanvasImageSource -> Nu
482488
-- | Enumerates the different types of pattern repetitions.
483489
data PatternRepeat = Repeat | RepeatX | RepeatY | NoRepeat
484490

491+
instance showPatternRepeat :: Show PatternRepeat where
492+
show Repeat = "Repeat"
493+
show RepeatX = "RepeatX"
494+
show RepeatY = "RepeatY"
495+
show NoRepeat = "NoRepeat"
496+
485497
foreign import createPatternImpl :: forall eff. CanvasImageSource -> String -> Context2D -> Eff (canvas :: Canvas | eff) CanvasPattern
486498

487499
-- | Create a new canvas pattern (repeatable image).
488500
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"
501+
createPattern img repeat = createPatternImpl img (toString repeat)
502+
where
503+
toString Repeat = "repeat"
504+
toString RepeatX = "repeat-x"
505+
toString RepeatY = "repeat-y"
506+
toString NoRepeat = "no-repeat"
493507

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

0 commit comments

Comments
 (0)