added edit mode to application state
This commit is contained in:
parent
f995da30b6
commit
8feecdfad5
|
@ -30,7 +30,15 @@ module Hamming.App.Types (
|
|||
-- * AppState
|
||||
AppState (..),
|
||||
-- ** Lenses
|
||||
appMode,
|
||||
hammingCode,
|
||||
-- * AppMode
|
||||
AppMode (..),
|
||||
-- * EditState,
|
||||
EditState (..),
|
||||
-- ** Lenses
|
||||
rowNum,
|
||||
colNum,
|
||||
-- * Other Types
|
||||
ResName,
|
||||
Event,
|
||||
|
@ -46,7 +54,21 @@ import Lens.Micro.TH (makeLenses)
|
|||
|
||||
-- | The main state of the application
|
||||
data AppState = AppState
|
||||
{ _hammingCode :: Word16
|
||||
{ _appMode :: AppMode
|
||||
, _hammingCode :: Word16
|
||||
}
|
||||
|
||||
-- | The application's main mode
|
||||
data AppMode
|
||||
= DisplayMode
|
||||
| EditMode EditState
|
||||
|
||||
-- | The state of the editor
|
||||
data EditState = EditState
|
||||
{ _rowNum :: Int
|
||||
-- ^ The selected row number
|
||||
, _colNum :: Int
|
||||
-- ^ The selected column
|
||||
}
|
||||
|
||||
-- | Identifies a resource
|
||||
|
@ -61,10 +83,13 @@ type Action a = EventM ResName AppState a
|
|||
-- | Event handler
|
||||
type Handler = Event -> Action ()
|
||||
|
||||
makeLenses ''AppState
|
||||
concat <$> mapM makeLenses
|
||||
[ ''AppState
|
||||
, ''EditState
|
||||
]
|
||||
|
||||
-- | Initial application state
|
||||
initialState :: AppState
|
||||
initialState = AppState 0
|
||||
initialState = AppState DisplayMode 0
|
||||
|
||||
--jl
|
||||
|
|
|
@ -44,16 +44,16 @@ hammingW'Spec = describe "hammingW'" $ mapM_
|
|||
it ("should be " ++ show numExpRows) $
|
||||
numActRows `shouldBe` numExpRows
|
||||
mapM_
|
||||
( \(rowNum, actRow, expRow) -> let
|
||||
( \(row, actRow, expRow) -> let
|
||||
numActCols = length actRow
|
||||
numExpCols = length expRow
|
||||
in context ("row " ++ show rowNum) $ do
|
||||
in context ("row " ++ show row) $ do
|
||||
context "number of columns" $
|
||||
it ("should be " ++ show numExpCols) $
|
||||
numActCols `shouldBe` numExpCols
|
||||
mapM_
|
||||
( \(colNum, actBit, expBit) ->
|
||||
context ("column " ++ show colNum) $
|
||||
( \(col, actBit, expBit) ->
|
||||
context ("column " ++ show col) $
|
||||
it ("should be " ++ show expBit) $
|
||||
actBit `shouldBe` expBit
|
||||
) $ zip3 [(0 :: Int)..] actRow expRow
|
||||
|
|
Loading…
Reference in New Issue
Block a user