Add extent-local coordinates to Clicked events

This commit is contained in:
Jonathan Daugherty 2016-10-25 22:32:36 -07:00
parent 940435ddcc
commit a85238a115
3 changed files with 9 additions and 5 deletions

View File

@ -28,7 +28,7 @@ data St =
St { _draggableLayerLocation :: T.Location
, _lastDragLoc :: DragState
, _clicked :: [T.Extent Name]
, _lastReportedClick :: Maybe Name
, _lastReportedClick :: Maybe (Name, T.Location)
}
makeLenses ''St
@ -73,7 +73,7 @@ draggableLayer st =
"on or within its border.") <+> fill ' '
appEvent :: St -> T.BrickEvent Name e -> T.EventM Name (T.Next St)
appEvent st (T.Clicked n _ _) = M.continue $ st & lastReportedClick .~ Just n
appEvent st (T.Clicked n _ _ loc) = M.continue $ st & lastReportedClick .~ Just (n, loc)
appEvent st (T.VtyEvent (V.EvKey V.KEsc [])) = M.halt st
appEvent st (T.VtyEvent ev) = do
Just e <- M.lookupExtent Layer

View File

@ -246,12 +246,16 @@ runVty vty chan app appState rs = do
VtyEvent (EvMouseDown c r button mods) -> do
let matching = findClickedExtents_ (c, r) exts
case matching of
(Extent n _ _:_) ->
(Extent n (Location (ec, er)) _:_) ->
-- If the clicked extent was registered as
-- clickable, send a click event. Otherwise, just
-- send the raw mouse event
case n `elem` firstRS^.clickableNamesL of
True -> return (Clicked n button mods, firstRS, exts)
True -> do
let localCoords = Location (lc, lr)
lc = c - ec
lr = r - er
return (Clicked n button mods localCoords, firstRS, exts)
False -> return (e, firstRS, exts)
_ -> return (e, firstRS, exts)
_ -> return (e, firstRS, exts)

View File

@ -198,7 +198,7 @@ data BrickEvent n e = VtyEvent Event
-- ^ The event was a Vty event.
| AppEvent e
-- ^ The event was an application event.
| Clicked n Button [Modifier]
| Clicked n Button [Modifier] Location
-- ^ A mouse click on the specified region was
-- received.
deriving (Show, Eq)