shamansir / tron-gui / Tron.Tree

The Tree a is the structure of the components of your GUI. Also, it stores some a subject with every control.

You get the Tree () as the previous state of controls in for and other functions like update and view, when you use WithTron helpers, so that you may get their previos values using WithTron.ValueAt.

Tron msg, on the other side, is just Tree (Control.Value -> Maybe msg), so every control strores the handler that convers its value to the messages. It is the structure you return from for function so that the system knows what messages to produce in response.

See also: WithTron.ValueAt.

Types


type alias Tree a =
Internals.Tree a

Empty

empty : Tree ()

Create the empty tree. Has to store something though, let it be ().

Mappings, zips & folds

map : (a -> b) -> Tree a -> Tree b

mapWithPath : (Tron.Path.Path -> a -> b) -> Tree a -> Tree b

mapWithValue : (Tron.Path.Path -> Tron.Control.Value.Value -> a -> b) -> Tree a -> Tree b

zip : (Maybe a -> Maybe b -> c) -> Tree a -> Tree b -> Tree c

zip maps two GUI trees with given fn; if tree structure doesn't match while zipping, the corresponding Maybes become Nothing. NB: When two controls match at the same place in two given trees, the state is taken from the second (right) one.

fold : (Tron.Path.Path -> Tree a -> b -> b) -> b -> Tree a -> b

Goes through all the inner components of the Tree (as deep as there is some non-nested component) and calls the function for every of those, folding them into one structure.

unfold : Tree a -> List ( Tron.Path.Path, Tree a )

Convert the tree to the full plane list of its components. So it goes as deep as there is some non-nested component and adds it to the list as well as its parent.

Bindings

andThen : (a -> Tree b) -> Tree a -> Tree b

with : (a -> Tree a -> Tree b) -> Tree a -> Tree b

Same as andThen, but also passes the same current property to the function. It helps in chaining things in Tree.Build.* and Tron.Build.

Convert

toUnit : Tree a -> Tree ()

Replace the subject everywhere within Tron GUI tree with (), it is useful for truly a lot of cases when you don't care about what are the associated values.

proxify : Tree a -> Tree Tron.Control.Value.Value

Replace the subject everywhere within Tron GUI tree with the associated Control.Value.

pathify : Tree a -> Tree Tron.Path.Path

Replace the subject everywhere within Tron GUI tree with the associated Control.Value.

Get value

get : Tree a -> a

Get the subject of the top-level component.

getValue : Tree a -> Tron.Control.Value.Value

get proxied value from Tron

Apply value

apply : Tree (Tron.Control.Value.Value -> Maybe a) -> Tree (Maybe a)

Take the Tree with a handler and call this handler for every control, storing the produced a as the subject. Usually, it is done to calculate msg at this place, as with Tron msg == Tree (Control.Value -> Maybe msg).