Skip to content

Commit

Permalink
Merge pull request #41 from diagrams/builder-cleanup
Browse files Browse the repository at this point in the history
Add Hashable instance for Options Cairo R2
  • Loading branch information
byorgey committed Jan 24, 2014
2 parents 0f5e399 + f676dcd commit b9c1776
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion diagrams-cairo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ Library
containers >= 0.3 && < 0.6,
lens >= 3.8 && < 4,
data-default-class >= 0.0.1 && < 0.1,
statestack >= 0.2 && < 0.3
statestack >= 0.2 && < 0.3,
hashable >= 1.1 && < 1.3
if impl(ghc < 7.6)
Build-depends: ghc-prim
default-language: Haskell2010

if !os(windows)
Expand Down
21 changes: 12 additions & 9 deletions src/Diagrams/Backend/Cairo/Internal.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -51,21 +52,19 @@ import Diagrams.TwoD.Text
import qualified Graphics.Rendering.Cairo as C
import qualified Graphics.Rendering.Cairo.Matrix as CM

import Control.Exception (try)
import Control.Lens hiding (transform, ( # ))
import Control.Monad (when)
import qualified Control.Monad.StateStack as SS
import Control.Monad.Trans (lift, liftIO)
import Data.Default.Class
import qualified Data.Foldable as F
import Data.Hashable (Hashable)
import Data.List (isSuffixOf)
import Data.Maybe (catMaybes, fromMaybe, isJust)
import Data.Tree

import Control.Lens hiding (transform, ( # ))

import Control.Exception (try)

import qualified Data.Foldable as F

import Data.Typeable
import GHC.Generics (Generic)

-- | This data declaration is simply used as a token to distinguish
-- the cairo backend: (1) when calling functions where the type
Expand All @@ -89,7 +88,9 @@ data OutputType =
-- action will do nothing, but the @Render ()@
-- action can be used (/e.g./ to draw to a Gtk
-- window; see the @diagrams-gtk@ package).
deriving (Eq, Ord, Read, Show, Bounded, Enum, Typeable)
deriving (Eq, Ord, Read, Show, Bounded, Enum, Typeable, Generic)

instance Hashable OutputType

-- | Custom state tracked in the 'RenderM' monad.
data CairoState
Expand Down Expand Up @@ -141,7 +142,7 @@ instance Backend Cairo R2 where
, _cairoOutputType :: OutputType -- ^ the output format and associated options
, _cairoBypassAdjust :: Bool -- ^ Should the 'adjustDia' step be bypassed during rendering?
}
deriving Show
deriving (Show, Generic)

doRender _ (CairoOptions file size out _) (C r) = (renderIO, r')
where r' = runRenderM r
Expand Down Expand Up @@ -185,6 +186,8 @@ instance Monoid (Render Cairo R2) where
mempty = C $ return ()
(C rd1) `mappend` (C rd2) = C (rd1 >> rd2)

instance Hashable (Options Cairo R2)

renderRTree :: RTree Cairo R2 a -> Render Cairo R2
renderRTree (Node (RPrim accTr p) _) = render Cairo (transform accTr p)
renderRTree (Node (RStyle sty) ts) = C $ do
Expand Down

0 comments on commit b9c1776

Please sign in to comment.