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 |         VtyEvent e | e `elem` moveRightEvents | ||||||
|                    , not $ isBlankElement $ listSelectedElement _asList -> asEnterRegister d selacct ui |                    , 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 |         MouseDown _n BLeft _mods Location{loc=(_x,y)} | not $ (=="") clickedacct -> do | ||||||
|           let list' = listMoveTo y _asList |           continue ui{aScreen=scr{_asList=listMoveTo y _asList}} | ||||||
|           asEnterRegister d clickedacct ui{aScreen=scr{_asList=list'}} |           where clickedacct = maybe "" asItemAccountName $ listElements _asList !? y | ||||||
|           where  |         -- and on MouseUp, enter the subscreen | ||||||
|             clickedacct = maybe "" asItemAccountName $ listElements _asList !? y |         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; |         -- prevent moving down over blank padding items; | ||||||
|         -- instead scroll down by one, until maximally scrolled - shows the end has been reached |         -- 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 (KRight)    [MShift]) -> continue $ regenerateScreens j d $ nextReportPeriod journalspan ui | ||||||
|         VtyEvent (EvKey (KLeft)     [MShift]) -> continue $ regenerateScreens j d $ previousReportPeriod 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 (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 'l') [MCtrl]) -> scrollSelectionToMiddle rsList >> redraw ui | ||||||
|         VtyEvent (EvKey (KChar 'z') [MCtrl]) -> suspend 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 -> |         VtyEvent e | e `elem` moveRightEvents -> | ||||||
|           case listSelectedElement rsList of |           case listSelectedElement rsList of | ||||||
|             Just _  -> continue $ screenEnter d transactionScreen{tsAccount=rsAccount} ui |             Just _  -> continue $ screenEnter d transactionScreen{tsAccount=rsAccount} ui | ||||||
|             Nothing -> continue ui |             Nothing -> continue ui | ||||||
| 
 |         -- or on transaction click | ||||||
|         -- or clicked transaction |         -- 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 |         MouseDown _n BLeft _mods Location{loc=(_x,y)} | not $ (=="") clickeddate -> do | ||||||
|           let  |           continue $ ui{aScreen=s{rsList=listMoveTo y rsList}} | ||||||
|             list' = listMoveTo y rsList |           where clickeddate = maybe "" rsItemDate $ listElements rsList !? y | ||||||
|             ui'   = ui{aScreen=s{rsList=list'}} |         -- and on MouseUp, enter the subscreen | ||||||
|           continue $ screenEnter d transactionScreen{tsAccount=rsAccount} ui' |         MouseUp _n (Just BLeft) Location{loc=(_x,y)} | not $ (=="") clickeddate -> do | ||||||
|           where  |           continue $ screenEnter d transactionScreen{tsAccount=rsAccount} ui | ||||||
|             clickeddate = maybe "" rsItemDate $ listElements rsList !? y |           where clickeddate = maybe "" rsItemDate $ listElements rsList !? y | ||||||
| 
 | 
 | ||||||
|         -- when at the last item, instead of moving down, scroll down by one, until maximally scrolled |         -- when at the last item, instead of moving down, scroll down by one, until maximally scrolled | ||||||
|         VtyEvent e | e `elem` moveDownEvents, isBlankElement mnextelement -> do |         VtyEvent e | e `elem` moveDownEvents, isBlankElement mnextelement -> do | ||||||
|  | |||||||
| @ -15,7 +15,7 @@ import Data.Maybe | |||||||
| import qualified Data.Text as T | import qualified Data.Text as T | ||||||
| import Data.Time.Calendar (Day) | import Data.Time.Calendar (Day) | ||||||
| import qualified Data.Vector as V | import qualified Data.Vector as V | ||||||
| import Graphics.Vty (Event(..),Key(..),Modifier(..)) | import Graphics.Vty (Event(..),Key(..),Modifier(..), Button (BLeft)) | ||||||
| import Lens.Micro ((^.)) | import Lens.Micro ((^.)) | ||||||
| import Brick | import Brick | ||||||
| import Brick.Widgets.List (listElementsL, listMoveTo, listSelectedElement) | 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` moveUpEvents   -> continue $ tsSelect iprev tprev ui | ||||||
|         VtyEvent e | e `elem` moveDownEvents -> continue $ tsSelect inext tnext 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. |         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 'l') [MCtrl]) -> redraw ui | ||||||
|         VtyEvent (EvKey (KChar 'z') [MCtrl]) -> suspend ui |         VtyEvent (EvKey (KChar 'z') [MCtrl]) -> suspend ui | ||||||
|         _ -> continue ui |         _ -> continue ui | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user