A path is the location of a branch in a tree (or forest). With this package you can use paths to navigate and alter a zwilias/elm-rosetree or a list of them, also called a "forest".
A Tree.Zipper can also focus a specific node in a tree.
However! Paths can be a nice alternative if you want to
Msges with potentially large, changing tree contentExample: There's a big tree on the screen. You want to be able to move and delete a subtree.
See in example.
import Tree.Path exposing (TreePath)
import Tree.Navigate
type alias Model =
{ tree : Tree { translate : ( Float, Float ) }
, dragged : Maybe TreePath
}
viewTree =
Tree.restructure
(\sub ->
(sub.label
|> ...
|> onMouseDown (PressedOn sub.path)
|> onRightClick (RightClickedOn sub.path)
)
:: sub.children
|> group
|> shift sub.label.translate
)
type Msg =
= RightClickedOn TreePath
| MouseMoved ( Float, Float )
--| ...
update msg model =
case msg of
RightClickedOn path ->
{ model
| tree =
model.tree
|> Tree.mapChildren
(Tree.Navigate.remove path)
}
MouseMoved mousePosition ->
case model.dragged of
Just path ->
{ model
| tree =
Tree.Navigate.alter path
(Tree.mapLabel
(\l -> { l | translate = ... })
)
}
Nothing ->
model
--...