diff --git a/src/Brick/Types.hs b/src/Brick/Types.hs index 75d3285..03dbd75 100644 --- a/src/Brick/Types.hs +++ b/src/Brick/Types.hs @@ -44,7 +44,6 @@ module Brick.Types -- ** Rendering results , Result(..) , lookupAttrName - , lookupViewportR -- ** Rendering result lenses , imageL @@ -188,8 +187,3 @@ lookupAttrName :: AttrName -> RenderM Attr lookupAttrName n = do c <- getContext return $ attrMapLookup n (c^.ctxAttrMapL) - --- | Given a name, obtain the viewport for that name by consulting --- the viewport map in the rendering monad. -lookupViewportR :: Name -> RenderM (Maybe Viewport) -lookupViewportR name = lift $ gets (M.lookup name . (^.viewportMapL)) diff --git a/src/Brick/Widgets/Core.hs b/src/Brick/Widgets/Core.hs index d715c58..37e7d8e 100644 --- a/src/Brick/Widgets/Core.hs +++ b/src/Brick/Widgets/Core.hs @@ -55,6 +55,7 @@ module Brick.Widgets.Core , viewport , visible , visibleRegion + , unsafeLookupViewport -- ** Adding offsets to cursor positions and visibility requests , addResultOffset @@ -629,6 +630,18 @@ viewport vpname typ p = $ padRight Max $ Widget Fixed Fixed $ return $ translated & visibilityRequestsL .~ mempty +-- | Given a name, obtain the viewport for that name by consulting the +-- viewport map in the rendering monad. NOTE! Some care must be taken +-- when calling this function, since it only returns useful values +-- after the viewport in question has been rendered. If you call this +-- function during rendering before a viewport has been rendered, you +-- may get nothing or you may get a stale version of the viewport. This +-- is because viewports are updated during rendering and the one you are +-- interested in may not have been rendered yet. So if you want to use +-- this, be sure you know what you are doing. +unsafeLookupViewport :: Name -> RenderM (Maybe Viewport) +unsafeLookupViewport name = lift $ gets (M.lookup name . (^.viewportMapL)) + scrollTo :: ViewportType -> ScrollRequest -> V.Image -> Viewport -> Viewport scrollTo Both _ _ _ = error "BUG: called scrollTo on viewport type 'Both'" scrollTo Vertical req img vp = vp & vpTop .~ newVStart