...
 
Commits (1)
......@@ -14,6 +14,7 @@ type alias Model =
{ stack : List Float
, currentNum : String
, error : Maybe String
, dirty : Bool
}
......@@ -22,6 +23,7 @@ initialModel =
{ stack = []
, currentNum = "0"
, error = Nothing
, dirty = False
}
......@@ -103,7 +105,7 @@ update msg model =
initialModel
Clear ->
{ model | currentNum = "0" }
{ model | currentNum = "0", dirty = False }
Back ->
let
......@@ -129,7 +131,7 @@ update msg model =
{ model | error = Just "PARSE ERR" }
Just num ->
{ model | stack = num :: model.stack, currentNum = "0" }
{ model | stack = num :: model.stack, dirty = True }
InputOperator operator ->
case model.stack of
......@@ -156,12 +158,16 @@ update msg model =
{ model
| stack = xs
, currentNum = String.fromFloat newNum
, dirty = True
}
InputNumber num ->
if model.currentNum == "0" then
{ model | currentNum = String.fromFloat num }
else if model.dirty then
{ model | currentNum = String.fromFloat num, dirty = False }
else
{ model | currentNum = model.currentNum ++ String.fromFloat num }
......@@ -241,7 +247,16 @@ section =
, cell (onClick <| InputNumber 0) Single White "0"
, cell (onClick SetDecimal) Single White "."
, cell (onClick SetSign) Single White "+/-"
, cell (onClick <| Enter) Single Yellow "Enter"
, cell (onClick <| Enter) Single Yellow "↵"
]
emptyBox : Html Msg
emptyBox =
div
[ class "input-box"
]
[ span [ class "empty" ] [ text "empty" ]
]
......@@ -269,7 +284,8 @@ view model =
[ h1 [ class "h1" ] [ text "RPN Calculator" ]
, div
[ class "calculator" ]
(List.map stackBox (List.reverse model.stack)
(List.repeat (3 - List.length model.stack) emptyBox
++ List.map stackBox (List.reverse <| List.take 3 model.stack)
++ [ inputBox <|
case model.error of
Nothing ->
......@@ -280,7 +296,8 @@ view model =
, section
]
)
, div [] [ text <| Debug.toString model ]
-- , div [] [ text <| Debug.toString model ]
]
......
......@@ -26,6 +26,10 @@ body {
margin: auto;
}
.empty {
opacity: 0;
}
.input-box {
text-align: right;
padding: 12px;
......