Skip to content
This repository has been archived by the owner on Aug 23, 2018. It is now read-only.

Commit

Permalink
use FontAwesome icons instead of PNGs for buttons
Browse files Browse the repository at this point in the history
FontAwesome.elm is ~330kb
  • Loading branch information
vilterp committed Jun 25, 2015
1 parent 821e476 commit 5cf14c9
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 29 deletions.
Binary file removed assets/_reactor/debugger/pause-button-down.png
Binary file not shown.
Binary file removed assets/_reactor/debugger/pause-button-hover.png
Binary file not shown.
Binary file removed assets/_reactor/debugger/pause-button-up.png
Binary file not shown.
Binary file removed assets/_reactor/debugger/play-button-down.png
Binary file not shown.
Binary file removed assets/_reactor/debugger/play-button-hover.png
Binary file not shown.
Binary file removed assets/_reactor/debugger/play-button-up.png
Binary file not shown.
Binary file removed assets/_reactor/debugger/restart-button-down.png
Binary file not shown.
Binary file removed assets/_reactor/debugger/restart-button-hover.png
Binary file not shown.
Binary file removed assets/_reactor/debugger/restart-button-up.png
Binary file not shown.
3 changes: 2 additions & 1 deletion elm-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"dependencies": {
"elm-lang/core": "2.0.0 <= v < 3.0.0",
"evancz/elm-html": "3.0.0 <= v < 4.0.0",
"evancz/elm-markdown": "1.1.4 <= v < 2.0.0"
"evancz/elm-markdown": "1.1.4 <= v < 2.0.0",
"jystic/elm-font-awesome": "1.0.0 <= v < 2.0.0"
},
"elm-version": "0.15.0 <= v < 0.16.0"
}
73 changes: 45 additions & 28 deletions frontend/SideBar/Controls.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Json.Decode exposing (..)
import List
import String
import Signal as S exposing (Signal, (<~), (~))
import Text
import FontAwesome

import Button
import SideBar.Model as Model
Expand All @@ -19,12 +19,15 @@ import Styles exposing (..)

-- STYLE

buttonHeight = 40
buttonWidth = 40
buttonIconSize = 20
buttonSideLength = 40
buttonBorderRadius = 8
sideMargin = 20
textHeight = 20
panelWidth = 275

playPauseButtonColor = Color.rgb 20 131 213

blue = Color.rgb 28 129 218
lightGrey = Color.rgb 228 228 228
darkGrey = Color.rgb 74 74 74
Expand All @@ -37,36 +40,21 @@ eventNumberTextStyle =

-- VIEW

buttonImage : String -> Button.Model -> Html
buttonImage name state =
let
stateName =
case state of
Button.Up -> "up"
Button.Down -> "down"
Button.Hover -> "hover"

path =
"/_reactor/debugger/" ++ name ++ "-button-" ++ stateName ++ ".png"
in
img
[ src path
, Attr.width 40
, Attr.height 40
]
[]


playPauseButton : Bool -> Button.Model -> Html
playPauseButton isPlay state =
let
name =
if isPlay then "play" else "pause"
icon =
if isPlay
then FontAwesome.play Color.white buttonIconSize
else FontAwesome.pause Color.white buttonIconSize
render state =
iconButton playPauseButtonColor icon
in
Button.view
(Signal.forwardTo buttonStateMailbox.address Model.PlayPauseButtonAction)
pausedInputMailbox.address False
state (buttonImage name)
pausedInputMailbox.address (not isPlay)
state render


pausedInputMailbox : Signal.Mailbox Bool
Expand All @@ -76,10 +64,14 @@ pausedInputMailbox =

restartButton : Button.Model -> Html
restartButton state =
Button.view
let
render st =
iconButton lightGrey (FontAwesome.undo darkGrey buttonIconSize)
in
Button.view
(Signal.forwardTo buttonStateMailbox.address Model.RestartButtonAction)
restartMailbox.address ()
state (buttonImage "restart")
state render


restartMailbox : Signal.Mailbox ()
Expand Down Expand Up @@ -250,5 +242,30 @@ view showSwap permitSwap state =

-- UTILITIES

iconButton : Color.Color -> Html -> Html
iconButton bgColor iconHtml =
let
transPx =
(buttonSideLength - buttonIconSize) // 2
in
div
[ style
[ ("background-color", colorToCss bgColor)
, ("border-radius", intToPx buttonBorderRadius)
, ("width", intToPx buttonSideLength)
, ("height", intToPx buttonSideLength)
]
]
[ div
[ style [("transform", translateToCss transPx transPx)] ]
[ iconHtml ]
]


translateToCss : Int -> Int -> String
translateToCss x y =
"translate(" ++ intToPx x ++ "," ++ intToPx y ++ ")"


intToPx : Int -> String
intToPx x = toString x ++ "px"

0 comments on commit 5cf14c9

Please sign in to comment.