mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-12-12 12:23:21 +03:00
Improve performance of h/vCenter by using images instead of box combinators to control padding
This commit is contained in:
parent
e3c46bbf41
commit
c68c95d954
@ -9,8 +9,8 @@ module Brick.Widgets.Center
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
import Control.Lens ((^.), to)
|
import Control.Lens ((^.), (&), (.~), to)
|
||||||
import Graphics.Vty (imageWidth, imageHeight)
|
import Graphics.Vty (imageWidth, imageHeight, horizCat, charFill, vertCat)
|
||||||
|
|
||||||
import Brick.Widgets.Core
|
import Brick.Widgets.Core
|
||||||
import Brick.Core
|
import Brick.Core
|
||||||
@ -29,10 +29,18 @@ hCenterWith mChar p =
|
|||||||
remainder = c^.availW - (leftPaddingAmount * 2)
|
remainder = c^.availW - (leftPaddingAmount * 2)
|
||||||
leftPaddingAmount = (c^.availW - rWidth) `div` 2
|
leftPaddingAmount = (c^.availW - rWidth) `div` 2
|
||||||
rightPaddingAmount = leftPaddingAmount + remainder
|
rightPaddingAmount = leftPaddingAmount + remainder
|
||||||
render $ vLimit rHeight $
|
leftPadding = charFill (c^.attr) ch leftPaddingAmount rHeight
|
||||||
(hLimit leftPaddingAmount $ fill ch) <+>
|
rightPadding = charFill (c^.attr) ch rightPaddingAmount rHeight
|
||||||
(Widget Fixed Fixed $ return result) <+>
|
paddedImage = horizCat [ leftPadding
|
||||||
(hLimit rightPaddingAmount $ fill ch)
|
, result^.image
|
||||||
|
, rightPadding
|
||||||
|
]
|
||||||
|
off = Location (leftPaddingAmount, 0)
|
||||||
|
if leftPaddingAmount == 0 && rightPaddingAmount == 0 then
|
||||||
|
return result else
|
||||||
|
return $ addVisibilityOffset off
|
||||||
|
$ addCursorOffset off
|
||||||
|
$ result & image .~ paddedImage
|
||||||
|
|
||||||
vCenter :: Widget -> Widget
|
vCenter :: Widget -> Widget
|
||||||
vCenter = vCenterWith Nothing
|
vCenter = vCenterWith Nothing
|
||||||
@ -48,10 +56,18 @@ vCenterWith mChar p =
|
|||||||
remainder = c^.availH - (topPaddingAmount * 2)
|
remainder = c^.availH - (topPaddingAmount * 2)
|
||||||
topPaddingAmount = (c^.availH - rHeight) `div` 2
|
topPaddingAmount = (c^.availH - rHeight) `div` 2
|
||||||
bottomPaddingAmount = topPaddingAmount + remainder
|
bottomPaddingAmount = topPaddingAmount + remainder
|
||||||
render $ hLimit rWidth $
|
topPadding = charFill (c^.attr) ch rWidth topPaddingAmount
|
||||||
(vLimit topPaddingAmount $ fill ch) <=>
|
bottomPadding = charFill (c^.attr) ch rWidth bottomPaddingAmount
|
||||||
(Widget Fixed Fixed $ return result) <=>
|
paddedImage = vertCat [ topPadding
|
||||||
(vLimit bottomPaddingAmount $ fill ch)
|
, result^.image
|
||||||
|
, bottomPadding
|
||||||
|
]
|
||||||
|
off = Location (0, topPaddingAmount)
|
||||||
|
if topPaddingAmount == 0 && bottomPaddingAmount == 0 then
|
||||||
|
return result else
|
||||||
|
return $ addVisibilityOffset off
|
||||||
|
$ addCursorOffset off
|
||||||
|
$ result & image .~ paddedImage
|
||||||
|
|
||||||
center :: Widget -> Widget
|
center :: Widget -> Widget
|
||||||
center = centerWith Nothing
|
center = centerWith Nothing
|
||||||
|
Loading…
Reference in New Issue
Block a user