mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-09-11 15:55:54 +03:00
Improve list demo
This commit is contained in:
parent
371d7768eb
commit
549c4b8663
@ -30,19 +30,28 @@ drawUI st = [ui]
|
||||
Nothing -> "-"
|
||||
Just i -> str (show (i + 1))
|
||||
total = str $ show $ length $ st^.stList.listElementsL
|
||||
ui = center $
|
||||
borderWithLabel label $
|
||||
hLimit 25 $
|
||||
vLimit 15 $
|
||||
renderList (st^.stList)
|
||||
box = borderWithLabel label $
|
||||
hLimit 25 $
|
||||
vLimit 15 $
|
||||
renderList (st^.stList)
|
||||
ui = vCenter $ vBox [ hCenter box
|
||||
, " "
|
||||
, hCenter "Press +/- to add/remove list elements."
|
||||
, hCenter "Press Esc to exit."
|
||||
]
|
||||
|
||||
appEvent :: Event -> St -> EventM (Next St)
|
||||
appEvent e st =
|
||||
case e of
|
||||
EvKey KEnter [] ->
|
||||
EvKey (KChar '+') [] ->
|
||||
let el = length $ st^.stList.listElementsL
|
||||
in continue $ st & stList %~ (listInsert el el)
|
||||
|
||||
EvKey (KChar '-') [] ->
|
||||
case st^.stList.listSelectedL of
|
||||
Nothing -> continue st
|
||||
Just i -> continue $ st & stList %~ (listRemove i)
|
||||
|
||||
EvKey KEsc [] -> halt st
|
||||
|
||||
ev -> continue $ st & stList %~ (handleEvent ev)
|
||||
|
Loading…
Reference in New Issue
Block a user