File: DynamicBorderDemo.hs

package info (click to toggle)
haskell-brick 2.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,328 kB
  • sloc: haskell: 8,492; makefile: 5
file content (71 lines) | stat: -rw-r--r-- 2,045 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{-# LANGUAGE OverloadedStrings #-}
module Main where

import qualified Brick.Main as M
import Brick.Types
  ( Widget
  )
import qualified Brick.Widgets.Center as C
import qualified Brick.Widgets.Core as C
import qualified Brick.Widgets.Border as B
import qualified Brick.Widgets.Border.Style as BS

doubleHorizontal :: BS.BorderStyle
doubleHorizontal = BS.BorderStyle
    { BS.bsCornerTL = '╒'
    , BS.bsCornerTR = '╕'
    , BS.bsCornerBR = '╛'
    , BS.bsCornerBL = '╘'
    , BS.bsIntersectL = '╞'
    , BS.bsIntersectR = '╡'
    , BS.bsIntersectT = '╤'
    , BS.bsIntersectB = '╧'
    , BS.bsIntersectFull = '╪'
    , BS.bsHorizontal = '═'
    , BS.bsVertical = '│'
    }

box1 :: Widget ()
box1
    = C.withBorderStyle doubleHorizontal . B.border
    . C.withBorderStyle BS.unicodeRounded . B.border
    $ C.str "25 kg"

weights :: Widget ()
weights = C.withBorderStyle doubleHorizontal $ C.hBox
    [ box1
    , C.str "\n\n" C.<=> B.hBorder
    , box1
    ]

box2 :: Widget ()
box2 = C.freezeBorders $ C.vBox
    [ C.hBox
        [ C.vLimit 3 B.vBorder
        , C.str "Resize horizontally to\nmove across the label\nbelow"
        , C.vLimit 3 B.vBorder
        ]
    , B.borderWithLabel (B.vBorder C.<+> C.str " Label " C.<+> B.vBorder) $ C.hBox
        [ C.str "               "
        , C.vBox [B.vBorder, C.str "L\na\nb\ne\nl", C.vLimit 3 B.vBorder]
        , C.str "\n\n\n Resize vertically to\n move across the label\n to the left\n\n\n\n\n" C.<=> B.hBorder
        ]
    ]

-- BYOB: build your own border
byob :: Widget ()
byob = C.vBox
    [              C.hBox [ corner   , top      , corner   ]
    , C.vLimit 6 $ C.hBox [ B.vBorder, mid      , B.vBorder]
    ,              C.hBox [ corner   , B.hBorder, corner   ]
    ]
    where
    top = B.hBorderWithLabel (C.str "BYOB")
    mid = C.center (C.str "If `border` is too easy,\nyou can build it yourself")
    corner = B.joinableBorder (pure False)

ui :: Widget ()
ui = C.vBox [weights, box2, byob]

main :: IO ()
main = M.simpleMain (C.joinBorders ui)