yoga-0.0.0.1: Bindings to Facebook's Yoga layout library

Copyright(c) Pavel Krajcevski 2017
LicenseMIT
MaintainerKrajcevski@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Yoga

Contents

Description

This module holds a high-level interface to the bindings associated with this library that are maintained in Bindings.Yoga. Application developers will likely want to use this module to interface with the library, but are available to use the C-level bindings if more control is desired.

These bindings are not affiliated with Facebook in any way, and have been developed separately for the sole purpose of interfacing with their open source library.

Full documentation can be found at http://facebook.github.io/yoga

Synopsis

Main datatype

data Layout a Source #

The main datatype in the high level bindings is a Layout. Layouts are used to store a tree of nodes that represent the different components of a layout. Layouts can be composed by adding one as a sub-tree to another. The parent-child relationship dictates different parameters such as width, height and position. This type is opaque to the user in order to facilitate updates to the library. For more control, use the C-level bindings in Yoga.Bindings.

Instances

Functor Layout Source # 

Methods

fmap :: (a -> b) -> Layout a -> Layout b #

(<$) :: a -> Layout b -> Layout a #

Foldable Layout Source # 

Methods

fold :: Monoid m => Layout m -> m #

foldMap :: Monoid m => (a -> m) -> Layout a -> m #

foldr :: (a -> b -> b) -> b -> Layout a -> b #

foldr' :: (a -> b -> b) -> b -> Layout a -> b #

foldl :: (b -> a -> b) -> b -> Layout a -> b #

foldl' :: (b -> a -> b) -> b -> Layout a -> b #

foldr1 :: (a -> a -> a) -> Layout a -> a #

foldl1 :: (a -> a -> a) -> Layout a -> a #

toList :: Layout a -> [a] #

null :: Layout a -> Bool #

length :: Layout a -> Int #

elem :: Eq a => a -> Layout a -> Bool #

maximum :: Ord a => Layout a -> a #

minimum :: Ord a => Layout a -> a #

sum :: Num a => Layout a -> a #

product :: Num a => Layout a -> a #

Traversable Layout Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Layout a -> f (Layout b) #

sequenceA :: Applicative f => Layout (f a) -> f (Layout a) #

mapM :: Monad m => (a -> m b) -> Layout a -> m (Layout b) #

sequence :: Monad m => Layout (m a) -> m (Layout a) #

Eq a => Eq (Layout a) Source # 

Methods

(==) :: Layout a -> Layout a -> Bool #

(/=) :: Layout a -> Layout a -> Bool #

Ord a => Ord (Layout a) Source # 

Methods

compare :: Layout a -> Layout a -> Ordering #

(<) :: Layout a -> Layout a -> Bool #

(<=) :: Layout a -> Layout a -> Bool #

(>) :: Layout a -> Layout a -> Bool #

(>=) :: Layout a -> Layout a -> Bool #

max :: Layout a -> Layout a -> Layout a #

min :: Layout a -> Layout a -> Layout a #

Show a => Show (Layout a) Source # 

Methods

showsPrec :: Int -> Layout a -> ShowS #

show :: Layout a -> String #

showList :: [Layout a] -> ShowS #

Children layouts

These layouts describe the way that children are ordered and spaced within their parent.

data Children a Source #

Children are a list of layouts annotated with a style for how they should be laid out in their container.

Instances

Eq a => Eq (Children a) Source # 

Methods

(==) :: Children a -> Children a -> Bool #

(/=) :: Children a -> Children a -> Bool #

Ord a => Ord (Children a) Source # 

Methods

compare :: Children a -> Children a -> Ordering #

(<) :: Children a -> Children a -> Bool #

(<=) :: Children a -> Children a -> Bool #

(>) :: Children a -> Children a -> Bool #

(>=) :: Children a -> Children a -> Bool #

max :: Children a -> Children a -> Children a #

min :: Children a -> Children a -> Children a #

Show a => Show (Children a) Source # 

Methods

showsPrec :: Int -> Children a -> ShowS #

show :: Children a -> String #

showList :: [Children a] -> ShowS #

startToEnd :: [Layout a] -> Children a Source #

Collects a list of layouts and orients them from start to end depending on the orientation of the parent (LTR vs RTL).

endToStart :: [Layout a] -> Children a Source #

Collects a list of layouts and orients them from end to start depending on the orientation of the parent (LTR vs RTL).

centered :: [Layout a] -> Children a Source #

Collects a list of children and centers them within the parent.

spaceBetween :: [Layout a] -> Children a Source #

Collects a list of children that span the parent such that the space between each child is equal

spaceAround :: [Layout a] -> Children a Source #

Collects a list of children that span the parent such that the space to the left and right of each child is equal.

wrapped :: Children a -> Children a Source #

Permits children to wrap to a new line if they exceed the bounds of their parent

Containers

hbox :: Children a -> a -> Layout a Source #

Generates a layout from a group of children and a payload such that the children are laid out horizontally. The orientation (RTL vs LTR) is inherited from the parent

vbox :: Children a -> a -> Layout a Source #

Generates a layout from a group of children and a payload such that the children are laid out vertically. The orientation (top to bottom vs bottom to top) is inherited from the parent.

hboxLeftToRight :: Children a -> a -> Layout a Source #

Generates a layout from a group of children and a payload such that the children are laid out horizontally from left to right.

hboxRightToLeft :: Children a -> a -> Layout a Source #

Generates a layout from a group of children and a payload such that the children are laid out horizontally from right to left.

vboxTopToBottom :: Children a -> a -> Layout a Source #

Generates a layout from a group of children and a payload such that the children are laid out vertically from top to bottom.

vboxBottomToTop :: Children a -> a -> Layout a Source #

Generates a layout from a group of children and a payload such that the children are laid out vertically from bottom to top.

Leaf nodes

data Size Source #

A Size is used to set properties about given layouts. In general, the width and height of a node along with its position are laid out by Yoga's internal layout engine. However, the user may decide to set limits on how much internal nodes can shrink or grow. This datatype controls those properties

Instances

shrinkable :: Float -> Size -> Size -> a -> Layout a Source #

Creates a layout that may shrink up to the given size. The weight parameter is used to determine how much this layout will shrink in relation to any siblings.

growable :: Float -> Size -> Size -> a -> Layout a Source #

Creates a layout that may grow up to the given size. The weight parameter is used to determine how much this layout will grow in relation to any siblings.

exact :: Float -> Float -> a -> Layout a Source #

Creates a layout with the exact width and height for the given payload.

Attributes

data Edge Source #

Edges are used to describe the direction from which we want to alter an attribute of a node. They are currently only being used with withMargin and withPadding.

stretched :: (b -> Layout a) -> b -> Layout a Source #

Allows a container to stretch to fit its parent

withMargin :: Edge -> Float -> (b -> Layout a) -> b -> Layout a Source #

Transforms a layout generator to one which applies the given margin using continuation passing style. In this way we maintain the const-ness of layout nodes. E.g.:

let lyt = ($ payload) (withMargin Edge'Left 10.0 $ exact 200.0 300.0)

withPadding :: Edge -> Float -> (b -> Layout a) -> b -> Layout a Source #

Transforms a layout generator to one which applies the given padding using continuation passing style. In this way we maintain the const-ness of layout nodes. E.g.:

let lyt = ($ payload) (withPadding Edge'Left 10.0 $ exact 200.0 300.0)

Rendering

data LayoutInfo Source #

Stores the calculated layout information for a given node. During rendering, the rendering function will take the payload and layout info to facilitate the renderer to do whatever it needs to with the given layout calculations.

Constructors

LayoutInfo 

Fields

type RenderFn m a b = LayoutInfo -> a -> m b Source #

A RenderFn takes a top-left position and a width and height of a node with the given payload. The function is expected to perform some monadic action in the Monad m, and return a new payload of type b. This function is called on each node in order during a call to render.

render :: (Functor m, Applicative m, Monad m) => Layout a -> RenderFn m a b -> m (Layout b) Source #

Renders a layout with the user-supplied function. The renderer traverses the tree from root node to children and transforms each payload using the user-supplied function.

foldRender :: (Functor m, Applicative m, Monad m, Monoid b) => Layout a -> RenderFn m a (b, c) -> m (b, Layout c) Source #

Renders a layout with the user-supplied function. For each return value of type '(b, c)', we append the first result to the output of the previous node. The second result is stored as the new payload for the given node. Hence, the resulting monadic action produces a mappend-ed set of bs and a new layout with payloads of type c.