mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-11-29 10:54:48 +03:00
Add bordered widget
This commit is contained in:
parent
45b095a6a2
commit
9f9f0c2c51
@ -23,6 +23,7 @@ drawUI :: St -> [Widget]
|
||||
drawUI st = [top]
|
||||
where
|
||||
top = translated (trans st) $
|
||||
bordered $
|
||||
hLimit 40 $
|
||||
vBox [ txt $ "Top (counter: " <> show (counter st) <> ")"
|
||||
, hBorder '-'
|
||||
|
31
src/Brick.hs
31
src/Brick.hs
@ -77,6 +77,37 @@ locOffset (Location (w1, h1)) (Location (w2, h2)) = Location (w1+w2, h1+h2)
|
||||
clOffset :: CursorLocation -> Location -> CursorLocation
|
||||
clOffset cl loc = cl { cursorLocation = (cursorLocation cl) `locOffset` loc }
|
||||
|
||||
bordered :: Widget -> Widget
|
||||
bordered w =
|
||||
def { render = renderBordered w
|
||||
}
|
||||
|
||||
renderBordered :: Widget -> DisplayRegion -> Attr -> Render
|
||||
renderBordered w sz attr = result { renderImage = borderedImg
|
||||
, renderCursors = translatedCursors
|
||||
}
|
||||
where
|
||||
result = render w sz attr
|
||||
childImg = renderImage result
|
||||
(width, height) = ( imageWidth childImg
|
||||
, imageHeight childImg
|
||||
)
|
||||
topBottomBorder = horizCat [ string attr "+"
|
||||
, charFill attr '-' width 1
|
||||
, string attr "+"
|
||||
]
|
||||
leftRightBorder = charFill attr '|' 1 height
|
||||
withSideBorders = horizCat [ leftRightBorder
|
||||
, childImg
|
||||
, leftRightBorder
|
||||
]
|
||||
borderedImg = vertCat [ topBottomBorder
|
||||
, withSideBorders
|
||||
, topBottomBorder
|
||||
]
|
||||
translatedCursors = (`clOffset` (Location (1,1))) <$>
|
||||
renderCursors result
|
||||
|
||||
txt :: String -> Widget
|
||||
txt s =
|
||||
def { render = \_ a -> def { renderImage = string a s }
|
||||
|
Loading…
Reference in New Issue
Block a user