Coloring strings

This commit is contained in:
Krzosa Karol
2024-07-04 07:35:29 +02:00
parent e7f53d2c07
commit 21df381d12
2 changed files with 24 additions and 7 deletions

View File

@@ -171,6 +171,11 @@ bool AreEqual(Cursor a, Cursor b) {
return result;
}
bool InRange(int64_t a, Range b) {
bool result = a >= b.min && a < b.max;
return result;
}
void MergeSort(int64_t Count, Edit *First, Edit *Temp) {
// SortKey = range.min
if (Count == 1) {

View File

@@ -87,7 +87,6 @@ int main() {
window.font = font;
window.font_size = font_size;
window.font_spacing;
window.colored_strings.allocator = FrameArena;
InitArena(&window.layout_arena);
InitBuffer(GetSystemAllocator(), &window.buffer);
@@ -115,6 +114,7 @@ int main() {
For(windows) {
Assert(it.cursors.len);
it.main_cursor_begin_frame = it.cursors[0];
it.colored_strings = {FrameArena};
}
frame += 1;
@@ -428,11 +428,15 @@ int main() {
}
{
int64_t index = 0;
String buffer_string = GetString(focused_window->buffer);
if (Seek(buffer_string, "number", &index)) {
Range range = {index, index + 6};
String seek = "number";
int64_t index = 0;
int64_t base_index = 0;
String s = GetString(focused_window->buffer);
while (Seek(s, seek, &index)) {
Range range = {base_index + index, base_index + index + seek.len};
focused_window->colored_strings.add({range, RED});
base_index += index + seek.len;
s = s.skip(index + seek.len);
}
}
@@ -452,7 +456,6 @@ int main() {
// Draw and layout window overlay
Vec2 mouse = GetMousePosition();
{
// @todo: why are we drawing this here??
DrawRectangleRec(ToRectangle(window.rect), WHITE);
DrawRectangleRec(ToRectangle(line_number_rect), WHITE);
@@ -645,12 +648,21 @@ int main() {
ForItem(col, visible_columns) {
Rect2 rect = {col.rect.min + window.rect.min - window.scroll, col.rect.max + window.rect.min - window.scroll};
Color color = BLACK;
For(window.colored_strings) {
if (InRange(col.pos, it.range)) {
color = it.color;
break;
}
}
if (col.codepoint == '\n') {
DrawTextEx(font, "\\n", rect.min, font_size, font_spacing, GRAY);
} else if (col.codepoint == '\0') {
DrawTextEx(font, "\\0", rect.min, font_size, font_spacing, {255, 0, 0, 150});
} else if ((col.codepoint != ' ') && (col.codepoint != '\t')) {
DrawTextCodepoint(font, col.codepoint, rect.min, font_size, BLACK);
DrawTextCodepoint(font, col.codepoint, rect.min, font_size, color);
}
}