Skip to content

Rendering issue when increasing frame size beyond a certain point #1441

@YS-L

Description

@YS-L

Description

I'm encountering a rendering issue where the rendered text appears to "warp" around instead of being placed at the specified positions. The problem seems to manifest when the number of cells in the frame increases beyond a certain point (e.g. by reducing font size while maintaining the terminal's physical size).

To Reproduce

I'm using this simple code based on ratatui/templates to fill the frame with short text.

    fn draw(&mut self, frame: &mut Frame) {
        let area = frame.area();
        let buf = frame.buffer_mut();
        for (i, y) in (area.y..area.bottom()).enumerate() {
            let s = if i == 0 {
                format!("Total area: {:?}", area.area())
            } else {
                format!("#{:02}", i)
            };
            buf.set_span(area.x, y, &Span::from(s.as_str()), s.len() as u16);
        }
    }

It should produce something simple like this, where the text is aligned to the left:

Image

This works for typical frame sizes, but when increasing the frame size beyond a certain point, some of the text is rendered in the middle of the screen, which shouldn't happen since the code always specifies the same area.x as the x position.

Expected behavior

All the text is aligned to the left regardless of frame size.

Screenshots

It works as expected for a while, but something strange happens when the frame size exceeds a certain size (I suspect 65536):

Image

Environment

  • OS: Linux
  • Terminal Emulator: xterm
  • Font: Monospace Regular
  • Crate version: main branch (514d273)
  • Backend: crossterm

Additional context

  • Same behavior when using v0.28.1

  • Cannot reproduce when using v0.27.0, where it looks like this:
    Image

    It seems the area is capped below 65536 somehow, possibly due to area clamping that is now removed.

  • I just realized that the list example in the repo might be affected by the same issue, though the symptoms are not exactly the same. This is what I get when the frame size is sufficiently large:
    Image

    which is quite different compared to the UI when rendered properly:
    Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions