Code Monkey home page Code Monkey logo

Comments (10)

jtdaugherty avatar jtdaugherty commented on July 30, 2024

This is possible using the attribute management combinators; you can find them in the "Attribute management" section of Brick.Widgets.Core:

http://hackage.haskell.org/package/brick-0.6.4/docs/Brick-Widgets-Core.html#g:5

But the easiest way is to use withDefAttr, e.g.,

listWidget =
  hBox [ withDefAttr fooAttr $ str "foo"
       , str " "
       , withDefAttr barAttr $ str "bar"
       , str " "
       , withDefAttr quuxAttr $ str "quux"
       ]

and then be sure to assign those attribute map entries in your attribute map, e.g.,

App { appAttrMap = const $ attrMap defAttr mapping
    }
mapping =
  [ (fooAttr,  fg white)
  , (barAttr,  fg red)
  , (quuxAttr, blue `on` green)
  ]

You can also see some examples of the attribute API at work in programs/AttrDemo.hs.

If this helps, please feel free to close the issue; otherwise let me know what I can do. Thanks!

from brick.

listx avatar listx commented on July 30, 2024

Oh cool, I will have a look at this and report back my findings.

On Wed, May 25, 2016 at 4:50 PM, Jonathan Daugherty <
[email protected]> wrote:

This is possible using the attribute management combinators; you can find
them in the "Attribute management" section of Brick.Widgets.Core:

http://hackage.haskell.org/package/brick-0.6.4/docs/Brick-Widgets-Core.html#g:5

But the easiest way is to use withDefAttr, e.g.,

listWidget =
hBox [ withDefAttr fooAttr $ str "foo"
, str " "
, withDefAttr barAttr $ str "bar"
, str " "
, withDefAttr quuxAttr $ str "quux"
]

and then be sure to assign those attribute map entries in your attribute
map, e.g.,

App { appAttrMap = const $ attrMap defAttr mapping
}
mapping =
[ (fooAttr, fg white)
, (barAttr, fg red)
, (quuxAttr, blue on green)
]

You can also see some examples of the attribute API at work in
programs/AttrDemo.hs.

If this helps, please feel free to close the issue; otherwise let me know
what I can do. Thanks!


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#58 (comment)

from brick.

listx avatar listx commented on July 30, 2024

Thanks, I got it working. I don't understand why I was thinking so narrowly before. The key is that the List widget comes with the wonderful renderList function, which allows one to supply a custom rendering function for the arbitrary element type in the List widget. My List elements are of a custom type and I used your hBox [<widgets>] approach to populate a list of str widgets for each element's subparts ("foo", "bar", and "quux" in my original post).

Thanks again!

from brick.

jtdaugherty avatar jtdaugherty commented on July 30, 2024

Great! I'm glad it's working out for you. Keep in mind that if you think of something about the docs that could have made this clearer, I'm interested to know what that would be.

from brick.

listx avatar listx commented on July 30, 2024

Hm, maybe the docs could say that we could simulate a spreadsheet by having each element in a List widget be composed of multiple 'column' subparts, optionally colored differently? Or just implement it in a new ListDemo2.hs program?

from brick.

jtdaugherty avatar jtdaugherty commented on July 30, 2024

Actually, the existing ListDemo already does this using withAttr (which is similar to withDefAttr).

from brick.

listx avatar listx commented on July 30, 2024

Yes it does, although I think it would be clearer if visually it had something more like a spreadsheet. Shrug but then again it could be just me. Your call!

from brick.

jtdaugherty avatar jtdaugherty commented on July 30, 2024

I only hesitate to program a spreadsheet as a demo because it's such a specific application idea, and I'm concerned that having a demo app for every way to use brick would get unmanageable because it's intended to let you do whatever you want. :)

With that said, I can see how it wouldn't be obvious to do what you want to do from the outset, and it will require learning the library well enough to imagine ways to get the layout you desire. My intention is to provide enough basic building blocks that just about anything can be built from them, if they are well understood.

from brick.

listx avatar listx commented on July 30, 2024

I agree with your concerns. Well, in the coming month(s) I will be
releasing a project that uses all of this functionality so maybe a
screenshot of that project would be good enough. We could have a "Brick
usage examples in the wild" section either in the Github wiki or directly
in the README and have links to screenshots and such.

On Thu, May 26, 2016 at 3:22 PM, Jonathan Daugherty <
[email protected]> wrote:

I only hesitate to program a spreadsheet as a demo because it's such a
specific application idea, and I'm concerned that having a demo app for
every way to use brick would get unmanageable because it's intended to let
you do whatever you want. :)

With that said, I can see how it wouldn't be obvious to do what you want
to do from the outset, and it will require learning the library well enough
to imagine ways to get the layout you desire. My intention is to provide
enough basic building blocks that just about anything can be built from
them, if they are well understood.


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#58 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAsSbQQ20_1riJoj2__ZCGGUnjF_yAYOks5qFh0xgaJpZM4Im7jE
.

from brick.

jtdaugherty avatar jtdaugherty commented on July 30, 2024

That would be fantastic! I would be happy to add it to the README.

from brick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.