ui: debounced clicking; click top/left margin to exit
This commit is contained in:
parent
6d69ea9c29
commit
3a57814402
@ -323,11 +323,15 @@ asHandle ui0@UIState{
|
||||
VtyEvent e | e `elem` moveRightEvents
|
||||
, not $ isBlankElement $ listSelectedElement _asList -> asEnterRegister d selacct ui
|
||||
|
||||
-- MouseDown is sometimes duplicated, https://github.com/jtdaugherty/brick/issues/347
|
||||
-- just use it to move the selection
|
||||
MouseDown _n BLeft _mods Location{loc=(_x,y)} | not $ (=="") clickedacct -> do
|
||||
let list' = listMoveTo y _asList
|
||||
asEnterRegister d clickedacct ui{aScreen=scr{_asList=list'}}
|
||||
where
|
||||
clickedacct = maybe "" asItemAccountName $ listElements _asList !? y
|
||||
continue ui{aScreen=scr{_asList=listMoveTo y _asList}}
|
||||
where clickedacct = maybe "" asItemAccountName $ listElements _asList !? y
|
||||
-- and on MouseUp, enter the subscreen
|
||||
MouseUp _n (Just BLeft) Location{loc=(_x,y)} | not $ (=="") clickedacct -> do
|
||||
asEnterRegister d clickedacct ui
|
||||
where clickedacct = maybe "" asItemAccountName $ listElements _asList !? y
|
||||
|
||||
-- prevent moving down over blank padding items;
|
||||
-- instead scroll down by one, until maximally scrolled - shows the end has been reached
|
||||
|
||||
@ -348,24 +348,29 @@ rsHandle ui@UIState{
|
||||
VtyEvent (EvKey (KRight) [MShift]) -> continue $ regenerateScreens j d $ nextReportPeriod journalspan ui
|
||||
VtyEvent (EvKey (KLeft) [MShift]) -> continue $ regenerateScreens j d $ previousReportPeriod journalspan ui
|
||||
VtyEvent (EvKey k []) | k `elem` [KBS, KDel] -> (continue $ regenerateScreens j d $ resetFilter ui)
|
||||
VtyEvent e | e `elem` moveLeftEvents -> continue $ popScreen ui
|
||||
VtyEvent (EvKey (KChar 'l') [MCtrl]) -> scrollSelectionToMiddle rsList >> redraw ui
|
||||
VtyEvent (EvKey (KChar 'z') [MCtrl]) -> suspend ui
|
||||
|
||||
-- enter transaction screen for selected transaction
|
||||
-- exit screen on LEFT
|
||||
VtyEvent e | e `elem` moveLeftEvents -> continue $ popScreen ui
|
||||
-- or on a click in the app's left or top margin. This is a VtyEvent since not in a clickable widget.
|
||||
VtyEvent (EvMouseUp x y (Just BLeft)) | x==0 || y==0 -> continue $ popScreen ui
|
||||
|
||||
-- enter transaction screen on RIGHT
|
||||
VtyEvent e | e `elem` moveRightEvents ->
|
||||
case listSelectedElement rsList of
|
||||
Just _ -> continue $ screenEnter d transactionScreen{tsAccount=rsAccount} ui
|
||||
Nothing -> continue ui
|
||||
|
||||
-- or clicked transaction
|
||||
-- or on transaction click
|
||||
-- MouseDown is sometimes duplicated, https://github.com/jtdaugherty/brick/issues/347
|
||||
-- just use it to move the selection
|
||||
MouseDown _n BLeft _mods Location{loc=(_x,y)} | not $ (=="") clickeddate -> do
|
||||
let
|
||||
list' = listMoveTo y rsList
|
||||
ui' = ui{aScreen=s{rsList=list'}}
|
||||
continue $ screenEnter d transactionScreen{tsAccount=rsAccount} ui'
|
||||
where
|
||||
clickeddate = maybe "" rsItemDate $ listElements rsList !? y
|
||||
continue $ ui{aScreen=s{rsList=listMoveTo y rsList}}
|
||||
where clickeddate = maybe "" rsItemDate $ listElements rsList !? y
|
||||
-- and on MouseUp, enter the subscreen
|
||||
MouseUp _n (Just BLeft) Location{loc=(_x,y)} | not $ (=="") clickeddate -> do
|
||||
continue $ screenEnter d transactionScreen{tsAccount=rsAccount} ui
|
||||
where clickeddate = maybe "" rsItemDate $ listElements rsList !? y
|
||||
|
||||
-- when at the last item, instead of moving down, scroll down by one, until maximally scrolled
|
||||
VtyEvent e | e `elem` moveDownEvents, isBlankElement mnextelement -> do
|
||||
|
||||
@ -15,7 +15,7 @@ import Data.Maybe
|
||||
import qualified Data.Text as T
|
||||
import Data.Time.Calendar (Day)
|
||||
import qualified Data.Vector as V
|
||||
import Graphics.Vty (Event(..),Key(..),Modifier(..))
|
||||
import Graphics.Vty (Event(..),Key(..),Modifier(..), Button (BLeft))
|
||||
import Lens.Micro ((^.))
|
||||
import Brick
|
||||
import Brick.Widgets.List (listElementsL, listMoveTo, listSelectedElement)
|
||||
@ -181,7 +181,12 @@ tsHandle ui@UIState{aScreen=TransactionScreen{tsTransaction=(i,t), tsTransaction
|
||||
|
||||
VtyEvent e | e `elem` moveUpEvents -> continue $ tsSelect iprev tprev ui
|
||||
VtyEvent e | e `elem` moveDownEvents -> continue $ tsSelect inext tnext ui
|
||||
|
||||
-- exit screen on LEFT
|
||||
VtyEvent e | e `elem` moveLeftEvents -> continue . popScreen $ tsSelect i t ui -- Probably not necessary to tsSelect here, but it's safe.
|
||||
-- or on a click in the app's left or top margin. This is a VtyEvent since not in a clickable widget.
|
||||
VtyEvent (EvMouseUp x y (Just BLeft)) | x==0 || y==0 -> continue . popScreen $ tsSelect i t ui
|
||||
|
||||
VtyEvent (EvKey (KChar 'l') [MCtrl]) -> redraw ui
|
||||
VtyEvent (EvKey (KChar 'z') [MCtrl]) -> suspend ui
|
||||
_ -> continue ui
|
||||
|
||||
Loading…
Reference in New Issue
Block a user