added edit mode to application state

This commit is contained in:
Jonathan Lamothe 2024-07-25 20:06:13 -04:00
parent f995da30b6
commit 8feecdfad5
2 changed files with 32 additions and 7 deletions

View File

@ -30,7 +30,15 @@ module Hamming.App.Types (
-- * AppState -- * AppState
AppState (..), AppState (..),
-- ** Lenses -- ** Lenses
appMode,
hammingCode, hammingCode,
-- * AppMode
AppMode (..),
-- * EditState,
EditState (..),
-- ** Lenses
rowNum,
colNum,
-- * Other Types -- * Other Types
ResName, ResName,
Event, Event,
@ -46,7 +54,21 @@ import Lens.Micro.TH (makeLenses)
-- | The main state of the application -- | The main state of the application
data AppState = AppState 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 -- | Identifies a resource
@ -61,10 +83,13 @@ type Action a = EventM ResName AppState a
-- | Event handler -- | Event handler
type Handler = Event -> Action () type Handler = Event -> Action ()
makeLenses ''AppState concat <$> mapM makeLenses
[ ''AppState
, ''EditState
]
-- | Initial application state -- | Initial application state
initialState :: AppState initialState :: AppState
initialState = AppState 0 initialState = AppState DisplayMode 0
--jl --jl

View File

@ -44,16 +44,16 @@ hammingW'Spec = describe "hammingW'" $ mapM_
it ("should be " ++ show numExpRows) $ it ("should be " ++ show numExpRows) $
numActRows `shouldBe` numExpRows numActRows `shouldBe` numExpRows
mapM_ mapM_
( \(rowNum, actRow, expRow) -> let ( \(row, actRow, expRow) -> let
numActCols = length actRow numActCols = length actRow
numExpCols = length expRow numExpCols = length expRow
in context ("row " ++ show rowNum) $ do in context ("row " ++ show row) $ do
context "number of columns" $ context "number of columns" $
it ("should be " ++ show numExpCols) $ it ("should be " ++ show numExpCols) $
numActCols `shouldBe` numExpCols numActCols `shouldBe` numExpCols
mapM_ mapM_
( \(colNum, actBit, expBit) -> ( \(col, actBit, expBit) ->
context ("column " ++ show colNum) $ context ("column " ++ show col) $
it ("should be " ++ show expBit) $ it ("should be " ++ show expBit) $
actBit `shouldBe` expBit actBit `shouldBe` expBit
) $ zip3 [(0 :: Int)..] actRow expRow ) $ zip3 [(0 :: Int)..] actRow expRow