benjajaja / ratatui-image

Ratatui widget for rendering image graphics in terminals that support it
https://crates.io/crates/ratatui-image
MIT License
110 stars 16 forks source link

scrollview support #28

Closed birbe closed 3 months ago

birbe commented 3 months ago

can I use this in combination with tui-scrollview? https://crates.io/crates/tui-scrollview

I tried doing it myself, but the image would either not render or would render in fragments in the terminal (with wezterm)

benjajaja commented 3 months ago

No. I took a quick glance at https://github.com/joshka/tui-scrollview/blob/3157616fe57d9dac717d4d33b1585f3c84231b9f/src/scroll_view.rs#L194 and it seems like the "child" widget is rendered into a buffer of some desired "full" size, and then the buffer is sliced and diced into the "viewport". This works perfectly for all normal widgets, but ratatui-image outputs some special control characters into the top-left-most cell, which causes the image to be drawn at the determined size ("inner" size here).

For something like this to work, we would need to know both the total inner scroll area, and the "viewport" area (offset and real size). This information is only available to ScrollView statefully at render time, so it would probably need to be some kind of callback to pass this back to the rendered widget, which would be very difficult to implement.

Then, additionally, ratatui-image would need to be able to render something like a "viewport" resize option. Recently the Resize::Crop has become configurable to cut off left/top, so something like this would be feasible, but it would have to be implemented.

birbe commented 3 months ago

thank you for the response!

benjajaja commented 3 months ago

@birbe for reference, ratatui-image is used in iamb (source) in some scrolling view, it just can't work only through the render API due to how images are not simply cells like with normal widgets.