shamansir / genui / GenUI

The core definition of the UI.

Core


type alias GenUI a =
{ version : String
, root : List (Property a) 
}

version : String

Current version, to be accessible from code.

Property


type alias PropertyRec a =
{ def : Def a
, name : String
, property : Maybe String
, live : Basics.Bool
, shape : Maybe CellShape
, triggerOn : Maybe Path
, statePath : Maybe Path 
}


type alias Property a =
( PropertyRec a, a )

root : a -> Property a

Truly optional to use. If you want to attach the controls to some common parrent, this is the way to do it. Don't use it anywhere in the tree except as in the root.

ghost : String -> a -> Property a

Create ghost with given name


type alias Path =
List String

A path to the property in the tree. So, all the first-level properties have the path of [0]. The second property that lies in the folder at index 3 has a path [0, 3, 1].


type alias IndexPath =
List Basics.Int

A path to the property in the tree. So, all the first-level properties have the path of [0]. The second property that lies in the folder at index 3 has a path [0, 3, 1].

get : Property a -> a

Get value of the property

Concrete property definitions


type Def a
    = Ghost
    | NumInt IntDef
    | NumFloat FloatDef
    | XY XYDef
    | Toggle ToggleDef
    | Color ColorDef
    | Textual TextualDef
    | Action ActionDef
    | Select SelectDef
    | Nest (NestDef a)
    | Gradient GradientDef
    | Progress ProgressDef
    | Zoom ZoomDef


type alias IntDef =
{ min : Basics.Int
, max : Basics.Int
, step : Basics.Int
, current : Basics.Int 
}


type alias FloatDef =
{ min : Basics.Float
, max : Basics.Float
, step : Basics.Float
, current : Basics.Float 
}


type alias XYDef =
{ x : FloatDef
, y : FloatDef 
}


type alias ToggleDef =
{ current : Basics.Bool }


type alias ColorDef =
{ current : Color }


type alias TextualDef =
{ current : String }


type alias ActionDef =
{ face : Face }


type alias GradientDef =
{ current : Gradient
, presets : List Color 
}


type alias ProgressDef =
{ api : Url }


type alias ZoomDef =
{ current : Basics.Float
, kind : ZoomKind 
}


type alias SelectDef =
{ current : String
, values : List SelectItem
, nestAt : Maybe String
, kind : SelectKind 
}


type alias NestDef a =
{ children : List (Property a)
, nestAt : Maybe String
, panel : Panel 
}

Folding

fold : (Property a -> x -> x) -> x -> GenUI a -> x

Fold the interface structure from top to bottom.

foldWithParent : (Maybe (Property a) -> Property a -> x -> x) -> x -> GenUI a -> x

Fold the interface structure from top to bottom. The first argument is the parent property and the second one is the property being folded itselfs.

foldWithPath : (Path -> Maybe (Property a) -> Property a -> x -> x) -> x -> GenUI a -> x

Fold the interface structure from top to bottom. The function gets property-path and the parent property and the second argument and the third one is the property being folded itself.

foldWithIndexPath : (IndexPath -> Maybe (Property a) -> Property a -> x -> x) -> x -> GenUI a -> x

Fold the interface structure from top to bottom. The function gets path and the parent property and the second argument and the third one is the property being folded itself.

foldWithPaths : (( IndexPath, Path ) -> Maybe (Property a) -> Property a -> x -> x) -> x -> GenUI a -> x

Fold the interface structure from top to bottom. The function gets index-path, property-name-path and the parent property and the second argument and the third one is the property being folded itself.

Find & Update

find : Path -> GenUI a -> Maybe (Property a)

Find property by property-based path. Traverses/folds the tree, so could be slow for a complex structure

findByIndices : Path -> GenUI a -> Maybe (Property a)

Find property by index-based path. Traverses/folds the tree, so could be slow for a complex structure

update : (( IndexPath, Path ) -> Property a -> Maybe (Property b)) -> GenUI a -> GenUI b

Update every property in the tree by applying the given function to it. If the function returns Nothing, the property is removed, even if it's a nesting.

updateAt : Path -> (Property a -> Maybe (Property a)) -> GenUI a -> GenUI a

Find property by property-based path and update it with given function. The function gets Nothing if the property wasn't found at path. Traverses/folds the tree, so could be slow for a complex structure

Helpers

withPath : GenUI a -> GenUI ( ( IndexPath, Path ), a )

Add path information to every property

withIndices : GenUI a -> GenUI ( Basics.Int, a )

Add unique numeric index to every property / control.

defToString : Def a -> String

Convert kind of the property to string, i.e. returns "int" for integer control and "xy" for XY control.

Subtypes


type Face
    = Empty
    | OfColor Color
    | OfIcon (List Icon)
    | Title
    | ExpandCollapse
    | Focus

The face of the UI cell, used for Tron UI.


type Unit
    = Half
    | One
    | OneAndAHalf
    | Two
    | Three
    | Custom Basics.Float

How much space takes the control in the Tron units


type alias CellShape =
{ horz : Unit, vert : Unit }

How many space takes the cell itself, used for Tron UI.


type SelectKind
    = Choice Panel
    | Knob
    | Switch

How the select switch looks and acts, used for Tron UI.


type alias SelectItem =
{ value : String
, face : Face
, name : Maybe String 
}

The item in the select box, a.k.a. option. value can be different from name, so if name exists, name should be shown to the user, but the value should be sent


type alias Icon =
{ theme : Theme, url : Url }

Icon: its theme and URL


type Form
    = Expanded
    | Collapsed


type Theme
    = Dark
    | Light

Icon theme: Light or Dark


type Url
    = Local String
    | Remote String

Icon URL: Remote or local


type Page
    = First
    | Last
    | ByCurrent
    | Page Basics.Int

Which page should be selected on the panel, if there's paging enabled


type Pages
    = Auto
    | Single
    | Distribute ({ maxInColumn : Cells, maxInRow : Cells })
    | Exact Basics.Int

How to distribute items over pages:


type alias Panel =
{ form : Form
, button : Face
, allOf : Maybe CellShape
, page : Page
, pages : Pages 
}


type alias Cells =
Basics.Int

The number of cells as the dimension of the panel


type ZoomKind
    = PlusMinus
    | Steps (List Basics.Float)

Mapping

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

mapProperty : (a -> b) -> Property a -> Property b

mapDef : (a -> b) -> Def a -> Def b