Code Monkey home page Code Monkey logo

Comments (4)

jtdaugherty avatar jtdaugherty commented on July 30, 2024

The hSize field of a Widget just describes the behavior of that widget rather than configuring its behavior, so setting it will only change how containers behave when rendering that widget. To actually get the behavior you want, you need to compose your string with a fill or pad operation so that extra spaces are rendered. You're on the right track with hLimit, though - that (in effect) takes a greedy widget and makes it fixed, both by setting the hSize and by cropping the resulting limited widget. Does that make sense?

Here is a way to do what you described. Assuming you have a list with element type (Int, String) as depicted above, here is what your list item draw function would look like (without logic for handling the selection since I'm only trying to illustrate the widget composition):

drawElem :: Bool -> (Int, String) -> Widget
drawElem _sel (i, s) =
  -- The integer portion
  let intPart = str $ show i
      -- The integer portion, padded (so it is now "greedy")
      intPartGreedy = padRight Max intPart
      -- The width-limited integer portion
      intPartFixed = hLimit 10 intPartGreedy
      -- The string portion
      strPart = str s
      -- The whole thing
      final = intPartFixed <+> strPart
  -- Finally, we right-pad the whole thing so as to make the cursor
  -- attribute go all the way to the right hand side of the list.
  in padRight Max final

from brick.

Profpatsch avatar Profpatsch commented on July 30, 2024

Thanks, I missed the Max Constructor for Padding. How does Pad Int work, though? It looks to me like it simply adds spaces to the end.

from brick.

jtdaugherty avatar jtdaugherty commented on July 30, 2024

Yes, you have it right. The integer argument specifies the number of rows or columns to pad.

On Nov 29, 2015, at 8:58 AM, Profpatsch [email protected] wrote:

Thanks, I missed the Max Constructor for Padding. How does Pad Int work, though? It looks to me like it simply adds spaces to the end.

ā€”
Reply to this email directly or view it on GitHub.

from brick.

jtdaugherty avatar jtdaugherty commented on July 30, 2024

If you decide that this approach works for you, please close the issue (or let me know what else I can do to help).

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.