Portability | GHC with TypeFamilies and more |
---|---|

Stability | unstable |

Maintainer | stephen.tetley@gmail.com |

Type classes and derived functions to compose 2D *pictures*.

The operations are fairly standard - see Regions in Paul Hudak's 'The Haskell School of Expression' and the pretty printing libraries wl-pprint and Text.PrettyPrint.HughesPJ (pretty printing combinators are some ways in 'One and a half D' as they have horizontal operations but only carriage return in the vertical.

WARNING - this module may change in detail if not in spirit quite significantly in future.

These drawing operations are pretty fundamental and a compentent functional drawing program should provide them in some formulation. However the implementation herein needs some more thought.

- data HAlign
- data VAlign
- type family PUnit a
- class Horizontal a where
- class Vertical a where
- class Composite a where
- class Move a where
- class Blank a where
- center :: (Horizontal a, Vertical a, Fractional u, u ~ PUnit a) => a -> Point2 u
- topleft :: (Horizontal a, Vertical a, u ~ PUnit a) => a -> Point2 u
- topright :: (Horizontal a, Vertical a, u ~ PUnit a) => a -> Point2 u
- bottomleft :: (Horizontal a, Vertical a, u ~ PUnit a) => a -> Point2 u
- bottomright :: (Horizontal a, Vertical a, u ~ PUnit a) => a -> Point2 u
- (-@-) :: (Horizontal a, Vertical a, Composite a, Move a, Fractional u, u ~ PUnit a) => a -> a -> a
- (->-) :: (Horizontal a, Composite a, Num u, u ~ PUnit a) => a -> a -> a
- (-<-) :: (Horizontal a, Composite a, Num u, u ~ PUnit a) => a -> a -> a
- (-//-) :: (Vertical a, Composite a, Num u, u ~ PUnit a) => a -> a -> a
- above :: (Vertical a, Composite a, Num u, u ~ PUnit a) => a -> a -> a
- below :: (Vertical a, Composite a, Num u, u ~ PUnit a) => a -> a -> a
- at :: (Move a, u ~ PUnit a) => a -> Point2 u -> a
- centeredAt :: (Horizontal a, Vertical a, Move a, Composite a, Blank a, Fractional u, u ~ PUnit a) => a -> Point2 u -> a
- stackOnto :: Composite a => [a] -> a -> a
- hcat :: (Horizontal a, Composite a, Num u, u ~ PUnit a) => a -> [a] -> a
- vcat :: (Vertical a, Composite a, Num u, u ~ PUnit a) => a -> [a] -> a
- stackOntoCenter :: (Horizontal a, Vertical a, Composite a, Move a, Fractional u, u ~ PUnit a) => [a] -> a -> a
- hspace :: (Num u, Composite a, Horizontal a, Blank a, u ~ PUnit a) => u -> a -> a -> a
- vspace :: (Num u, Composite a, Vertical a, Blank a, u ~ PUnit a) => u -> a -> a -> a
- hsep :: (Num u, Composite a, Horizontal a, Blank a, u ~ PUnit a) => u -> a -> [a] -> a
- vsep :: (Num u, Composite a, Vertical a, Blank a, u ~ PUnit a) => u -> a -> [a] -> a
- alignH :: (Fractional u, Composite a, Horizontal a, Vertical a, Move a, u ~ PUnit a) => HAlign -> a -> a -> a
- alignV :: (Fractional u, Composite a, Horizontal a, Vertical a, Move a, u ~ PUnit a) => VAlign -> a -> a -> a
- hcatA :: (Fractional u, Horizontal a, Vertical a, Composite a, Move a, u ~ PUnit a) => HAlign -> a -> [a] -> a
- vcatA :: (Fractional u, Horizontal a, Vertical a, Composite a, Move a, u ~ PUnit a) => VAlign -> a -> [a] -> a
- hsepA :: (Fractional u, Horizontal a, Vertical a, Composite a, Move a, Blank a, u ~ PUnit a) => HAlign -> u -> a -> [a] -> a
- vsepA :: (Fractional u, Horizontal a, Vertical a, Composite a, Move a, Blank a, u ~ PUnit a) => VAlign -> u -> a -> [a] -> a
- multilabel :: (Fractional u, Ord u, TextLabel t) => t -> u -> VAlign -> [String] -> Point2 u -> Picture u

# Data types for alignment

Horizontal alignment - align to the top, center or bottom.

Vertical alignment - align to the left, center or bottom.

# Type family and classes

Move vertically.

a `over` b

Place 'picture' a over b. The idea of `over`

here is the same
as z-ordering in 2D design programs. Implementations of this
class should 'draw' picture a over b but move neither.

Similarly `beneath`

should 'draw' the first picture behind
the second but move neither.

Beneath has a default definition:

beneath = flip over

Move in both the horizontal and vertical.

Create a *picture* that has no content but occupies space
(i.e. it has a bounding box).

# Bounds

Corresponding operations are available on bounding boxes - the definitions here have different type class obligations.

center :: (Horizontal a, Vertical a, Fractional u, u ~ PUnit a) => a -> Point2 uSource

The center of a picture.

topleft :: (Horizontal a, Vertical a, u ~ PUnit a) => a -> Point2 uSource

Extract the top-left corner.

topright :: (Horizontal a, Vertical a, u ~ PUnit a) => a -> Point2 uSource

Extract the top-right corner.

bottomleft :: (Horizontal a, Vertical a, u ~ PUnit a) => a -> Point2 uSource

Extract the bottom-left corner.

bottomright :: (Horizontal a, Vertical a, u ~ PUnit a) => a -> Point2 uSource

Extract the bottom-right corner.

# Composition

(-@-) :: (Horizontal a, Vertical a, Composite a, Move a, Fractional u, u ~ PUnit a) => a -> a -> aSource

a -@- b

Center `a`

on top of `b`

, `a`

is potentially moved and drawn
`over`

`b`

.

(->-) :: (Horizontal a, Composite a, Num u, u ~ PUnit a) => a -> a -> aSource

a ->- b

Horizontal composition - move `b`

, placing it to the right
of `a`

.

(-<-) :: (Horizontal a, Composite a, Num u, u ~ PUnit a) => a -> a -> aSource

a -<- b

Horizontal composition - move `a`

, placing it to the left
of `b`

.

(-//-) :: (Vertical a, Composite a, Num u, u ~ PUnit a) => a -> a -> aSource

a -//- b

Vertical composition - move `b`

, placing it below `a`

.

above :: (Vertical a, Composite a, Num u, u ~ PUnit a) => a -> a -> aSource

a `above` b

Vertical composition - move `a`

, placing it above `b`

.

below :: (Vertical a, Composite a, Num u, u ~ PUnit a) => a -> a -> aSource

a `below` b

Vertical composition - move `a`

, placing it below `b`

centeredAt :: (Horizontal a, Vertical a, Move a, Composite a, Blank a, Fractional u, u ~ PUnit a) => a -> Point2 u -> aSource

Center the picture at the supplied point.

hcat :: (Horizontal a, Composite a, Num u, u ~ PUnit a) => a -> [a] -> aSource

x ->- xs

Concatenate the list pictures `xs`

horizontally with `(->-)`

starting at `x`

.

vcat :: (Vertical a, Composite a, Num u, u ~ PUnit a) => a -> [a] -> aSource

x -//- xs

Concatenate the list of pictures `xs`

vertically with `(-//-)`

starting at `x`

.

stackOntoCenter :: (Horizontal a, Vertical a, Composite a, Move a, Fractional u, u ~ PUnit a) => [a] -> a -> aSource

Stack pictures centered ontop of each other - the first picture in the list is drawn at the top, last picture is on drawn at the bottom.

hspace :: (Num u, Composite a, Horizontal a, Blank a, u ~ PUnit a) => u -> a -> a -> aSource

hspace n a b

Concatenate the pictures `a`

and `b`

with `(->-)`

- injecting
a space of `n`

units to separate the pictures.

vspace :: (Num u, Composite a, Vertical a, Blank a, u ~ PUnit a) => u -> a -> a -> aSource

vspace n a b

Concatenate the pictures `a`

and `b`

with `(-//-)`

- injecting
a space of `n`

units to separate the pictures.

hsep :: (Num u, Composite a, Horizontal a, Blank a, u ~ PUnit a) => u -> a -> [a] -> aSource

hsep n x xs

Concatenate the list of pictures `xs`

horizontally with
`hspace`

starting at `x`

. The pictures are interspersed with
spaces of `n`

units.

vsep :: (Num u, Composite a, Vertical a, Blank a, u ~ PUnit a) => u -> a -> [a] -> aSource

vsep n x xs

Concatenate the list of pictures `xs`

vertically with
`vspace`

starting at `x`

. The pictures are interspersed with
spaces of `n`

units.

# Compose with alignment

alignH :: (Fractional u, Composite a, Horizontal a, Vertical a, Move a, u ~ PUnit a) => HAlign -> a -> a -> aSource

alignH z a b

Move picture `b`

up or down to be horizontally aligned along a
line from the top, center or bottom of picture `a`

alignV :: (Fractional u, Composite a, Horizontal a, Vertical a, Move a, u ~ PUnit a) => VAlign -> a -> a -> aSource

alignV z a b

Move picture `b`

left or right to be vertically aligned along a
line from the left side, center or right side of picture `a`

hcatA :: (Fractional u, Horizontal a, Vertical a, Composite a, Move a, u ~ PUnit a) => HAlign -> a -> [a] -> aSource

Variant of `hcat`

that aligns the pictures as well as
concatenating them.

vcatA :: (Fractional u, Horizontal a, Vertical a, Composite a, Move a, u ~ PUnit a) => VAlign -> a -> [a] -> aSource

Variant of `vcat`

that aligns the pictures as well as
concatenating them.

hsepA :: (Fractional u, Horizontal a, Vertical a, Composite a, Move a, Blank a, u ~ PUnit a) => HAlign -> u -> a -> [a] -> aSource

Variant of `hsep`

that aligns the pictures as well as
concatenating and spacing them.

vsepA :: (Fractional u, Horizontal a, Vertical a, Composite a, Move a, Blank a, u ~ PUnit a) => VAlign -> u -> a -> [a] -> aSource

Variant of `vsep`

that aligns the pictures as well as
concatenating and spacing them.

# Special function for text

multilabel :: (Fractional u, Ord u, TextLabel t) => t -> u -> VAlign -> [String] -> Point2 u -> Picture uSource

Create multiple lines of text.

The dimension argument is the linespacing, measured as the distance between the upper lines descender and the lower lines ascender.

An error is throw if the list of strings is empty