Code Monkey home page Code Monkey logo

Comments (7)

joshka avatar joshka commented on May 12, 2024 2

I wonder if we could get some of this by implementing StatefulWidget on Paragraph, which fills a ParagraphState { render_height: usize, render_width: usize } struct?

If implementing this, care should be taken to ensure that this struct is extensible for scrolling purposes, and we should initially gate it behind an experimental feature flag (as this particular feature will probably churn based on future scrolling / wrapping changes).

from ratatui.

mindoodoo avatar mindoodoo commented on May 12, 2024

By offset you mean the amount of actual lines of the terminal that paragraph ends up taking ?

from ratatui.

sayanarijit avatar sayanarijit commented on May 12, 2024

@blacknon could you pls provide a code example?

from ratatui.

max-ishere avatar max-ishere commented on May 12, 2024

I need this too to implement a dynamic footer. the footer will occupy 100%w x N lines.

But actually what I'd like to have is a way to render generic dynamic widgets. Here's what I'm thinking (pseudo rust)

let widget: impl DynamicSizedWidget;

let size_hint = DynamicSize::new(10.., 1..5)
    //or maybe more verbose api:
    .width(10..)
    .height(1..5);

let size = some_buffer.render_dynamic_size(widget, size_hint);

let chunks = Layout.constraint(
    Length(terminal.size - size.height), ...;

What I think would be really cool is if you have a widget that you render or estimate the size of with these size hints and then combine together. When they're combined you can also give them the exact size that should be arbitrary, so you should be able to shrink the buffer. And at this stage is when the border is drawn and stuff is resized to fit the new size.

from ratatui.

blacknon avatar blacknon commented on May 12, 2024

Sorry for the late reply.

By offset you mean the amount of actual lines of the terminal that paragraph ends up taking ?

Yes, that right.
In ncurses, it's can use getmaxyx to get the overall size including line wrapping in window and pad, but I felt we need a similar feature.

from ratatui.

deifactor avatar deifactor commented on May 12, 2024

I worry that if we take that approach, it'll encourage more and more use of StatefulWidget to implement "draw, and also return some additional data as well".

I propose an approach along the lines of:

use std::cell::Cell;

#[derive(Copy, Clone)]
struct Size {
    width: usize,
    height: usize,
}

struct Paragraph {
    rendered_size: Cell<Option<Size>>,
}

impl Paragraph {
    fn size(&self) -> Size {
        if self.rendered_size.get().is_none() {
            let actual_size = todo!("layout etc");
            self.rendered_size.set(Some(actual_size));
        }
        self.rendered_size.get().unwrap()
    }
}

And then .draw() can just call size().

from ratatui.

a-kenji avatar a-kenji commented on May 12, 2024

We already have a pattern that can do that in Block.inner() , we could do something similar with the paragraph. I imagine this will allow it to be fairly composable.

from ratatui.

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.