Copyright | (c) Pavel Krajcevski 2017 |
---|---|
License | MIT |
Maintainer | Krajcevski@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
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
- data Layout a
- data Children a
- startToEnd :: [Layout a] -> Children a
- endToStart :: [Layout a] -> Children a
- centered :: [Layout a] -> Children a
- spaceBetween :: [Layout a] -> Children a
- spaceAround :: [Layout a] -> Children a
- wrapped :: Children a -> Children a
- hbox :: Children a -> a -> Layout a
- vbox :: Children a -> a -> Layout a
- hboxLeftToRight :: Children a -> a -> Layout a
- hboxRightToLeft :: Children a -> a -> Layout a
- vboxTopToBottom :: Children a -> a -> Layout a
- vboxBottomToTop :: Children a -> a -> Layout a
- data Size
- shrinkable :: Float -> Size -> Size -> a -> Layout a
- growable :: Float -> Size -> Size -> a -> Layout a
- exact :: Float -> Float -> a -> Layout a
- data Edge
- stretched :: (b -> Layout a) -> b -> Layout a
- withMargin :: Edge -> Float -> (b -> Layout a) -> b -> Layout a
- withPadding :: Edge -> Float -> (b -> Layout a) -> b -> Layout a
- data LayoutInfo = LayoutInfo {}
- type RenderFn m a b = LayoutInfo -> a -> m b
- render :: (Functor m, Applicative m, Monad m) => Layout a -> RenderFn m a b -> m (Layout b)
- foldRender :: (Functor m, Applicative m, Monad m, Monoid b) => Layout a -> RenderFn m a (b, c) -> m (b, Layout c)
Main datatype
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.
Children layouts
These layouts describe the way that children are ordered and spaced within their parent.
Children are a list of layouts annotated with a style for how they should be laid out in their container.
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
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
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
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.
type RenderFn m a b = LayoutInfo -> a -> m b Source #
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 b
s and
a new layout with payloads of type c
.