mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-12-15 07:23:49 +03:00
Combine h/vPad into pad
This commit is contained in:
parent
adbcbf72b0
commit
deb97623f0
@ -19,33 +19,39 @@ hCenter :: Widget -> Widget
|
||||
hCenter = hCenterWith Nothing
|
||||
|
||||
hCenterWith :: Maybe Char -> Widget -> Widget
|
||||
hCenterWith Nothing p =
|
||||
Widget Unlimited (vSize p) $ do
|
||||
hCenterWith mChar p =
|
||||
let ch = maybe ' ' id mChar
|
||||
in Widget Unlimited (vSize p) $ do
|
||||
result <- render p
|
||||
c <- getContext
|
||||
let offW = (c^.availW - (result^.image.to imageWidth)) `div` 2
|
||||
render $ translateBy (Location (offW, 0)) $ Widget Fixed Fixed $ return result
|
||||
hCenterWith (Just c) p =
|
||||
hBox [ (hPad c, Low)
|
||||
, (p, High)
|
||||
, (hPad c, Low)
|
||||
]
|
||||
let rWidth = result^.image.to imageWidth
|
||||
rHeight = result^.image.to imageHeight
|
||||
remainder = c^.availW - (leftPaddingAmount * 2)
|
||||
leftPaddingAmount = (c^.availW - rWidth) `div` 2
|
||||
rightPaddingAmount = leftPaddingAmount + remainder
|
||||
render $ vLimit rHeight $
|
||||
(hLimit leftPaddingAmount $ pad ch) <+>
|
||||
(Widget Fixed Fixed $ return result) <+>
|
||||
(hLimit rightPaddingAmount $ pad ch)
|
||||
|
||||
vCenter :: Widget -> Widget
|
||||
vCenter = vCenterWith Nothing
|
||||
|
||||
vCenterWith :: (Maybe Char) -> Widget -> Widget
|
||||
vCenterWith Nothing p =
|
||||
Widget (hSize p) Unlimited $ do
|
||||
vCenterWith :: Maybe Char -> Widget -> Widget
|
||||
vCenterWith mChar p =
|
||||
let ch = maybe ' ' id mChar
|
||||
in Widget (hSize p) Unlimited $ do
|
||||
result <- render p
|
||||
c <- getContext
|
||||
let offH = (c^.availH - (result^.image.to imageHeight)) `div` 2
|
||||
render $ translateBy (Location (0, offH)) $ Widget Fixed Fixed $ return result
|
||||
vCenterWith (Just c) p =
|
||||
vBox [ (vPad c, Low)
|
||||
, (p, High)
|
||||
, (vPad c, Low)
|
||||
]
|
||||
let rWidth = result^.image.to imageWidth
|
||||
rHeight = result^.image.to imageHeight
|
||||
remainder = c^.availH - (topPaddingAmount * 2)
|
||||
topPaddingAmount = (c^.availH - rHeight) `div` 2
|
||||
bottomPaddingAmount = topPaddingAmount + remainder
|
||||
render $ hLimit rWidth $
|
||||
(vLimit topPaddingAmount $ pad ch) <=>
|
||||
(Widget Fixed Fixed $ return result) <=>
|
||||
(vLimit topPaddingAmount $ pad ch)
|
||||
|
||||
center :: Widget -> Widget
|
||||
center = centerWith Nothing
|
||||
|
@ -24,8 +24,7 @@ module Brick.Widgets.Core
|
||||
|
||||
, txt
|
||||
, str
|
||||
, hPad
|
||||
, vPad
|
||||
, pad
|
||||
, hFill
|
||||
, vFill
|
||||
, hBox
|
||||
|
@ -34,8 +34,7 @@ module Brick.Widgets.Internal
|
||||
|
||||
, txt
|
||||
, str
|
||||
, hPad
|
||||
, vPad
|
||||
, pad
|
||||
, hFill
|
||||
, vFill
|
||||
|
||||
@ -209,17 +208,11 @@ str s =
|
||||
txt :: T.Text -> Widget
|
||||
txt = str . T.unpack
|
||||
|
||||
hPad :: Char -> Widget
|
||||
hPad ch =
|
||||
Widget Unlimited Fixed $ do
|
||||
pad :: Char -> Widget
|
||||
pad ch =
|
||||
Widget Unlimited Unlimited $ do
|
||||
c <- getContext
|
||||
return $ def & image .~ (V.charFill (c^.attr) ch (c^.availW) (max 1 (c^.availH)))
|
||||
|
||||
vPad :: Char -> Widget
|
||||
vPad ch =
|
||||
Widget Fixed Unlimited $ do
|
||||
c <- getContext
|
||||
return $ def & image .~ (V.charFill (c^.attr) ch (max 1 (c^.availW)) (c^.availH))
|
||||
return $ def & image .~ (V.charFill (c^.attr) ch (max 1 (c^.availW)) (max 1 (c^.availH)))
|
||||
|
||||
hFill :: Char -> Widget
|
||||
hFill ch =
|
||||
@ -451,7 +444,7 @@ viewport vpname typ p =
|
||||
|
||||
-- Return the translated result with the visibility requests
|
||||
-- discarded
|
||||
render $ cropToContext $ ((Widget Fixed Fixed $ return $ translated & visibilityRequests .~ mempty) <+> hPad ' ') <=> vPad ' '
|
||||
render $ cropToContext $ ((Widget Fixed Fixed $ return $ translated & visibilityRequests .~ mempty) <+> pad ' ') <=> pad ' '
|
||||
|
||||
scrollTo :: ViewportType -> ScrollRequest -> V.Image -> Viewport -> Viewport
|
||||
scrollTo typ req img vp = vp & theStart .~ newStart
|
||||
|
Loading…
Reference in New Issue
Block a user