Skip to content

Handle character width and offscreen rendering#51

Merged
Shresht7 merged 8 commits into
mainfrom
unicode-width
Jul 7, 2026
Merged

Handle character width and offscreen rendering#51
Shresht7 merged 8 commits into
mainfrom
unicode-width

Conversation

@Shresht7

@Shresht7 Shresht7 commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Implement logic to account for character widths in rendering and movement calculations.

Introduce a private width field for entities and optimize boundary checks for offscreen conditions.

Adjust random symbol generation to respect column widths and improve trail clearing logic for right-to-left movement.

Without the unicode-width changes, horizontal/diagonal movements had these issues:

  • Positioning: Entities were spaced by i (1 column) instead of i * width, so double-width chars overlapped each other
  • Speed: rain() moved x by speed_x instead of speed_x * width, so horizontal flow was too slow for wide chars
  • Off-screen detection: Checked e.x >= columns instead of e.x + width >= columns, so entities hung off the right edge
  • Trail clearing: Used a single space instead of " ".repeat(width), leaving ghost characters
  • Background population (the --leave-trail option): Wrote a char to every column, so double-width chars stomped on each other
  • is_offscreen took &mut self unnecessarily

In the case when moving from right-to-left, printing whitespace to clear the trail was causing issues when clearing the last element which had already been cleared.

The logic now checks if the x position is less than the width of the symbol to render and adjusts the clear logic accordingly
@Shresht7 Shresht7 self-assigned this Jul 7, 2026
@Shresht7 Shresht7 added the bug Something isn't working label Jul 7, 2026
@Shresht7 Shresht7 merged commit 6449d04 into main Jul 7, 2026
1 check passed
@Shresht7 Shresht7 deleted the unicode-width branch July 7, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant