Skip to content

Commit

Permalink
D.Attributes: export utility functions mk{Fill,Line}Color
Browse files Browse the repository at this point in the history
These are intentionally not re-exported from the Prelude; most users
should not need them.
  • Loading branch information
Brent Yorgey committed Nov 14, 2013
1 parent 9a89228 commit a9339c6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Diagrams/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ module Diagrams.Attributes (
Color(..), SomeColor(..), someToAlpha

-- ** Line color
, LineColor, getLineColor, lineColor, lineColorA, lc, lcA
, LineColor, getLineColor, mkLineColor, lineColor, lineColorA, lc, lcA

-- ** Fill color
, FillColor, getFillColor, recommendFillColor, fillColor, fc, fcA
, FillColor, getFillColor, mkFillColor, recommendFillColor, fillColor, fc, fcA

-- ** Opacity
, Opacity, getOpacity, opacity
Expand Down Expand Up @@ -117,13 +117,16 @@ instance Default LineColor where
getLineColor :: LineColor -> SomeColor
getLineColor (LineColor (Last c)) = c

mkLineColor :: Color c => c -> LineColor
mkLineColor = LineColor . Last . SomeColor

-- | Set the line (stroke) color. This function is polymorphic in the
-- color type (so it can be used with either 'Colour' or
-- 'AlphaColour'), but this can sometimes create problems for type
-- inference, so the 'lc' and 'lcA' variants are provided with more
-- concrete types.
lineColor :: (Color c, HasStyle a) => c -> a -> a
lineColor = applyAttr . LineColor . Last . SomeColor
lineColor = applyAttr . mkLineColor

-- | Apply a 'lineColor' attribute.
lineColorA :: HasStyle a => LineColor -> a -> a
Expand All @@ -148,12 +151,15 @@ newtype FillColor = FillColor (Recommend (Last SomeColor))
deriving (Typeable, Semigroup)
instance AttributeClass FillColor

mkFillColor :: Color c => c -> FillColor
mkFillColor = FillColor . Commit . Last . SomeColor

-- | Set the fill color. This function is polymorphic in the color
-- type (so it can be used with either 'Colour' or 'AlphaColour'),
-- but this can sometimes create problems for type inference, so the
-- 'fc' and 'fcA' variants are provided with more concrete types.
fillColor :: (Color c, HasStyle a) => c -> a -> a
fillColor = applyAttr . FillColor . Commit . Last . SomeColor
fillColor = applyAttr . mkFillColor

-- | Set a \"recommended\" fill color, to be used only if no explicit
-- calls to 'fillColor' (or 'fc', or 'fcA') are used.
Expand Down

0 comments on commit a9339c6

Please sign in to comment.