чување b96e9c288f0b59eff244a6130e3e7c01b30b08bf
родитељ 86e8884d8269bc422e158d157c20801ea58ebc44
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Thu, 8 Jul 2021 11:09:38 +0200
Continued work on u32_draw_string wrt tabs, p2
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | draw.c | | | 55 | ++++++++++++++++++++++++++++++++++++++++++++----------- |
| A | tabs.draft | | | 58 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
измењених датотека: 2, додавања: 102(+), брисања: 11(-)
diff --git a/draw.c b/draw.c
@@ -285,25 +285,58 @@ u32_draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg,
}
}
- while (ps && *ps && col < max_cols-padding_right)
+ while (ps && *ps && col < display_starts_at+max_cols-padding_right)
{
if (*ps == '\t')
{
- int i = 0;
- for (i = 0; i < TAB_SIZE -
- ((col - display_starts_at) % TAB_SIZE)
- && col+i < max_cols-padding_right; i++)
- tb_change_cell(x+padding_left+col+i, y, ' ',
- fg, bg);
- col += i;
- ps++;
+ if (col < display_starts_at)
+ {
+ if (col+TAB_SIZE >= display_starts_at)
+ {
+ for (int j = 0; j <
+ TAB_SIZE-(display_starts_at
+ -col); j++)
+ tb_change_cell(x+padding_left+
+ col+j, y, ' ', fg, bg);
+ col += TAB_SIZE;
+ }
+ else
+ {
+ int limit = MIN(display_starts_at+
+ max_cols-padding_right-col,
+ TAB_SIZE);
+ for (int j = 0; j < limit; j++)
+ tb_change_cell(x+padding_left+
+ col+j, y, ' ', fg, bg);
+ col += limit;
+ }
+ }
+ else
+ {
+ if (col >= display_starts_at)
+ tb_change_cell(x+padding_left+col,
+ y, *ps, fg, bg);
+ col++;
+ }
+ /*
+ *int i = 0;
+ *for (i = 0; i < TAB_SIZE -
+ * ((col - display_starts_at) % TAB_SIZE)
+ * && col+i < max_cols-padding_right; i++)
+ * tb_change_cell(x+padding_left+col+i, y, ' ',
+ * fg, bg);
+ *col += i;
+ *ps++;
+ */
}
else
{
- tb_change_cell(x+padding_left+col, y, *ps, fg, bg);
- ps++;
+ if (col >= display_starts_at)
+ tb_change_cell(x+padding_left+col, y, *ps,
+ fg, bg);
col++;
}
+ ps++;
}
}
diff --git a/tabs.draft b/tabs.draft
@@ -0,0 +1,58 @@
+
+ s - string
+ x - starting column
+ y - starting row
+ c - first screen column
+ t - index in string containing \t
+ max_cols = w - max screen width
+ col = d - current screen column
+
+ w = padding_left + ... + padding_right
+
+
+01 234567890123456 7
+f\t test_with_tabs\t;
+012[45670123456701234567]123456701234567012345670123456701234567
+f------>test_with_tabs->]
+f [----test_with_tabs--]
+012[45678901234567890123]567890123456789012345678901234567890123456789
+ |
+ t = 1
+012[45678901234567890123]567890123456789012345678901234567890123456789
+ | |<--c+w=24
+ c = 4 |
+ [01234567890123456789]1234567890123456789012345678901234567890123456789
+ |
+ w = 20
+-----------------------|<--c+w=24
+
+int i = 0;
+int d = 0;
+while (i < len && d < c+w)
+{
+ if (s[i] == '\t')
+ {
+ if (d < c)
+ {
+ if (d+8 >= c)
+ for (int j = 0; j < 8-(c-d); j++)
+ print(' ');
+ d += 8;
+ }
+ else
+ {
+ for (int j = 0; j < MIN(c+w-d, 8); j++)
+ print(' ');
+ d += MIN(c+w-d, 8);
+ }
+ }
+ else
+ {
+ if (d >= c)
+ print(s[i]);
+ d++;
+ }
+
+ i++;
+}
+