sneathlane-haste-2: A compositional web UI library, which draws to a Canvas element

Safe HaskellNone





data Widget f z Source

Atom of a sneath lane application


Finish z 
Continue (f (OutputFn f z)) (Maybe (MouseOut (Widget f z))) (Maybe (Animate (Widget f z))) (WidgetFocus f z) 

data WidgetFocus f z Source

Determines the focus behavior of the widget



Widget can not take keyboard focus

Focusable (Widget f z) (Widget f z)

Widget can take keyboard focus, but does not have it now

Focused (Widget f z) (Widget f z, Bool) (Widget f z, Bool) (HandleKey (Widget f z))

Widget has keyboard focus

zipW :: (Functor f, Functor g, Functor h) => (f (OutputFn h z) -> g (OutputFn h z) -> h (OutputFn h z)) -> Widget f z -> Widget g z -> Widget h z Source

Combine two widgets to run in parallel as a single widget

Build Widgets

graphicWidget :: Functor f => Maybe String -> f () -> Widget f a Source

A widget which just shows a constant graphic output.

above :: Widget GraphicTree z -> Widget GraphicTree z -> Widget GraphicTree z Source

Combine two widgets one above the other

beside :: Widget GraphicTree z -> Widget GraphicTree z -> Widget GraphicTree z Source

Combine two widgets side by side

mapGraphic :: Functor f1 => (f1 (MouseEv -> (Maybe String, Widget f z)) -> f (OutputFn f z)) -> Widget f1 z -> Widget f z Source

mapWidgetFocus :: (Widget t t1 -> Widget f z) -> WidgetFocus t t1 -> WidgetFocus f z Source

Run Widgets

runOnCanvas :: (forall z. Double -> Widget GraphicTree z) -> IO () Source

Create a Canvas element filling the browser viewport, and run the given Widget there


data GraphicTree :: * -> * where Source

A tree of graphics, used as widget output type. FMap functions are stored in the tree instead of being mapped over the leaves, so that tree reconstruction is fast when a widget changes. This is why GraphicTree is a GADT.

Offset: a sub-tree translated by a point

Branch: Two sub-trees; graphicTreeBounds are cached for each

Leaf: A leaf, consisting of a single graphic element

FMap: A graphic tree composed with a function.


Clip :: Rect -> GraphicTree a -> GraphicTree a 
Offset :: Point -> GraphicTree a -> GraphicTree a 
Branch :: Rect -> GraphicTree a -> Rect -> GraphicTree a -> GraphicTree a 
Leaf :: Graphic -> GraphicTree () 
FMap :: (a -> b) -> GraphicTree a -> GraphicTree b 

graphicList :: [Graphic] -> GraphicTree () Source

Construct a graphic tree from a nonempty list of graphics.

graphicTreeBounds :: GraphicTree a -> Rect Source

Find a rectangle containing the entire contents of the graphic tree


data MouseButton Source

Which mouse button (if any) was being pressed




balancedFold :: (a -> a -> a) -> [a] -> a Source

Apply a fold in a balanced fashion over a list. Recommended for combining lists of widgets, so that the widget tree has logarithmic depth.

Type synonyms

type OutputFn f z = MouseEv -> (Maybe String, Widget f z) Source

type MouseOut a = a Source

type HandleKey a = Key -> a Source