shamansir / tron-gui / WithTron.ValueAt

ValueAt is the way to extract values from the Tree x or Tron x.

Using ask and any Decoder you don't have to worry what Value is, just do:

tree |> ask (xy [ "Goose", "Eye" ])

And get Maybe (Float, Float) in response. Same works for any of the decoders below:

tree |> ask (toggle [ "Goose", "Punk" ]) -- returns `Maybe Bool`
tree |> ask (choice [ "Color Scheme", "Product" ]) -- returns `Maybe (ItemId, Path.Label)`
tree |> ask (choiceOf Products.all [ "Color Scheme", "Product" ]) -- returns `Maybe Product`
    -- NB: Just ensure to use the very same list you used for creating the `choice` in this case
tree |> ask (color [ "Feather", "Color" ]) -- returns `Maybe Color`
-- and so on...

For the example of such, see example/ForTiler, where the structure/state of GUI is dependent on current values, but also doesn't store them in its own model, since mostly connects to JavaScript.

See also: Tron.Tree.

Asking values at path

at : List Tron.Path.Label -> Tron.Tree.Tree a -> Maybe Tron.Control.Value.Value

Actually, all the possible ways to get your value as a common type:

atKnob : Basics.Float -> List Tron.Path.Label -> Tron.Tree.Tree x -> Basics.Float

atXY : ( Basics.Float, Basics.Float ) -> List Tron.Path.Label -> Tron.Tree.Tree x -> ( Basics.Float, Basics.Float )

atText : String -> List Tron.Path.Label -> Tron.Tree.Tree x -> String

atToggle : (Basics.Bool -> a) -> a -> List Tron.Path.Label -> Tron.Tree.Tree x -> a

atColor : Color -> List Tron.Path.Label -> Tron.Tree.Tree x -> Color

atChoice : (( Tron.Control.Impl.Nest.ItemId, Maybe Tron.Path.Label ) -> a) -> a -> List Tron.Path.Label -> Tron.Tree.Tree x -> a

atChoiceOf : List a -> a -> List Tron.Path.Label -> Tron.Tree.Tree x -> a

Ask using decoders

ask : Decoder a -> Tron.Tree.Tree x -> Maybe a

Load value from the tree using the decoder, and if it's there, you'll get it:

tree |> ask (xy [ "Goose", "Eye" ]) -- returns `Maybe (Float, Float)`

number : List Tron.Path.Label -> Decoder Basics.Float

Load number value by path: works both for Builr.int & Build.float

xy : List Tron.Path.Label -> Decoder ( Basics.Float, Basics.Float )

Load XY value by path

text : List Tron.Path.Label -> Decoder String

Load text value by path

toggle : List Tron.Path.Label -> Decoder Basics.Bool

Load Toggle value by path.

color : List Tron.Path.Label -> Decoder Color

Load color value by path.

action : List Tron.Path.Label -> Decoder ()

Has a little sense, but still there. Could be named absurd. Check, if button was pressed at least once.

choice : List Tron.Path.Label -> Decoder ( Tron.Control.Impl.Nest.ItemId, Maybe Tron.Path.Label )

Load chosen item ID (which is Int) by path. Use choiceOf to get the actual value.

choiceOf : List a -> List Tron.Path.Label -> Decoder a

Load chosen value by path. NB: Ensure to use the very same list you used for creating the choice in this case.

Decode


type Decoder a

The decoder that knows how to extract a value at the certain path.

Common helpers

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

Common map function for decoder.