New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paragraph: I would like to have the ability to get the offset of the text being drawn in Paragraph
.
#136
Comments
By offset you mean the amount of actual lines of the terminal that paragraph ends up taking ? |
@blacknon could you pls provide a code example? |
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. |
Sorry for the late reply.
Yes, that right. |
I wonder if we could get some of this by implementing 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). |
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 |
We already have a pattern that can do that in |
Paragraph
.Paragraph
.
Problem
When displaying text in
Paragraph
, the calculation of the maximum number of lines is complicated by the need to wrap long horizontal lines.For this reason, we would like the ability to get the block size of the text being displayed in a
Paragraph
.The text was updated successfully, but these errors were encountered: