henriklovhaug / md-tui

Markdown renderer in the terminal
GNU Affero General Public License v3.0
206 stars 13 forks source link

Unable to render outside of Y:0 coordinates #152

Open orhun opened 2 months ago

orhun commented 2 months ago

Again, this is something that I experienced in #150

I want to add a vertical padding to the rendered area so that it is not at y:0 all the time.

I modified the example (demo.rs) like so:

 use ratatui::backend::{Backend, CrosstermBackend};
-use ratatui::layout::Rect;
+use ratatui::layout::{Constraint, Direction, Layout, Rect};
 use ratatui::{Frame, Terminal};

 const CONTENT: &str = r#"
@@ -73,7 +73,10 @@ impl App {
     }

     fn draw(&mut self, frame: &mut Frame) {
-        self.area = frame.area();
+        self.area = Layout::default()
+            .direction(Direction::Vertical)
+            .constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
+            .split(frame.area())[1];

         self.markdown = Some(parser::parse_markdown(
             None,

https://github.com/orhun/md-tui/blob/e0a5778d364775304c112562489329f55c45e68b/examples/demo.rs#L76

So that markdown should be rendered starting from the half of the screen. However:

image

It is sitting still at Y:0

I think this is about clipping the upper bounds of Y, reference: https://github.com/henriklovhaug/md-tui/blob/abb51636ca5df433b7060a7624b7d24cdf0b0ab7/src/pages/markdown_renderer.rs#L42

Or somewhere in there Y is reseted to 0

orhun commented 2 months ago

In the meantime I came up a workaround like so:

if let Component::TextComponent(c) = child {
    let mut c = c.clone();
    c.set_y_offset(c.y_offset() + 2); // shift the text
    frame.render_widget(c, area);
}
orhun commented 1 month ago

Well that workaround does not really work well with scrolling :/ I get the same issue.

henriklovhaug commented 1 month ago

Hmmm. Could you provide an example where I could test it?

orhun commented 1 month ago

To test it you can try the updated code that I shared in the initial comment above.

Or you can watch towards the end of the this stream (after 1hr 10m) to see me struggle about this :D

I updated the workaround to skip rendering when the components are out of the render area: https://github.com/orhun/git-cliff/commit/65327c0aed9fded7dd7536ceb70474e87586f0e4