Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

What is the purpose of a list of widgets for appDraw? What are vty layers?

44 views
Skip to first unread message

Chris Stryczynski

unread,
Jun 9, 2018, 3:02:52 PM6/9/18
to Brick Users
Hello :), thanks for making this library - probably the best documentation I've seen for a Haskell library!

What is the purpose of having appDraw return multiple widgets ( `[Widet a]`)? I don't understand what it represents - the guide mentions 'vty layers' but I'm not familiar with this either. Does one layer `Widget`(?) get written over another if there are multiple layers?

I've got a short example here:

```
module Main where

import Brick
import Brick.Widgets.Border
import Graphics.Vty.Attributes

type AppState = Int

app :: App AppState () String
app =
  App
  { appDraw = appDraw'
  , appChooseCursor =
      const . const Nothing                     :: AppState -> [CursorLocation String] -> Maybe (CursorLocation String)
  , appHandleEvent =
      (\appState _ -> Brick.halt appState)  :: AppState -> BrickEvent String () -> EventM String (Next AppState)
  , appStartEvent = return                      :: AppState -> EventM String AppState
  , appAttrMap = const (attrMap (defAttr) ([])) :: AppState -> AttrMap
  }

appDraw' :: AppState -> [Widget String]
appDraw' _ = [
    hBox [str "Abc...", str "Xyz...", str "Woohoo"]
  , (str "Hello," <=> str "World!" <=> hBorder)
  , hBox [str "Abc", str "Xyz", str "Woohoo"]
  ]


main :: IO ()
main = do
  let initialState = 5
  defaultMain app initialState >>= print
```

This outputs:
```
Abc...Xyz...Woohoo                                         
World!                                                     
───────────────────────────────────────────────────────────
```

I was expecting something like:
```
Abc...Xyz...Woohoo
Hello World
--------------------
AbcXyzWoohoo
```

Jonathan Daugherty

unread,
Jun 9, 2018, 7:27:32 PM6/9/18
to Chris Stryczynski, Brick Users
Hi,

> Hello :), thanks for making this library - probably the best
> documentation I've seen for a Haskell library!

Thanks!

> What is the purpose of having appDraw return multiple widgets (
> `[Widet a]`)? I don't understand what it represents - the guide
> mentions 'vty layers' but I'm not familiar with this either. Does
> one layer `Widget`(?) get written over another if there are multiple
> layers?
>
> ```
> Abc...Xyz...Woohoo
> World!
> ───────────────────────────────────────────────────────────
> ```

The word "layer" here has the same meaning that it does in image
editors: the list of things returned by appDraw is a list of layers,
with the top-most layer first in the list. As in an image editor, visual
elements in a layer above another layer obscure elements in the layer
underneath, meaning you can use this functionality to do things like
overlay UI elements on top of other ones such as menus, pop-up dialogs,
etc. - whatever you want.

To see an example of this in action, try out the layer demonstration
program:

$ cabal new-build -f demos
$ $(find dist-newstyle -type f -name brick-layer-demo)

Hope that helps,

--
Jonathan Daugherty
Reply all
Reply to author
Forward
0 new messages