Skip to content

Commit fd97d81

Browse files
authored
[Renderers/termbox] fixed horizontal text culling bug (#525)
1 parent 7216815 commit fd97d81

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

renderers/termbox2/clay_renderer_termbox2.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
Copyright (c) 2025 Mivirl
55
6+
altered by Godje (Sep 2025)
7+
68
This software is provided 'as-is', without any express or implied warranty.
79
In no event will the authors be held liable for any damages arising from the
810
use of this software.
@@ -1616,6 +1618,20 @@ void Clay_Termbox_Render(Clay_RenderCommandArray commands)
16161618

16171619
Clay_StringSlice *text = &render_data.stringContents;
16181620
int32_t i = 0;
1621+
1622+
// culling text characters that are outside of the layout
1623+
int h_clip = 0 - cell_box.x;
1624+
while(h_clip > 0 && i < text->length){
1625+
uint32_t ch = ' ';
1626+
int codepoint_length = tb_utf8_char_to_unicode(&ch, text->chars + i);
1627+
if (0 > codepoint_length) {
1628+
clay_tb_assert(false, "Invalid utf8");
1629+
}
1630+
i += codepoint_length;
1631+
h_clip -= 1;
1632+
}
1633+
1634+
// printing the rest of the characters
16191635
for (int y = box_begin_y; y < box_end_y; ++y) {
16201636
for (int x = box_begin_x; x < box_end_x;) {
16211637
uint32_t ch = ' ';

0 commit comments

Comments
 (0)