mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-11-28 01:33:35 +03:00
Compare commits
6 Commits
8eb7c197b8
...
86d1b8e442
Author | SHA1 | Date | |
---|---|---|---|
|
86d1b8e442 | ||
|
6819100e20 | ||
|
adc0fe33c5 | ||
|
ca36492dec | ||
|
696ae5c467 | ||
|
aeeee31e49 |
@ -46,8 +46,8 @@ drawUi st =
|
|||||||
[ C.centerLayer $
|
[ C.centerLayer $
|
||||||
B.border $ str "This layer is centered but other\nlayers are placed underneath it."
|
B.border $ str "This layer is centered but other\nlayers are placed underneath it."
|
||||||
, arrowLayer
|
, arrowLayer
|
||||||
, middleLayer st
|
, middleLayer (st^.middleLayerLocation)
|
||||||
, bottomLayer st
|
, bottomLayer (st^.bottomLayerLocation)
|
||||||
]
|
]
|
||||||
|
|
||||||
arrowLayer :: Widget Name
|
arrowLayer :: Widget Name
|
||||||
@ -59,15 +59,15 @@ arrowLayer =
|
|||||||
withDefAttr arrowAttr $
|
withDefAttr arrowAttr $
|
||||||
str msg
|
str msg
|
||||||
|
|
||||||
middleLayer :: St -> Widget Name
|
middleLayer :: Location -> Widget Name
|
||||||
middleLayer st =
|
middleLayer l =
|
||||||
translateBy (st^.middleLayerLocation) $
|
translateBy l $
|
||||||
reportExtent MiddleLayerElement $
|
reportExtent MiddleLayerElement $
|
||||||
B.border $ str "Middle layer\n(Arrow keys move)"
|
B.border $ str "Middle layer\n(Arrow keys move)"
|
||||||
|
|
||||||
bottomLayer :: St -> Widget Name
|
bottomLayer :: Location -> Widget Name
|
||||||
bottomLayer st =
|
bottomLayer l =
|
||||||
translateBy (st^.bottomLayerLocation) $
|
translateBy l $
|
||||||
B.border $ str "Bottom layer\n(Ctrl-arrow keys move)"
|
B.border $ str "Bottom layer\n(Ctrl-arrow keys move)"
|
||||||
|
|
||||||
appEvent :: T.BrickEvent Name e -> T.EventM Name St ()
|
appEvent :: T.BrickEvent Name e -> T.EventM Name St ()
|
||||||
|
@ -17,7 +17,9 @@ module Brick.BorderMap
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Brick.Types.Common (Edges(..), Location(..), eTopL, eBottomL, eRightL, eLeftL, origin)
|
import Brick.Types.Common (Edges(..), Location(..), eTopL, eBottomL, eRightL, eLeftL, origin)
|
||||||
|
#if !(MIN_VERSION_base(4,10,0))
|
||||||
import Control.Applicative (liftA2)
|
import Control.Applicative (liftA2)
|
||||||
|
#endif
|
||||||
import Data.IMap (IMap, Run(Run))
|
import Data.IMap (IMap, Run(Run))
|
||||||
import GHC.Generics
|
import GHC.Generics
|
||||||
import Control.DeepSeq
|
import Control.DeepSeq
|
||||||
|
@ -1084,15 +1084,16 @@ translateBy off p =
|
|||||||
-- | Given a widget, translate it to position it relative to the
|
-- | Given a widget, translate it to position it relative to the
|
||||||
-- upper-left coordinates of a reported extent with the specified
|
-- upper-left coordinates of a reported extent with the specified
|
||||||
-- positioning offset. If the specified name has no reported extent,
|
-- 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
|
-- This is only useful for positioning something in a higher layer
|
||||||
-- relative to a reported extent in a lower layer. Any other use is
|
-- 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
|
-- likely to result in the specified widget not being rendered. This
|
||||||
-- no translation. This is because this function relies on information
|
-- is because this function relies on information about lower layer
|
||||||
-- about lower layer renderings in order to work; using it with a
|
-- renderings in order to work; using it with a resource name that
|
||||||
-- resource name that wasn't rendered in a lower layer will result in
|
-- wasn't rendered in a lower layer will result in this being equivalent
|
||||||
-- this being equivalent to @id@.
|
-- to @emptyWidget@.
|
||||||
--
|
--
|
||||||
-- For example, if you have two layers @topLayer@ and @bottomLayer@,
|
-- For example, if you have two layers @topLayer@ and @bottomLayer@,
|
||||||
-- then a widget drawn in @bottomLayer@ with @reportExtent Foo@ can be
|
-- 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
|
Widget (hSize w) (vSize w) $ do
|
||||||
mExt <- lookupReportedExtent n
|
mExt <- lookupReportedExtent n
|
||||||
case mExt of
|
case mExt of
|
||||||
Nothing -> render w
|
Nothing -> render emptyWidget
|
||||||
Just ext -> render $ translateBy (extentUpperLeft ext <> off) w
|
Just ext -> render $ translateBy (extentUpperLeft ext <> off) w
|
||||||
|
|
||||||
-- | Crop the specified widget on the left by the specified number of
|
-- | Crop the specified widget on the left by the specified number of
|
||||||
@ -1254,7 +1255,6 @@ cached n w =
|
|||||||
allClickables <- use clickableNamesL
|
allClickables <- use clickableNamesL
|
||||||
return [extentName e | e <- renderResult^.extentsL, extentName e `elem` allClickables]
|
return [extentName e | e <- renderResult^.extentsL, extentName e `elem` allClickables]
|
||||||
|
|
||||||
|
|
||||||
cacheLookup :: (Ord n) => n -> RenderM n (Maybe ([n], Result n))
|
cacheLookup :: (Ord n) => n -> RenderM n (Maybe ([n], Result n))
|
||||||
cacheLookup n = do
|
cacheLookup n = do
|
||||||
cache <- lift $ gets (^.renderCacheL)
|
cache <- lift $ gets (^.renderCacheL)
|
||||||
|
@ -8,7 +8,7 @@ module Brick.Widgets.Internal
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
import Lens.Micro ((^.), (&), (%~))
|
import Lens.Micro ((^.), (&), (%~), (.~))
|
||||||
import Lens.Micro.Mtl ((%=))
|
import Lens.Micro.Mtl ((%=))
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.State.Strict
|
import Control.Monad.State.Strict
|
||||||
@ -35,7 +35,14 @@ renderFinal :: (Ord n)
|
|||||||
renderFinal aMap layerRenders (w, h) chooseCursor rs =
|
renderFinal aMap layerRenders (w, h) chooseCursor rs =
|
||||||
(newRS, picWithBg, theCursor, concat layerExtents)
|
(newRS, picWithBg, theCursor, concat layerExtents)
|
||||||
where
|
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) <$>
|
(\p -> runReaderT p ctx) <$>
|
||||||
(\layerWidget -> do
|
(\layerWidget -> do
|
||||||
result <- render $ cropToContext layerWidget
|
result <- render $ cropToContext layerWidget
|
||||||
|
Loading…
Reference in New Issue
Block a user