jtdaugherty/vty-ui — pull request #53 by fredlebel (2014-07-28 02:32:26+00:00)
Title: List: Changed how the selection attributes are set and used when renderi...

Example of three lists with complex child widgets and different selection attributes.

main = do
c <- newCollection
fg <- newFocusGroup

someList1 <- newList 1
setSelectedFocusedAttr someList1 Nothing
setSelectedUnfocusedAttr someList1 Nothing

someList2 <- newList 1
setSelectedFocusedAttr someList2 (Just (bgColor yellow))
setSelectedUnfocusedAttr someList2 (Just (bgColor white))

someList3 <- newList 1
setSelectedFocusedAttr someList3 (Just (black `on` yellow))
setSelectedUnfocusedAttr someList3 (Just (blue `on` white))

do
listItem <- newTable [column ColAuto, column (ColFixed 10) `align` AlignRight] BorderNone
defText <- plainText "Text"
-- plainText with red foreground color.
redText <- plainText "Red" >>= withNormalAttribute (fgColor red) >>= withFocusAttribute (fgColor green)
addRow listItem $ defText .|. redText
addToList someList1 False listItem

do
listItem <- newTable [column ColAuto, column (ColFixed 10) `align` AlignRight] BorderNone
defText <- plainText "Text"
-- plainText with blue foreground color.
redText <- plainText "Blue" >>= withNormalAttribute (fgColor blue) >>= withFocusAttribute (fgColor cyan)
addRow listItem $ defText .|. redText
addToList someList1 False listItem

do
listItem <- newTable [column ColAuto, column (ColFixed 10) `align` AlignRight] BorderNone
defText <- plainText "Text"
-- plainText with red foreground color.
redText <- plainText "Red" >>= withNormalAttribute (fgColor red) >>= withFocusAttribute (fgColor green)
addRow listItem $ defText .|. redText
addToList someList2 False listItem

do
listItem <- newTable [column ColAuto, column (ColFixed 10) `align` AlignRight] BorderNone
defText <- plainText "Text"
-- plainText with blue foreground color.
redText <- plainText "Blue" >>= withNormalAttribute (fgColor blue) >>= withFocusAttribute (fgColor cyan)
addRow listItem $ defText .|. redText
addToList someList2 False listItem

do
listItem <- newTable [column ColAuto, column (ColFixed 10) `align` AlignRight] BorderNone
defText <- plainText "Text"
-- plainText with red foreground color.
redText <- plainText "Red" >>= withNormalAttribute (fgColor red) >>= withFocusAttribute (fgColor green)
addRow listItem $ defText .|. redText
addToList someList3 False listItem

do
listItem <- newTable [column ColAuto, column (ColFixed 10) `align` AlignRight] BorderNone
defText <- plainText "Text"
-- plainText with blue foreground color.
redText <- plainText "Blue" >>= withNormalAttribute (fgColor blue) >>= withFocusAttribute (fgColor cyan)
addRow listItem $ defText .|. redText
addToList someList3 False listItem

form <- (return someList1 <--> return someList2 <--> return someList3)

addToFocusGroup fg someList1
addToFocusGroup fg someList2
addToFocusGroup fg someList3

_cb <- addToCollection c form fg
runUi c $ defaultContext