Compare commits

...

6 Commits

4 changed files with 27 additions and 18 deletions

View File

@ -46,8 +46,8 @@ drawUi st =
[ C.centerLayer $
B.border $ str "This layer is centered but other\nlayers are placed underneath it."
, arrowLayer
, middleLayer st
, bottomLayer st
, middleLayer (st^.middleLayerLocation)
, bottomLayer (st^.bottomLayerLocation)
]
arrowLayer :: Widget Name
@ -59,15 +59,15 @@ arrowLayer =
withDefAttr arrowAttr $
str msg
middleLayer :: St -> Widget Name
middleLayer st =
translateBy (st^.middleLayerLocation) $
middleLayer :: Location -> Widget Name
middleLayer l =
translateBy l $
reportExtent MiddleLayerElement $
B.border $ str "Middle layer\n(Arrow keys move)"
bottomLayer :: St -> Widget Name
bottomLayer st =
translateBy (st^.bottomLayerLocation) $
bottomLayer :: Location -> Widget Name
bottomLayer l =
translateBy l $
B.border $ str "Bottom layer\n(Ctrl-arrow keys move)"
appEvent :: T.BrickEvent Name e -> T.EventM Name St ()

View File

@ -17,7 +17,9 @@ module Brick.BorderMap
) where
import Brick.Types.Common (Edges(..), Location(..), eTopL, eBottomL, eRightL, eLeftL, origin)
#if !(MIN_VERSION_base(4,10,0))
import Control.Applicative (liftA2)
#endif
import Data.IMap (IMap, Run(Run))
import GHC.Generics
import Control.DeepSeq

View File

@ -1084,15 +1084,16 @@ translateBy off p =
-- | Given a widget, translate it to position it relative to the
-- upper-left coordinates of a reported extent with the specified
-- positioning offset. If the specified name has no reported extent,
-- this just draws the specified widget with no special positioning.
-- this draws nothing on the basis that it only makes sense to draw what
-- was requested when the relative position can be known.
--
-- This is only useful for positioning something in a higher layer
-- relative to a reported extent in a lower layer. Any other use is
-- likely to result in the specified widget being rendered as-is with
-- no translation. This is because this function relies on information
-- about lower layer renderings in order to work; using it with a
-- resource name that wasn't rendered in a lower layer will result in
-- this being equivalent to @id@.
-- likely to result in the specified widget not being rendered. This
-- is because this function relies on information about lower layer
-- renderings in order to work; using it with a resource name that
-- wasn't rendered in a lower layer will result in this being equivalent
-- to @emptyWidget@.
--
-- For example, if you have two layers @topLayer@ and @bottomLayer@,
-- then a widget drawn in @bottomLayer@ with @reportExtent Foo@ can be
@ -1103,7 +1104,7 @@ relativeTo n off w =
Widget (hSize w) (vSize w) $ do
mExt <- lookupReportedExtent n
case mExt of
Nothing -> render w
Nothing -> render emptyWidget
Just ext -> render $ translateBy (extentUpperLeft ext <> off) w
-- | Crop the specified widget on the left by the specified number of
@ -1254,7 +1255,6 @@ cached n w =
allClickables <- use clickableNamesL
return [extentName e | e <- renderResult^.extentsL, extentName e `elem` allClickables]
cacheLookup :: (Ord n) => n -> RenderM n (Maybe ([n], Result n))
cacheLookup n = do
cache <- lift $ gets (^.renderCacheL)

View File

@ -8,7 +8,7 @@ module Brick.Widgets.Internal
)
where
import Lens.Micro ((^.), (&), (%~))
import Lens.Micro ((^.), (&), (%~), (.~))
import Lens.Micro.Mtl ((%=))
import Control.Monad
import Control.Monad.State.Strict
@ -35,7 +35,14 @@ renderFinal :: (Ord n)
renderFinal aMap layerRenders (w, h) chooseCursor rs =
(newRS, picWithBg, theCursor, concat layerExtents)
where
(layerResults, !newRS) = flip runState rs $ sequence $
-- Reset various fields from the last rendering state so they
-- don't accumulate or affect this rendering.
resetRs = rs & reportedExtentsL .~ mempty
& observedNamesL .~ mempty
& clickableNamesL .~ mempty
& requestedVisibleNames_L .~ mempty
(layerResults, !newRS) = flip runState resetRs $ sequence $
(\p -> runReaderT p ctx) <$>
(\layerWidget -> do
result <- render $ cropToContext layerWidget