packages feed

geomancy-layout-0.2.1 / test / Menu / Grids.hs

module Menu.Grids  ( tracks  , spans  , interplay  ) whereimport Data.Function ((&))import Geomancy.Layout.Alignment qualified as Alignmentimport Geomancy.Layout.Viewimport Geomancy.Vec2 (vec2)import Geomancy.Vec4 (vec4)import Menu.Kitlight, dim, columnHue, rowHue, fillHue, smallHue, cellHue, spanHue, panelHue :: Stringlight = "#e8e6e0"dim = "#a9a7a0"columnHue = "#3d5a8f"rowHue = "#8f5a3d"fillHue = "#4f8f6f"smallHue = "#c9a23c"cellHue = "#3d5a8f"spanHue = "#7a4f8f"panelHue = "#5a5f6b"caption :: String -> UIcaption = label (font 18 light)page :: String -> [String] -> [UI] -> UIpage heading notes body =  padding_ (vec4 80 80 80 80) $    vstack 24 Alignment.leftTop $      label (heavy $ font 34 light) heading        : vstack 6 Alignment.leftTop (map (label $ font 18 dim) notes)        : bodysized :: String -> String -> Float -> Float -> String -> UIsized name hue w h text =  frame_ (vec2 w h) $    zstack Alignment.center      [ fill name (paint hue & rounded 6)      , caption text      ]loose :: String -> String -> String -> UIloose name hue text =  zstack Alignment.center    [ fill name (paint hue & faded 0.45 & rounded 6 & rimmed hue)    , caption text    ]band :: String -> FrameBounds -> String -> UIband name bounds text = flexible_ bounds Alignment.center (loose name spanHue text)tracks :: UItracks =  page "Grid tracks"    [ "Columns take their widest sized cell, rows their tallest. Unsized fills take their whole slot without widening it."    , "The 60x30 cell is smaller than its slot, so it sits at the slot's top-left, by the grid's alignment."    ]    [ grid 12 12 Alignment.leftTop        [ [spacer_, sized "col 1" columnHue 260 60 "260 wide", sized "col 2" columnHue 140 60 "140 wide", sized "col 3" columnHue 380 60 "380 wide"]        , [sized "row 1" rowHue 120 50 "50 tall", loose "r1c1" fillHue "unsized", loose "r1c2" fillHue "unsized", loose "r1c3" fillHue "unsized"]        , [sized "row 2" rowHue 120 120 "120 tall", loose "r2c1" fillHue "unsized", sized "small" smallHue 60 30 "60x30", loose "r2c3" fillHue "unsized"]        , [sized "row 3" rowHue 120 80 "80 tall", loose "r3c1" fillHue "unsized", loose "r3c2" fillHue "unsized", loose "r3c3" fillHue "unsized"]        ]    ]spans :: UIspans =  page "Grid spans"    [ "Cells fill the grid row by row, skipping slots that earlier row spans cover. A span stops at a slot that is already taken."    , "Right: a fixed header wider than the two columns under it grows both of them evenly."    ]    [ hstack 80 Alignment.leftTop        [ grid 12 12 Alignment.leftTop            [ [span_ 3 1 (band "header" (unbounded & heightWithin 56 56 & fillWidth) "span 3 x 1"), sized "corner" cellHue 140 56 "140 x 56"]            , [span_ 1 2 (band "sidebar" (unbounded & widthWithin 160 160 & fillHeight) "span 1 x 2"), sized "a" cellHue 140 70 "140 x 70", sized "b" cellHue 140 70 "140 x 70", span_ 1 3 (band "tall" filling "span 1 x 3")]            , [span_ 2 1 (band "wide" (unbounded & heightWithin 70 70 & fillWidth) "span 2 x 1")]            , [span_ 4 1 (band "cut" (unbounded & heightWithin 56 56 & fillWidth) "span 4 x 1, cut to 3")]            ]        , grid 12 12 Alignment.leftTop            [ [span_ 2 1 (sized "wide header" spanHue 400 50 "400 wide, over two 140 columns")]            , [sized "left" cellHue 140 60 "140", sized "right" cellHue 140 60 "140"]            ]        ]    ]interplay :: UIinterplay =  page "Grids with other views"    [ "Left: a spacer column pushes values to the panel's right edge, a divider spans every column, and a background sits behind the grid."    , "Right: 16:9 cards keep their height in a row, captions centre under them, and a badge overlays a card. Below: a grid with an open column fills a row."    ]    [ hstack 60 Alignment.leftTop [settings, cards]    , hstack 0 Alignment.leftTop        [ grid 12 0 Alignment.leftTop [[sized "fixed A" cellHue 200 60 "200 wide", spacer_, sized "fixed B" cellHue 200 60 "200 wide"]]        , sized "panel" panelHue 300 60 "300 wide panel"        ]    ]  where    settings =      flexible_ (unbounded & widthWithin 640 640) Alignment.leftTop $        backdrop "settings panel" (paint "#1d2230" & rounded 10 & rimmed "#3a4560") $          padding_ (vec4 20 20 20 20) $            grid 24 14 Alignment.leftMiddle              [ [caption "Master volume", spacer_, caption "80%"]              , [caption "Resolution", spacer_, caption "1920 x 1080"]              , [caption "V-Sync", spacer_, caption "On"]              , [span_ 3 1 (divider "settings rule" (paint "#3a4560"))]              , [caption "Language", spacer_, caption "English"]              ]    cards =      grid 16 8 Alignment.center        [ [card "card 1" "#6b2a2a", card "card 2" "#2a4a6b", overlay Alignment.rightTop badge (card "card 3" "#2a6b44")]        , [caption "Expansion", caption "Season pass", caption "Soundtrack"]        ]    card name hue = flexible_ (unbounded & widthWithin 240 240) Alignment.center $ aspect_ (vec2 16 9) (art name (paint hue & rimmed "#ffffff40"))    badge = offset_ (vec2 8 (-8)) $ glyph "badge" (paint "#e0b040" & rounded 6) 26 Tile "!"