Pebble.Companion.Preferences
Typed declarations for Pebble companion preference pages.
The same schema describes the generated, Slate-like configuration page and the decoder used when Pebble returns saved values.
type alias Settings =
{ showDate : Bool
, units : Units
}
type Units
= Celsius
| Fahrenheit
settings : Schema Settings
settings =
schema "Settings" Settings
|> section "Display"
(\s ->
s
|> field "showDate" (toggle "Show date" True)
|> field "units"
(choice "Units"
[ choiceOption Celsius "c" "Celsius"
, choiceOption Fahrenheit "f" "Fahrenheit"
]
)
)Native Pebble C API
- Preferences on developer.repebble.com
Schemas
Schema
type Schema settingsOpaque preference schema that decodes to settings.
Error
type Error
= InvalidJson String
| MissingResponseDecode errors from a saved configuration payload.
schema
schema : String -> settings -> Schema settingsStart a schema with a record or custom type constructor.
section
section : String -> (Schema partial -> Schema next) -> Schema partial -> Schema nextAdd a visual section. Fields added inside the callback are grouped under the section title.
field
field : String -> Control value -> Schema (value -> next) -> Schema nextAdd a typed field to the schema.
Fields are decoded in the order they are added, so this works naturally with Elm record constructors and normal pipeline style.
decoder
decoder : Schema settings -> Decoder settingsDecode the saved Pebble webview payload.
decodeString
decodeString : Schema settings -> String -> Result Error settingsDecode a saved JSON string into typed settings.
decodeResponse
decodeResponse : Schema settings -> Maybe String -> Result Error settingsDecode Pebble's optional webviewclosed response into typed settings.
Controls
Control
type Control valueA typed control for a single field.
Field
type Field valueA typed field. The generator uses the definition; Elm code uses the decoder.
Section
type alias Section =
{ title : String
, fields : List FieldDefinition
}A visual group of fields.
toggle
toggle : String -> Bool -> Control BoolA boolean toggle.
text
text : String -> String -> Control StringA text input.
number
number : String -> Float -> Control FloatA numeric input.
slider
slider : String -> { min : Float, max : Float, step : Float, default : Float } -> Control FloatA slider with minimum, maximum, step, and default values.
color
color : String -> Color -> Control ColorA color picker encoded as a CSS hex string.
choice
choice : String -> List (ChoiceOption value) -> Control valueA select/radio-style choice that decodes to real Elm values.
ChoiceOption
type ChoiceOption valueA choice option mapping an encoded webview value to a real Elm value.
choiceOption
choiceOption : value -> String -> String -> ChoiceOption valueDefine one encoded choice value and the Elm value it represents.
sendToWatch
sendToWatch : String -> Control value -> Control valueDeclare the phone-to-watch message constructor emitted when this preference is saved.
This is debugger/build metadata; the typed decoder still determines the Elm value seen by the companion app.
Colors
Color
type alias Color = StringPebble configuration color value encoded as a CSS hex string.
black
black : ColorBlack color swatch.
white
white : ColorWhite color swatch.
green
green : ColorGreen color swatch.
blue
blue : ColorBlue color swatch.
yellow
yellow : ColorYellow color swatch.