data Language = English | French | German
toString English = "english"
toString French = "french"
toString German = "german"
greet English = "Hello"
greet French = "Salut"
greet German = "Hallo"
ui = (greet <$> (select "Language" (English :| [French, German]) toString))
<> pure " " <> string "Name" "Pierre" <> pure "!"
Example 7: Integration with Signals (Superformula)
plot m n1 s col time =
filled (fillColor col) $
path (map point angles)
where point phi = { x: 100.0 + radius phi * cos phi
, y: 100.0 + radius phi * sin phi }
angles = map (\i -> 2.0 * pi / toNumber points * toNumber i)
(0 .. points)
points = 400
n2 = s + 3.0 * sin (0.005 * time)
n3 = s + 3.0 * cos (0.005 * time)
radius phi = 20.0 * pow expr (- 1.0 / n1)
where expr = first + second
first = pow (abs (cos (m * phi / 4.0))) n2
second = pow (abs (sin (m * phi / 4.0))) n3
ui7 = plot <$> (numberSlider "m" 0.0 10.0 1.0 7.0)
<*> (numberSlider "n1" 1.0 10.0 0.1 4.0)
<*> (numberSlider "s" 4.0 16.0 0.1 14.0)
<*> (color "Color" (hsl 333.0 0.6 0.5))
<*> lift animationFrame
Example 8: Lists and sliders
traverse (intSlider_ 1 5) (1..5)
Example 9: Checkboxes
lift2 (&&) (boolean_ false) (boolean_ true)
Example 10: Folding over the past
graph xs width = outlined (outlineColor black <> lineWidth width)
(path points)
where points = zipWith point xs (1 .. length xs)
point x y = { x, y: toNumber y }
ui = graph <$> foldp cons [] (numberSlider "Position" 0.0 150.0 1.0 75.0)
<*> numberSlider "Width" 1.0 5.0 0.1 1.0
Example 11: Buttons
ui = foldp (+) 0 (button "Increment" 0 1)
Example 12: HTML output using Smolder
table h w = H.table $ foldMap row (0 .. h)
where row i = H.tr $ foldMap (cell i) (0 .. w)
cell i j = H.td (H.text (show i <> "," <> show j))
ui = table <$> intSlider_ 0 9 5 <*> intSlider_ 0 9 5
Example 13: Adding items to a list
actions = string "Add item:" "Orange" <**> button "Add" (flip const) cons
list = foldp id ["Apple", "Banana"] actions
ui = (H.ul <<< foldMap (H.li <<< H.text)) <$> list
Example 14: Color picker (running Flare inside Flare)