Skip to content

Instantly share code, notes, and snippets.

@tennety
Last active October 31, 2015 02:11
Show Gist options
  • Save tennety/12b8272fe0d61f9a379d to your computer and use it in GitHub Desktop.
Save tennety/12b8272fe0d61f9a379d to your computer and use it in GitHub Desktop.
understanding graphics checkboxes in Elm
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Graphics.Input exposing (..)
import Signal exposing (..)
import Color exposing (..)
checkRed : Signal.Mailbox Bool
checkRed = Signal.mailbox False
checkBlue : Signal.Mailbox Bool
checkBlue = Signal.mailbox False
checkGreen : Signal.Mailbox Bool
checkGreen = Signal.mailbox False
box: Bool -> Address Bool -> Element
box checked address =
container 40 40 middle (checkbox (Signal.message address) checked)
boxes: Bool -> Bool -> Bool -> Element
boxes red blue green =
flow down
[
flow right
[
box red checkRed.address
, box blue checkBlue.address
, box green checkGreen.address
]
, collage 200 100
[
colorBox red Color.red (-60.0, 0.0)
, colorBox blue Color.blue (0.0, 0.0)
, colorBox green Color.green (60.0, 0.0)
]
]
colorBox: Bool -> Color -> (Float, Float) -> Form
colorBox fill color position =
-- yeah, this can be written better. easier to read this way.
if fill
then (circle 20 |> filled color |> move position )
else (circle 20 |> traced (solid color) |> move position)
main : Signal Element
main = boxes <~ checkRed.signal ~ checkBlue.signal ~ checkGreen.signal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment