String coloring
This commit is contained in:
@@ -30,7 +30,12 @@ struct History {
|
||||
|
||||
struct ColoredString {
|
||||
Range range;
|
||||
Color color;
|
||||
Color text_color;
|
||||
Color highlight_background_color;
|
||||
|
||||
uint8_t use_text_color;
|
||||
uint8_t use_highlight_background_color;
|
||||
uint8_t use_underline;
|
||||
};
|
||||
|
||||
struct Window {
|
||||
|
||||
@@ -76,9 +76,9 @@ int main() {
|
||||
|
||||
InitArena(&FrameArena);
|
||||
InitArena(&PermArena);
|
||||
float font_size = 64;
|
||||
float font_size = 14;
|
||||
float font_spacing = 1;
|
||||
Font font = LoadFontEx("C:/Windows/Fonts/times.ttf", (int)font_size, NULL, 250);
|
||||
Font font = LoadFontEx("C:/Windows/Fonts/consola.ttf", (int)font_size, NULL, 250);
|
||||
|
||||
Array<Window> windows = {};
|
||||
{
|
||||
@@ -434,7 +434,20 @@ int main() {
|
||||
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});
|
||||
|
||||
ColoredString colored = {};
|
||||
colored.range = range;
|
||||
colored.use_text_color = true;
|
||||
colored.use_underline = true;
|
||||
colored.text_color = RED;
|
||||
focused_window->colored_strings.add(colored);
|
||||
|
||||
colored = {};
|
||||
colored.range = range;
|
||||
colored.use_highlight_background_color = true;
|
||||
colored.highlight_background_color = {0, 50, 150, 50};
|
||||
focused_window->colored_strings.add(colored);
|
||||
|
||||
base_index += index + seek.len;
|
||||
s = s.skip(index + seek.len);
|
||||
}
|
||||
@@ -649,20 +662,35 @@ 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, color);
|
||||
|
||||
bool underline = false;
|
||||
bool highlight = false;
|
||||
Color highlight_color = MAGENTA;
|
||||
Color text_color = BLACK;
|
||||
|
||||
For(window.colored_strings) {
|
||||
if (InRange(col.pos, it.range)) {
|
||||
if (it.use_underline) underline = true;
|
||||
if (it.use_text_color) text_color = it.text_color;
|
||||
if (it.use_highlight_background_color) {
|
||||
highlight = true;
|
||||
highlight_color = it.highlight_background_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (highlight) DrawRectangleRec(ToRectangle(rect), highlight_color);
|
||||
DrawTextCodepoint(font, col.codepoint, rect.min, font_size, text_color);
|
||||
if (underline) {
|
||||
Rect2 rect_copy = rect;
|
||||
Rect2 r = CutBottom(&rect_copy, 1) - Vec2{0, window.font_size * 0.1f};
|
||||
DrawRectangleRec(ToRectangle(r), text_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user