MouseDemo: move clickedExtent into Brick.Main

This commit is contained in:
Jonathan Daugherty 2016-10-23 19:24:57 -07:00
parent 9154522509
commit afe2e7eec5
2 changed files with 9 additions and 6 deletions

View File

@ -76,7 +76,7 @@ appEvent st ev = do
-- If the mouse button was down in the layer and
-- we were not already dragging it, start dragging
-- the layer.
| clickedExtent (c, r) e -> st & lastDragLoc .~ LastLocation mouseLoc True
| M.clickedExtent (c, r) e -> st & lastDragLoc .~ LastLocation mouseLoc True
-- If the mouse button was down outside the layer,
-- start dragging outside the layer.
| otherwise -> st & lastDragLoc .~ LastLocation mouseLoc False
@ -90,11 +90,6 @@ appEvent st ev = do
& draggableLayerLocation %~ if bound then (<> off) else id
_ -> st
clickedExtent :: (Int, Int) -> T.Extent n -> Bool
clickedExtent (c, r) (T.Extent _ (T.Location (lc, lr)) (w, h)) =
c >= lc && c < (lc + w) &&
r >= lr && r < (lr + h)
aMap :: AttrMap
aMap = attrMap V.defAttr
[ ("info", V.white `on` V.magenta)

View File

@ -11,6 +11,7 @@ module Brick.Main
, suspendAndResume
, lookupViewport
, lookupExtent
, clickedExtent
, getVtyHandle
-- ** Viewport scrolling
@ -272,6 +273,13 @@ applyInvalidations ns cache = foldr (.) id (mkFunc <$> ns) cache
lookupViewport :: (Ord n) => n -> EventM n (Maybe Viewport)
lookupViewport n = EventM $ asks (M.lookup n . eventViewportMap)
-- | Did the specified mouse coordinates (column, row) intersect the
-- specified extent?
clickedExtent :: (Int, Int) -> Extent n -> Bool
clickedExtent (c, r) (Extent _ (Location (lc, lr)) (w, h)) =
c >= lc && c < (lc + w) &&
r >= lr && r < (lr + h)
-- | Given a name, get the most recent rendering extent for the name (if
-- any).
lookupExtent :: (Eq n) => n -> EventM n (Maybe (Extent n))