module TextUI.ItemField.Types where
import qualified Data.Text as T
type GroupName = T.Text
type NumItems = Int
data Items = ItemGroup GroupName Items | Items NumItems deriving Show
data ItemState = Free | Marked | Good | Bad | Pending deriving (Show,Eq)
type ItemIdent = Maybe (Int -> ItemState -> T.Text)
numItems :: Items -> NumItems
numItems (ItemGroup _ x) = numItems x
numItems (Items n) = n
cntItems :: [Items] -> NumItems
cntItems = sum . map numItems
data ItemField = ItemFld { curSel :: Int
, items :: [Items]
, itemst8 :: [ItemState]
, elemIdent :: ItemIdent
}
instance Show ItemField where
showsPrec p s = showParen (p > 10) $
showString "ItemFld @ " . shows (curSel s)
. showString " with " . shows (length $ itemst8 s)
. showString " items"
newItemField :: [Items] -> ItemIdent -> ItemField
newItemField itms = ItemFld 0 itms (replicate (cntItems itms) Free)