Code Monkey home page Code Monkey logo

Comments (3)

jtdaugherty avatar jtdaugherty commented on July 30, 2024

If you specifically want to work with lines that are strings, a custom widget such as the following can do what you want. If you want this behavior to work for arbitrary widgets, a viewport will be necessary and in that case rather than using visibility functions you'll need to call vScrollToEnd in your event handler whenever the window is resized (or whenever conditions change enough that you'd want to re-orient your cropped area).

module Main where
import Control.Lens ((^.))
import Control.Applicative ((<$>))
import Brick

alignBottom :: [String] -> Widget
alignBottom theLines =
    Widget Greedy Greedy $ do
        ctx <- getContext
        let numToDrop = max 0 $ length theLines - ctx^.availHeightL
            numEmptyLines = max 0 $ ctx^.availHeightL - length theLines
            linesWidget = str $ unlines $ drop numToDrop theLines
            emptyLines = vLimit numEmptyLines $ fill ' '
        render $ emptyLines <=> linesWidget

ui :: Widget
ui = alignBottom $ ("line " ++) <$> show <$> [1..20]

main :: IO ()
main = simpleMain ui

from brick.

lspitzner avatar lspitzner commented on July 30, 2024

Oh great, that works perfectly. I could have looked into custom widgets myself, but had assumed there would be a solution using the existing combinators.

Thanks for the quick reply!

from brick.

jtdaugherty avatar jtdaugherty commented on July 30, 2024

Great! I definitely want the built-in combinators to make writing custom widgets unnecessary, but there will definitely be cases where that's the only approach.

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.