Comments (7)
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.
By offset you mean the amount of actual lines of the terminal that paragraph ends up taking ?
from ratatui.
@blacknon could you pls provide a code example?
from ratatui.
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.
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.
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.
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)
- Provide a mechanism to retrieve the pixel(x,y) where a mouse is clicked on canvas HOT 4
- Remove `block::Title` and `block::Position`, add `Block::top_title()` and `Block::bottom_title()` for ergonomics HOT 3
- Constructors
- Async Counter Demo does not correctly compile due to trait bound errors HOT 1
- Add Rows and Columns iterators to Rect HOT 2
- Change `Alignment` enum to be direction agnostic HOT 9
- Add Style and Alignment to Text HOT 1
- Support hsluv color constructor HOT 5
- Add tick counter to `Frame` HOT 7
- Highlight symbol should be `Text` or `Cell` HOT 2
- Examples use unreleased code incompatible with 0.25.0 HOT 5
- Specification for `Table` widget HOT 2
- Create an interactive example that helps show how layout constraints interact
- fix apply deprecation in chart
- Document better frame diffing
- Add a span macro
- Create constructors for Padding that make it more clear
- Add theme module HOT 2
- Update table example HOT 4
- Implement Widget for Text HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ratatui.