Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- renderData :: (Monad m, Renderable a, Monoid (RenderTfrm a)) => Cache m (RenderTfrm a) -> a -> m ()
- renderDataHidden :: (Renderable a, Monad m, Monoid (RenderTfrm a)) => Cache m (RenderTfrm a) -> RenderTfrm a -> a -> m ()
- renderComposite :: (Monad m, Monoid t) => Cache m t -> t -> Composite t -> m ()
- attachIfNeeded :: (Renderable a, Monad (RenderMonad a), Monoid (RenderTfrm a), Hashable a) => RenderRsrc a -> Cache (RenderMonad a) (RenderTfrm a) -> a -> RenderMonad a (Cache (RenderMonad a) (RenderTfrm a))
- detachUnused :: (Monad m, Renderable a) => Cache m t -> a -> m (Cache m t)
- detach :: Monad m => Cache m t -> Int -> m (Cache m t)
- class Decomposable a m r t where
- data Element m r t where
- Element :: (Monad m, Show a, Hashable a, Renderable a, m ~ RenderMonad a, r ~ RenderRsrc a, t ~ RenderTfrm a) => a -> Element m r t
- class Renderable a where
- type RenderMonad a :: * -> *
- type RenderTfrm a :: *
- type RenderRsrc a :: *
- nameOf :: a -> String
- cache :: (Monad (RenderMonad a), Monoid (RenderTfrm a)) => RenderRsrc a -> Cache (RenderMonad a) (RenderTfrm a) -> a -> RenderMonad a (Cache (RenderMonad a) (RenderTfrm a))
- composite :: a -> Composite (RenderTfrm a)
- type Cache m t = IntMap (Rendering m t)
- data Rendering m t = Rendering {}
- type Composite a = [(Int, Maybe a)]
Documentation
renderData :: (Monad m, Renderable a, Monoid (RenderTfrm a)) => Cache m (RenderTfrm a) -> a -> m () Source
Render a datatype using renderings stored in the given cache.
renderDataHidden :: (Renderable a, Monad m, Monoid (RenderTfrm a)) => Cache m (RenderTfrm a) -> RenderTfrm a -> a -> m () Source
Render only the hidden layers of a datatype using renderings stored in the given cache. This is sometimes useful for debugging.
renderComposite :: (Monad m, Monoid t) => Cache m t -> t -> Composite t -> m () Source
Render the composite of a datatype using renderings stored in the given cache.
attachIfNeeded :: (Renderable a, Monad (RenderMonad a), Monoid (RenderTfrm a), Hashable a) => RenderRsrc a -> Cache (RenderMonad a) (RenderTfrm a) -> a -> RenderMonad a (Cache (RenderMonad a) (RenderTfrm a)) Source
If needed, create a new rendering given some resources, insert it in the cache and return the new cache.
detachUnused :: (Monad m, Renderable a) => Cache m t -> a -> m (Cache m t) Source
Detach any renderings that are not needed to render the given data.
detach :: Monad m => Cache m t -> Int -> m (Cache m t) Source
Remove a rendering from a cache and clean up the resources allocated for that rendering.
class Decomposable a m r t where Source
An instance of Decomposable can be broken down into a number of elements.
Decomposable (Element m r t) m r t Source | Any element is decomposable by returning a list consisting of itself. |
data Element m r t where Source
Element is a generic existential type that can be used to enclose
instances of Renderable in order to contain them all in a heterogeneous list.
m
, r
and t
must be shared with all Renderable instances stored in
a heterogeneous list of Elements.
Element :: (Monad m, Show a, Hashable a, Renderable a, m ~ RenderMonad a, r ~ RenderRsrc a, t ~ RenderTfrm a) => a -> Element m r t |
Eq (Element m r t) Source | |
Show (Element m r t) Source | |
Hashable (Element m r t) Source | |
Renderable (Element m r t) Source | Any Element is renderable by rendering its contained datatype. |
Decomposable (Element m r t) m r t Source | Any element is decomposable by returning a list consisting of itself. |
type RenderMonad (Element m r t) = m Source | |
type RenderTfrm (Element m r t) = t Source | |
type RenderRsrc (Element m r t) = r Source |
class Renderable a where Source
type RenderMonad a :: * -> * Source
The monad needed to render the datatype. In most cases this is probably IO.
type RenderTfrm a :: * Source
The datatype that is used to transform renderings.
type RenderRsrc a :: * Source
The datatype that holds cached resources that will be used to composite and render the datatype.
The name of a renderable datatype. This is mostly for debugging.
cache :: (Monad (RenderMonad a), Monoid (RenderTfrm a)) => RenderRsrc a -> Cache (RenderMonad a) (RenderTfrm a) -> a -> RenderMonad a (Cache (RenderMonad a) (RenderTfrm a)) Source
Store the rendering of a datatype in a cache keyed by the hash of that datatype. Returns the new cache.
composite :: a -> Composite (RenderTfrm a) Source
The entire composite list of renderings for a given datatype.
(Renderable a, Hashable a) => Renderable [a] Source | A list of renderable instances is renderable by rendering each instance. |
(Renderable a, Hashable a, Show a) => Renderable (Maybe a) Source | A Maybe is renderable by rendering the datatype contained in the Just constructor or by rendering nothing. |
((~) * t (RenderTfrm a), Show t, Monoid t, Hashable a, Renderable a) => Renderable (t, a) Source | A tuple is renderable when it is a pairing of a transform and another renderable datatype. |
Renderable (Element m r t) Source | Any Element is renderable by rendering its contained datatype. |
A rendering is a type that contains some effectful computation for displaying something given a transform. It also contains an effectful computation for cleaning up any resources allocated during its creation.
type Composite a = [(Int, Maybe a)] Source
A composite is a representation of the entire rendered datatype. It is
a flattened list of all the renderings (denoted by hash), along with
that rendering's local transformation. If a rendering is explicitly run
by another rendering (as in a Renderable class definition) then the
transformation for that rendering should be Nothing, which will keep
renderComposite
from running that rendering in addition to the
rendering its included in. For example:
[(0, Just $ Transform (10,10) (0.5,0.5) 0)
,(1, Nothing)
]
The above is a composite of two renderings, the first will be rendered
by renderComposite
using the given transform while the second is
effectively hidden but present. Being present in the composite will keep
detachUnused
from detaching and cleaning the rendering.