From 4ea381d6a8a2a560213de896bab2aad02a70f937 Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 15 Aug 2023 10:50:30 -0300 Subject: some settings stuff --- buffer.c | 41 ++++++++++++++++++++--------------------- build.c | 2 +- config.c | 20 ++++++++++++++++++++ find.c | 28 ++++++++++++++-------------- ide-definitions.c | 3 +-- ide-document-link.c | 2 +- ide-hover.c | 7 +++---- ide-rename-symbol.c | 11 +++++------ ide-signature-help.c | 13 ++++++------- main.c | 11 +++++------ menu.c | 25 ++++++++++--------------- node.c | 7 +++---- ted.c | 8 ++++---- ted.h | 11 ++++++++++- ui.c | 41 +++++++++++++++++++---------------------- 15 files changed, 122 insertions(+), 108 deletions(-) diff --git a/buffer.c b/buffer.c index 2743a05..7ad8921 100644 --- a/buffer.c +++ b/buffer.c @@ -3209,14 +3209,13 @@ void buffer_render(TextBuffer *buffer, Rect r) { float char_height = text_font_char_height(font); Ted *ted = buffer->ted; - const u32 *colors = settings->colors; const float padding = settings->padding; const float border_thickness = settings->border_thickness; u32 start_line = buffer_first_rendered_line(buffer); // line to start rendering from - u32 border_color = colors[COLOR_BORDER]; // color of border around buffer + u32 border_color = settings_color(settings, COLOR_BORDER); // color of border around buffer // bounding box around buffer gl_geometry_rect_border(rect4(x1, y1, x2, y2), border_thickness, border_color); @@ -3251,7 +3250,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { strbuf_printf(str, "%" PRIu32, line + 1); // convert line number to string float x = x1 + line_number_width - text_get_size_vec2(font, str).x; // right justify // set color - rgba_u32_to_floats(colors[line == cursor_line ? COLOR_CURSOR_LINE_NUMBER : COLOR_LINE_NUMBERS], + settings_color_floats(settings, line == cursor_line ? COLOR_CURSOR_LINE_NUMBER : COLOR_LINE_NUMBERS, text_state.color); text_state.x = x; text_state.y = y; text_state_break_kerning(&text_state); @@ -3263,7 +3262,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { x1 += line_number_width; x1 += 2; // a little bit of padding // line separating line numbers from text - gl_geometry_rect(rect_xywh(x1, y1, border_thickness, y2 - y1), colors[COLOR_LINE_NUMBERS_SEPARATOR]); + gl_geometry_rect(rect_xywh(x1, y1, border_thickness, y2 - y1), settings_color(settings, COLOR_LINE_NUMBERS_SEPARATOR)); x1 += border_thickness; } @@ -3305,7 +3304,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { if (!buffer->is_line_buffer) { // highlight line cursor is on Rect hl_rect = rect_xywh(x1, cursor_display_pos.y, x2-x1-1, char_height); buffer_clip_rect(buffer, &hl_rect); - gl_geometry_rect(hl_rect, colors[COLOR_CURSOR_LINE_BG]); + gl_geometry_rect(hl_rect, settings_color(settings, COLOR_CURSOR_LINE_BG)); } @@ -3346,7 +3345,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { (vec2){(float)highlight_width, char_height} ); buffer_clip_rect(buffer, &hl_rect); - gl_geometry_rect(hl_rect, colors[buffer->view_only ? COLOR_VIEW_ONLY_SELECTION_BG : COLOR_SELECTION_BG]); + gl_geometry_rect(hl_rect, settings_color(settings, buffer->view_only ? COLOR_VIEW_ONLY_SELECTION_BG : COLOR_SELECTION_BG)); } index1 = 0; } @@ -3394,7 +3393,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { text_state.max_x = x2; text_state.max_y = y2; if (!syntax_highlighting) - rgba_u32_to_floats(colors[COLOR_TEXT], text_state.color); + settings_color_floats(settings, COLOR_TEXT, text_state.color); buffer->first_line_on_screen = start_line; buffer->last_line_on_screen = 0; @@ -3412,7 +3411,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { if (syntax_highlighting) { SyntaxCharType type = char_types[i]; ColorSetting color = syntax_char_type_to_color_setting(type); - rgba_u32_to_floats(colors[color], text_state.color); + rgba_u32_to_floats(settings_color(settings, color), text_state.color); } buffer_render_char(buffer, font, &text_state, c); } @@ -3445,7 +3444,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { vec2 gl_pos = buffer_pos_to_pixels(buffer, pos); Rect hl_rect = rect(gl_pos, (vec2){text_font_char_width(font, c), char_height}); if (buffer_clip_rect(buffer, &hl_rect)) { - gl_geometry_rect(hl_rect, colors[COLOR_MATCHING_BRACKET_HL]); + gl_geometry_rect(hl_rect, settings_color(settings, COLOR_MATCHING_BRACKET_HL)); } } } @@ -3469,11 +3468,11 @@ void buffer_render(TextBuffer *buffer, Rect r) { if (is_on) { if (buffer_clip_rect(buffer, &cursor_rect)) { // draw cursor - u32 color = colors[COLOR_CURSOR]; - if (buffer->view_only) - color = colors[COLOR_VIEW_ONLY_CURSOR]; + u32 color = settings_color(settings, buffer->view_only ? COLOR_VIEW_ONLY_CURSOR : COLOR_CURSOR); if (error_animation) { - color = color_interpolate(maxf(0, 2 * ((float)(error_animation_dt / error_animation_duration) - 0.5f)), colors[COLOR_CURSOR_ERROR], colors[COLOR_CURSOR]); + color = color_interpolate(maxf(0, 2 * ((float)(error_animation_dt / error_animation_duration) - 0.5f)), + settings_color(settings, COLOR_CURSOR_ERROR), + settings_color(settings, COLOR_CURSOR)); } gl_geometry_rect(cursor_rect, color); @@ -3561,7 +3560,7 @@ void buffer_dedent_cursor_line(TextBuffer *buffer) { void buffer_comment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { - Settings *settings = buffer_settings(buffer); + const Settings *settings = buffer_settings(buffer); const char *start = settings->comment_start, *end = settings->comment_end; if (!start[0] && !end[0]) return; @@ -3616,7 +3615,7 @@ static bool buffer_line_ends_with_ascii(TextBuffer *buffer, u32 line_idx, const } void buffer_uncomment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { - Settings *settings = buffer_settings(buffer); + const Settings *settings = buffer_settings(buffer); const char *start = settings->comment_start, *end = settings->comment_end; if (!start[0] && !end[0]) return; @@ -3640,7 +3639,7 @@ void buffer_uncomment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { } void buffer_toggle_comment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { - Settings *settings = buffer_settings(buffer); + const Settings *settings = buffer_settings(buffer); const char *start = settings->comment_start, *end = settings->comment_end; if (!start[0] && !end[0]) return; @@ -3667,7 +3666,7 @@ void buffer_toggle_comment_selection(TextBuffer *buffer) { void buffer_highlight_lsp_range(TextBuffer *buffer, LSPRange range, ColorSetting color) { Font *font = buffer_font(buffer); - const u32 *colors = buffer_settings(buffer)->colors; + const Settings *settings = buffer_settings(buffer); const float char_height = text_font_char_height(font); BufferPos range_start = buffer_pos_from_lsp(buffer, range.start); BufferPos range_end = buffer_pos_from_lsp(buffer, range.end); @@ -3677,14 +3676,14 @@ void buffer_highlight_lsp_range(TextBuffer *buffer, LSPRange range, ColorSetting vec2 b = buffer_pos_to_pixels(buffer, range_end); b.y += char_height; Rect r = rect_endpoints(a, b); buffer_clip_rect(buffer, &r); - gl_geometry_rect(r, colors[color]); + gl_geometry_rect(r, settings_color(settings, color)); } else if (range_end.line - range_start.line < 1000) { // prevent gigantic highlights from slowing things down // multiple lines. vec2 a = buffer_pos_to_pixels(buffer, range_start); vec2 b = buffer_pos_to_pixels(buffer, buffer_pos_end_of_line(buffer, range_start.line)); b.y += char_height; Rect r1 = rect_endpoints(a, b); buffer_clip_rect(buffer, &r1); - gl_geometry_rect(r1, colors[COLOR_HOVER_HL]); + gl_geometry_rect(r1, settings_color(settings, COLOR_HOVER_HL)); for (u32 line = range_start.line + 1; line < range_end.line; ++line) { // these lines are fully contained in the range. @@ -3694,7 +3693,7 @@ void buffer_highlight_lsp_range(TextBuffer *buffer, LSPRange range, ColorSetting b = buffer_pos_to_pixels(buffer, end); b.y += char_height; Rect r = rect_endpoints(a, b); buffer_clip_rect(buffer, &r); - gl_geometry_rect(r, colors[COLOR_HOVER_HL]); + gl_geometry_rect(r, settings_color(settings, COLOR_HOVER_HL)); } // last line @@ -3702,6 +3701,6 @@ void buffer_highlight_lsp_range(TextBuffer *buffer, LSPRange range, ColorSetting b = buffer_pos_to_pixels(buffer, range_end); b.y += char_height; Rect r2 = rect_endpoints(a, b); buffer_clip_rect(buffer, &r2); - gl_geometry_rect(r2, colors[COLOR_HOVER_HL]); + gl_geometry_rect(r2, settings_color(settings, COLOR_HOVER_HL)); } } diff --git a/build.c b/build.c index df8f36f..265c7ac 100644 --- a/build.c +++ b/build.c @@ -103,7 +103,7 @@ void build_start_with_command(Ted *ted, const char *command) { } void build_start(Ted *ted) { - Settings *settings = ted_active_settings(ted); + const Settings *settings = ted_active_settings(ted); const char *command = settings->build_command; { diff --git a/config.c b/config.c index 665f124..6dce3bc 100644 --- a/config.c +++ b/config.c @@ -1313,3 +1313,23 @@ void settings_color_floats(const Settings *settings, ColorSetting color, float f rgba_u32_to_floats(settings_color(settings, color), f); } + +u16 settings_tab_width(const Settings *settings) { + return settings->tab_width; +} + +bool settings_indent_with_spaces(const Settings *settings) { + return settings->indent_with_spaces; +} + +bool settings_auto_indent(const Settings *settings) { + return settings->auto_indent; +} + +float settings_border_thickness(const Settings *settings) { + return settings->border_thickness; +} + +float settings_padding(const Settings *settings) { + return settings->padding; +} diff --git a/find.c b/find.c index 8cf2e04..f5fd9ce 100644 --- a/find.c +++ b/find.c @@ -332,9 +332,9 @@ void find_menu_frame(Ted *ted, Rect menu_bounds) { const float char_height = text_font_char_height(font); const Settings *settings = ted_active_settings(ted); + const u32 color_text = settings_color(settings, COLOR_TEXT); const float padding = settings->padding; const float border_thickness = settings->border_thickness; - const u32 *colors = settings->colors; bool const replace = ted->replace; const float line_buffer_height = ted_line_buffer_height(ted); @@ -346,8 +346,8 @@ void find_menu_frame(Ted *ted, Rect menu_bounds) { u32 last_rendered_line = buffer_last_rendered_line(buffer); - gl_geometry_rect(menu_bounds, colors[COLOR_MENU_BG]); - gl_geometry_rect_border(menu_bounds, border_thickness, colors[COLOR_BORDER]); + gl_geometry_rect(menu_bounds, settings_color(settings, COLOR_MENU_BG)); + gl_geometry_rect_border(menu_bounds, border_thickness, settings_color(settings, COLOR_BORDER)); rect_shrink(&menu_bounds, border_thickness); float x1, y1, x2, y2; @@ -404,7 +404,7 @@ void find_menu_frame(Ted *ted, Rect menu_bounds) { pos2.y += char_height; Rect hl_rect = rect4(pos1.x, pos1.y, pos2.x, pos2.y); if (buffer_clip_rect(buffer, &hl_rect)) - gl_geometry_rect(hl_rect, colors[COLOR_FIND_HL]); + gl_geometry_rect(hl_rect, settings_color(settings, COLOR_FIND_HL)); } } @@ -418,12 +418,12 @@ void find_menu_frame(Ted *ted, Rect menu_bounds) { replace_buffer_bounds.pos.y += line_buffer_height + padding; - button_render(ted, button_prev, prev_text, colors[COLOR_TEXT]); - button_render(ted, button_next, next_text, colors[COLOR_TEXT]); + button_render(ted, button_prev, prev_text, color_text); + button_render(ted, button_next, next_text, color_text); if (replace) { - button_render(ted, button_replace, replace_text, colors[COLOR_TEXT]); - button_render(ted, button_replace_find, replace_find_text, colors[COLOR_TEXT]); - button_render(ted, button_replace_all, replace_all_text, colors[COLOR_TEXT]); + button_render(ted, button_replace, replace_text, color_text); + button_render(ted, button_replace_find, replace_find_text, color_text); + button_render(ted, button_replace_all, replace_all_text, color_text); } { @@ -436,16 +436,16 @@ void find_menu_frame(Ted *ted, Rect menu_bounds) { strbuf_printf(str, "%" PRIu32 " of %" PRIu32, match_idx + 1, arr_len(ted->find_results)); } text_get_size(font, str, &w, &h); - text_utf8(font, str, x2 - w, rect_ymid(find_buffer_bounds) - h * 0.5f, colors[COLOR_TEXT]); + text_utf8(font, str, x2 - w, rect_ymid(find_buffer_bounds) - h * 0.5f, color_text); x2 -= w; find_buffer_bounds.size.x -= w; } - text_utf8(font_bold, find_text, x1, y1, colors[COLOR_TEXT]); + text_utf8(font_bold, find_text, x1, y1, color_text); y1 += line_buffer_height + padding; if (replace) { - text_utf8(font_bold, replace_with_text, x1, y1, colors[COLOR_TEXT]); + text_utf8(font_bold, replace_with_text, x1, y1, color_text); y1 += line_buffer_height + padding; } @@ -462,9 +462,9 @@ void find_menu_frame(Ted *ted, Rect menu_bounds) { String32 term = buffer_get_line(find_buffer, 0); if (ted->find_invalid_pattern) - gl_geometry_rect(find_buffer_bounds, colors[COLOR_NO] & 0xFFFFFF3F); // invalid regex + gl_geometry_rect(find_buffer_bounds, settings_color(settings, COLOR_NO) & 0xFFFFFF3F); // invalid regex else if (term.len && !ted->find_results) - gl_geometry_rect(find_buffer_bounds, colors[COLOR_CANCEL] & 0xFFFFFF3F); // no matches + gl_geometry_rect(find_buffer_bounds, settings_color(settings, COLOR_CANCEL) & 0xFFFFFF3F); // no matches gl_geometry_draw(); } diff --git a/ide-definitions.c b/ide-definitions.c index b853207..8fe7582 100644 --- a/ide-definitions.c +++ b/ide-definitions.c @@ -183,7 +183,6 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res const LSPResponseWorkspaceSymbols *response_syms = &response->data.workspace_symbols; const LSPSymbolInformation *symbols = response_syms->symbols; const Settings *settings = ted_active_settings(ted); - const u32 *colors = settings->colors; definitions_clear_entries(defs); arr_set_len(defs->all_definitions, arr_len(symbols)); @@ -193,7 +192,7 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res def->name = str_dup(lsp_response_string(response, symbol->name)); SymbolKind kind = symbol_kind_to_ted(symbol->kind); - def->color = colors[color_for_symbol_kind(kind)]; + def->color = settings_color(settings, color_for_symbol_kind(kind)); def->from_lsp = true; def->position = lsp_location_start_position(symbol->location); const char *container_name = lsp_response_string(response, symbol->container); diff --git a/ide-document-link.c b/ide-document-link.c index 0c2d8cd..2d43807 100644 --- a/ide-document-link.c +++ b/ide-document-link.c @@ -68,7 +68,7 @@ static Rect document_link_get_rect(Ted *ted, DocumentLink *link) { } void document_link_frame(Ted *ted) { - Settings *settings = ted_active_settings(ted); + const Settings *settings = ted_active_settings(ted); if (!settings->document_links) { document_link_clear(ted); return; diff --git a/ide-hover.c b/ide-hover.c index 28bc1af..ae870c3 100644 --- a/ide-hover.c +++ b/ide-hover.c @@ -156,7 +156,6 @@ void hover_frame(Ted *ted, double dt) { const float padding = settings->padding; const float border = settings->border_thickness; - const u32 *colors = settings->colors; const char *text = hover->text; Font *font = ted->font; float char_height = text_font_char_height(font); @@ -192,9 +191,9 @@ void hover_frame(Ted *ted, double dt) { state.max_y = y + height; Rect rect = rect_xywh(x - padding, y - padding, width + 2*padding, height + 2*padding); - gl_geometry_rect(rect, colors[COLOR_HOVER_BG]); - gl_geometry_rect_border(rect, border, colors[COLOR_HOVER_BORDER]); - rgba_u32_to_floats(colors[COLOR_HOVER_TEXT], state.color); + gl_geometry_rect(rect, settings_color(settings, COLOR_HOVER_BG)); + gl_geometry_rect_border(rect, border, settings_color(settings, COLOR_HOVER_BORDER)); + settings_color_floats(settings, COLOR_HOVER_TEXT, state.color); text_utf8_with_state(font, &state, text); } diff --git a/ide-rename-symbol.c b/ide-rename-symbol.c index cc8f176..ed7483c 100644 --- a/ide-rename-symbol.c +++ b/ide-rename-symbol.c @@ -67,7 +67,6 @@ static void rename_symbol_menu_render(Ted *ted) { } const Settings *settings = buffer_settings(buffer); const float padding = settings->padding; - const u32 *colors = settings->colors; const float line_buffer_height = ted_line_buffer_height(ted); u32 sym_start=0, sym_end=0; @@ -86,8 +85,8 @@ static void rename_symbol_menu_render(Ted *ted) { vec2 p1 = buffer_pos_to_pixels(buffer, bpos1); p1.y += text_font_char_height(buffer_font(buffer)); Rect highlight = rect_endpoints(p0, p1); - gl_geometry_rect_border(highlight, settings->border_thickness, colors[COLOR_BORDER]); - gl_geometry_rect(highlight, colors[COLOR_HOVER_HL]); + gl_geometry_rect_border(highlight, settings->border_thickness, settings_color(settings, COLOR_BORDER)); + gl_geometry_rect(highlight, settings_color(settings, COLOR_HOVER_HL)); const float width = ted_get_menu_width(ted); const float height = line_buffer_height + 2 * padding; @@ -95,12 +94,12 @@ static void rename_symbol_menu_render(Ted *ted) { .pos = {(ted->window_width - width) / 2, padding}, .size = {width, height}, }; - gl_geometry_rect(bounds, colors[COLOR_MENU_BG]); - gl_geometry_rect_border(bounds, settings->border_thickness, colors[COLOR_BORDER]); + gl_geometry_rect(bounds, settings_color(settings, COLOR_MENU_BG)); + gl_geometry_rect_border(bounds, settings->border_thickness, settings_color(settings, COLOR_BORDER)); gl_geometry_draw(); rect_shrink(&bounds, padding); const char *text = "Rename symbol to..."; - text_utf8(ted->font_bold, text, bounds.pos.x, bounds.pos.y, colors[COLOR_TEXT]); + text_utf8(ted->font_bold, text, bounds.pos.x, bounds.pos.y, settings_color(settings, COLOR_TEXT)); rect_shrink_left(&bounds, text_get_size_vec2(ted->font_bold, text).x + padding); text_render(ted->font_bold); diff --git a/ide-signature-help.c b/ide-signature-help.c index 5611c19..7bde85c 100644 --- a/ide-signature-help.c +++ b/ide-signature-help.c @@ -39,7 +39,7 @@ static void signature_help_clear(SignatureHelp *help) { static void signature_help_send_request(Ted *ted) { SignatureHelp *help = ted->signature_help; - Settings *settings = ted_active_settings(ted); + const Settings *settings = ted_active_settings(ted); if (!settings->signature_help_enabled) { signature_help_clear(help); return; @@ -86,7 +86,7 @@ void signature_help_close(Ted *ted) { void signature_help_process_lsp_response(Ted *ted, const LSPResponse *response) { SignatureHelp *help = ted->signature_help; - Settings *settings = ted_active_settings(ted); + const Settings *settings = ted_active_settings(ted); if (!settings->signature_help_enabled) return; if (response->request.type != LSP_REQUEST_SIGNATURE_HELP) @@ -129,7 +129,7 @@ void signature_help_process_lsp_response(Ted *ted, const LSPResponse *response) } void signature_help_frame(Ted *ted) { - Settings *settings = ted_active_settings(ted); + const Settings *settings = ted_active_settings(ted); if (!settings->signature_help_enabled) return; @@ -145,7 +145,6 @@ void signature_help_frame(Ted *ted) { if (!buffer) return; - u32 *colors = settings->colors; float border = settings->border_thickness; Rect buf_rect = buffer_rect(buffer); @@ -162,9 +161,9 @@ void signature_help_frame(Ted *ted) { } float x = buf_rect.pos.x, y = rect_y2(buf_rect) - height; gl_geometry_rect(rect_xywh(x, y - border, width, border), - colors[COLOR_AUTOCOMPLETE_BORDER]); + settings_color(settings, COLOR_AUTOCOMPLETE_BORDER)); gl_geometry_rect(rect_xywh(x, y, width, height), - colors[COLOR_AUTOCOMPLETE_BG]); + settings_color(settings, COLOR_AUTOCOMPLETE_BG)); // draw the signatures for (int s = 0; s < signature_count; ++s) { @@ -176,7 +175,7 @@ void signature_help_frame(Ted *ted) { state.min_y = y; state.max_x = rect_x2(buf_rect); state.max_y = rect_y2(buf_rect); - rgba_u32_to_floats(colors[COLOR_TEXT], state.color); + settings_color_floats(settings, COLOR_TEXT, state.color); text_utf8_with_state(font, &state, signature->label_pre); text_utf8_with_state(font_bold, &state, signature->label_active); diff --git a/main.c b/main.c index b207233..e068783 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,5 @@ /* TODO: -- public Settings API - use home/end with selector FUTURE FEATURES: @@ -619,7 +618,7 @@ int main(int argc, char **argv) { { - Settings *active_settings = ted_active_settings(ted); + const Settings *active_settings = ted_active_settings(ted); // we don't properly handle variable-width fonts text_font_set_force_monospace(ted->font, active_settings->force_monospace); text_font_set_force_monospace(ted->font_bold, active_settings->force_monospace); @@ -637,7 +636,7 @@ int main(int argc, char **argv) { case SDL_MOUSEWHEEL: { if (ted_is_ctrl_down(ted)) { // adjust text size with ctrl+scroll - Settings *settings = ted_active_settings(ted); + const Settings *settings = ted_active_settings(ted); scroll_wheel_text_size_change += settings->ctrl_scroll_adjust_text_size * event.wheel.preciseY; } else if (key_modifier == 0) { // scroll with mouse wheel @@ -752,7 +751,7 @@ int main(int argc, char **argv) { command_execute_string_argument(ted, CMD_INSERT_TEXT, text); // check for trigger character LSP *lsp = buffer_lsp(buffer); - Settings *settings = buffer_settings(buffer); + const Settings *settings = buffer_settings(buffer); if (lsp && settings->trigger_characters) { u32 last_code_point = (u32)strlen(text) - 1; while (last_code_point > 0 && @@ -928,7 +927,7 @@ int main(int argc, char **argv) { { // background shader - Settings *s = ted_active_settings(ted); + const Settings *s = ted_active_settings(ted); if (s->bg_shader) { GLuint shader = s->bg_shader->shader; GLuint buffer = s->bg_shader->buffer; @@ -1065,7 +1064,7 @@ int main(int argc, char **argv) { // message box if (*ted->message_shown) { double time_passed = ted->frame_time - ted->message_time; - Settings *settings = ted_active_settings(ted); + const Settings *settings = ted_active_settings(ted); if (time_passed > settings->error_display_time) { // stop showing error *ted->message_shown = '\0'; diff --git a/menu.c b/menu.c index a1efad5..7c7f16f 100644 --- a/menu.c +++ b/menu.c @@ -93,7 +93,6 @@ Rect selection_menu_render_bg(Ted *ted) { const Settings *settings = ted_active_settings(ted); const float menu_width = ted_get_menu_width(ted); const float padding = settings->padding; - const u32 *colors = settings->colors; const float window_width = ted->window_width, window_height = ted->window_height; Rect bounds = rect_xywh( window_width * 0.5f - 0.5f * menu_width, padding, @@ -104,8 +103,8 @@ Rect selection_menu_render_bg(Ted *ted) { rect_coords(bounds, &x1, &y1, &x2, &y2); // menu rectangle & border - gl_geometry_rect(bounds, colors[COLOR_MENU_BG]); - gl_geometry_rect_border(bounds, settings->border_thickness, colors[COLOR_BORDER]); + gl_geometry_rect(bounds, settings_color(settings, COLOR_MENU_BG)); + gl_geometry_rect_border(bounds, settings->border_thickness, settings_color(settings, COLOR_BORDER)); gl_geometry_draw(); x1 += padding; @@ -117,11 +116,10 @@ Rect selection_menu_render_bg(Ted *ted) { void menu_render(Ted *ted) { const Settings *settings = ted_active_settings(ted); - const u32 *colors = settings->colors; const float window_width = ted->window_width, window_height = ted->window_height; const MenuInfo *info = &ted->all_menus[ted->menu_open_idx]; // render backdrop - gl_geometry_rect(rect_xywh(0, 0, window_width, window_height), colors[COLOR_MENU_BACKDROP]); + gl_geometry_rect(rect_xywh(0, 0, window_width, window_height), settings_color(settings, COLOR_MENU_BACKDROP)); gl_geometry_draw(); if (info->render) @@ -388,7 +386,6 @@ static void command_selector_update(Ted *ted) { static void command_selector_render(Ted *ted) { const Settings *settings = ted_active_settings(ted); const float padding = settings->padding; - const u32 *colors = settings->colors; const float line_buffer_height = ted_line_buffer_height(ted); Font *font_bold = ted->font_bold; @@ -399,7 +396,7 @@ static void command_selector_render(Ted *ted) { // argument field const char *text = "Argument"; - text_utf8(font_bold, text, x1, y1, colors[COLOR_TEXT]); + text_utf8(font_bold, text, x1, y1, settings_color(settings, COLOR_TEXT)); float x = x1 + text_get_size_vec2(font_bold, text).x + padding; buffer_render(ted->argument_buffer, rect4(x, y1, x2, y1 + line_buffer_height)); @@ -451,14 +448,13 @@ static void goto_line_menu_update(Ted *ted) { static void goto_line_menu_render(Ted *ted) { const Settings *settings = ted_active_settings(ted); const float padding = settings->padding; - const u32 *colors = settings->colors; const float window_width = ted->window_width, window_height = ted->window_height; Font *font_bold = ted->font_bold; float menu_height = ted_line_buffer_height(ted) + 2 * padding; Rect r = rect_xywh(padding, window_height - menu_height - padding, window_width - 2 * padding, menu_height); - gl_geometry_rect(r, colors[COLOR_MENU_BG]); - gl_geometry_rect_border(r, settings->border_thickness, colors[COLOR_BORDER]); + gl_geometry_rect(r, settings_color(settings, COLOR_MENU_BG)); + gl_geometry_rect_border(r, settings->border_thickness, settings_color(settings, COLOR_BORDER)); const char *text = "Go to line..."; vec2 text_size = text_get_size_vec2(font_bold, text); float x1=0, y1=0, x2=0, y2=0; @@ -468,7 +464,7 @@ static void goto_line_menu_render(Ted *ted) { x2 -= padding; y2 -= padding; // render "Go to line" text - text_utf8(font_bold, text, x1, 0.5f * (y1 + y2 - text_size.y), colors[COLOR_TEXT]); + text_utf8(font_bold, text, x1, 0.5f * (y1 + y2 - text_size.y), settings_color(settings, COLOR_TEXT)); x1 += text_size.x + padding; gl_geometry_draw(); text_render(font_bold); @@ -505,19 +501,18 @@ static void shell_menu_render(Ted *ted) { const float line_buffer_height = ted_line_buffer_height(ted); const Settings *settings = ted_active_settings(ted); const float padding = settings->padding; - const u32 *colors = settings->colors; const float width = ted_get_menu_width(ted); const float height = line_buffer_height + 2 * padding; Rect bounds = { .pos = {(ted->window_width - width) / 2, padding}, .size = {width, height}, }; - gl_geometry_rect(bounds, colors[COLOR_MENU_BG]); - gl_geometry_rect_border(bounds, settings->border_thickness, colors[COLOR_BORDER]); + gl_geometry_rect(bounds, settings_color(settings, COLOR_MENU_BG)); + gl_geometry_rect_border(bounds, settings->border_thickness, settings_color(settings, COLOR_BORDER)); gl_geometry_draw(); rect_shrink(&bounds, padding); const char *text = "Run"; - text_utf8(ted->font_bold, text, bounds.pos.x, bounds.pos.y, colors[COLOR_TEXT]); + text_utf8(ted->font_bold, text, bounds.pos.x, bounds.pos.y, settings_color(settings, COLOR_TEXT)); rect_shrink_left(&bounds, text_get_size_vec2(ted->font_bold, text).x + padding); text_render(ted->font_bold); buffer_render(ted->line_buffer, bounds); diff --git a/node.c b/node.c index 9b7fbed..f224a7f 100644 --- a/node.c +++ b/node.c @@ -293,7 +293,6 @@ void node_frame(Ted *ted, Node *node, Rect r) { const Settings *settings = ted_active_settings(ted); if (node->tabs) { bool is_active = node == ted->active_node; - const u32 *colors = settings->colors; Font *font = ted->font; const float border_thickness = settings->border_thickness; const float char_height = text_font_char_height(font); @@ -395,7 +394,7 @@ void node_frame(Ted *ted, Node *node, Rect r) { } // tab border - gl_geometry_rect_border(tab_rect, border_thickness, colors[COLOR_BORDER]); + gl_geometry_rect_border(tab_rect, border_thickness, settings_color(settings, COLOR_BORDER)); rect_shrink(&tab_rect, border_thickness); // tab title @@ -408,7 +407,7 @@ void node_frame(Ted *ted, Node *node, Rect r) { strbuf_printf(tab_title, "%s", filename); } text_state.max_x = rect_x2(tab_rect); - rgba_u32_to_floats(colors[COLOR_TEXT], text_state.color); + settings_color_floats(settings, COLOR_TEXT, text_state.color); text_state.x = tab_rect.pos.x; text_state.y = tab_rect.pos.y; text_state_break_kerning(&text_state); @@ -416,7 +415,7 @@ void node_frame(Ted *ted, Node *node, Rect r) { if (i == node->active_tab) { // highlight active tab - gl_geometry_rect(tab_rect, colors[is_active ? COLOR_ACTIVE_TAB_HL : COLOR_SELECTED_TAB_HL]); + gl_geometry_rect(tab_rect, settings_color(settings, is_active ? COLOR_ACTIVE_TAB_HL : COLOR_SELECTED_TAB_HL)); // set window title to active tab's title strbuf_printf(ted->window_title, "ted %s", tab_title); } diff --git a/ted.c b/ted.c index c06611c..730280a 100644 --- a/ted.c +++ b/ted.c @@ -180,7 +180,7 @@ void *ted_realloc(Ted *ted, void *p, size_t new_size) { } char *ted_get_root_dir_of(Ted *ted, const char *path) { - Settings *settings = ted_active_settings(ted); + const Settings *settings = ted_active_settings(ted); return settings_get_root_dir(settings, path); } @@ -237,7 +237,7 @@ LSP *ted_get_lsp_by_id(Ted *ted, LSPID id) { } LSP *ted_get_lsp(Ted *ted, const char *path, Language language) { - Settings *settings = ted_get_settings(ted, path, language); + const Settings *settings = ted_get_settings(ted, path, language); if (!settings->lsp_enabled) return NULL; @@ -293,7 +293,7 @@ LSP *ted_active_lsp(Ted *ted) { } u32 ted_active_color(Ted *ted, ColorSetting color) { - return ted_active_settings(ted)->colors[color]; + return settings_color(ted_active_settings(ted), color); } void ted_path_full(Ted *ted, const char *relpath, char *abspath, size_t abspath_size) { @@ -405,7 +405,7 @@ void ted_load_fonts(Ted *ted) { } ted_free_fonts(ted); - Settings *settings = ted_active_settings(ted); + const Settings *settings = ted_active_settings(ted); ted->font = ted_load_multifont(ted, settings->font); if (!ted->font) { ted->font = ted_load_multifont(ted, "assets/font.ttf"); diff --git a/ted.h b/ted.h index f01ea2e..07c50c2 100644 --- a/ted.h +++ b/ted.h @@ -813,7 +813,16 @@ char *settings_get_root_dir(const Settings *settings, const char *path); u32 settings_color(const Settings *settings, ColorSetting color); /// get color as four floats void settings_color_floats(const Settings *settings, ColorSetting color, float f[4]); - +/// get tab width +u16 settings_tab_width(const Settings *settings); +/// get whether to indent with spaces +bool settings_indent_with_spaces(const Settings *settings); +/// get whether auto-indent is enabled +bool settings_auto_indent(const Settings *settings); +/// get border thickness +float settings_border_thickness(const Settings *settings); +/// get padding +float settings_padding(const Settings *settings); // === find.c === /// which buffer will be searched? diff --git a/ui.c b/ui.c index afa1c5b..8c0350f 100644 --- a/ui.c +++ b/ui.c @@ -600,14 +600,13 @@ char *file_selector_update(Ted *ted, FileSelector *fs) { void file_selector_render(Ted *ted, FileSelector *fs) { const Settings *settings = ted_active_settings(ted); - const u32 *colors = settings->colors; Rect bounds = fs->bounds; Font *font = ted->font, *font_bold = ted->font_bold; float padding = settings->padding; float char_height = text_font_char_height(font); if (*fs->title) { - text_utf8(font_bold, fs->title, bounds.pos.x, bounds.pos.y, colors[COLOR_TEXT]); + text_utf8(font_bold, fs->title, bounds.pos.x, bounds.pos.y, settings_color(settings, COLOR_TEXT)); rect_shrink_top(&bounds, text_font_char_height(font_bold) * 0.75f + padding); } @@ -623,7 +622,7 @@ void file_selector_render(Ted *ted, FileSelector *fs) { state.x = rect_x2(bounds) - text_width - padding; } state.y = bounds.pos.y; - rgba_u32_to_floats(colors[COLOR_TEXT], state.color); + settings_color_floats(settings, COLOR_TEXT, state.color); state.min_x = bounds.pos.x; state.max_x = rect_x2(bounds); @@ -643,16 +642,14 @@ vec2 button_get_size(Ted *ted, const char *text) { return vec2_add_const(text_get_size_vec2(ted->font, text), 2 * border_thickness); } -void button_render(Ted *ted, Rect button, const char *text, u32 color) { - const u32 *colors = ted_active_settings(ted)->colors; - +void button_render(Ted *ted, Rect button, const char *text, u32 color) { if (rect_contains_point(button, ted->mouse_pos)) { // highlight button when hovering over it u32 new_color = (color & 0xffffff00) | ((color & 0xff) / 3); gl_geometry_rect(button, new_color); } - gl_geometry_rect_border(button, ted_active_settings(ted)->border_thickness, colors[COLOR_BORDER]); + gl_geometry_rect_border(button, ted_active_settings(ted)->border_thickness, ted_active_color(ted, COLOR_BORDER)); gl_geometry_draw(); vec2 pos = rect_center(button); @@ -705,7 +702,6 @@ void popup_render(Ted *ted, u32 options, const char *title, const char *body) { Font *font_bold = ted->font_bold; Rect r, button_yes, button_no, button_cancel; const Settings *settings = ted_active_settings(ted); - const u32 *colors = settings->colors; const float char_height_bold = text_font_char_height(font_bold); const float padding = settings->padding; const float border_thickness = settings->border_thickness; @@ -716,20 +712,21 @@ void popup_render(Ted *ted, u32 options, const char *title, const char *body) { float y = r.pos.y; // popup rectangle - gl_geometry_rect(r, colors[COLOR_MENU_BG]); - gl_geometry_rect_border(r, border_thickness, colors[COLOR_BORDER]); + gl_geometry_rect(r, settings_color(settings, COLOR_MENU_BG)); + gl_geometry_rect_border(r, border_thickness, settings_color(settings, COLOR_BORDER)); // line separating text from body - gl_geometry_rect(rect_xywh(r.pos.x, y + char_height_bold, r.size.x, border_thickness), colors[COLOR_BORDER]); + gl_geometry_rect(rect_xywh(r.pos.x, y + char_height_bold, r.size.x, border_thickness), + settings_color(settings, COLOR_BORDER)); - if (options & POPUP_YES) button_render(ted, button_yes, "Yes", colors[COLOR_YES]); - if (options & POPUP_NO) button_render(ted, button_no, "No", colors[COLOR_NO]); - if (options & POPUP_CANCEL) button_render(ted, button_cancel, "Cancel", colors[COLOR_CANCEL]); + if (options & POPUP_YES) button_render(ted, button_yes, "Yes", settings_color(settings, COLOR_YES)); + if (options & POPUP_NO) button_render(ted, button_no, "No", settings_color(settings, COLOR_NO)); + if (options & POPUP_CANCEL) button_render(ted, button_cancel, "Cancel", settings_color(settings, COLOR_CANCEL)); // title text vec2 title_size = {0}; text_get_size(font_bold, title, &title_size.x, &title_size.y); vec2 title_pos = {(window_width - title_size.x) * 0.5f, y}; - text_utf8(font_bold, title, title_pos.x, title_pos.y, colors[COLOR_TEXT]); + text_utf8(font_bold, title, title_pos.x, title_pos.y, settings_color(settings, COLOR_TEXT)); text_render(font_bold); // body text @@ -742,7 +739,7 @@ void popup_render(Ted *ted, u32 options, const char *title, const char *body) { state.wrap = true; state.x = text_x1; state.y = y + char_height_bold + padding; - rgba_u32_to_floats(colors[COLOR_TEXT], state.color); + settings_color_floats(settings, COLOR_TEXT, state.color); text_utf8_with_state(font, &state, body); text_render(font); @@ -754,9 +751,9 @@ vec2 checkbox_frame(Ted *ted, bool *value, const char *label, vec2 pos) { float char_height = text_font_char_height(font); float checkbox_size = char_height; const Settings *settings = ted_active_settings(ted); - const u32 *colors = settings->colors; - float padding = settings->padding; - float border_thickness = settings->border_thickness; + const float padding = settings->padding; + const float border_thickness = settings->border_thickness; + const u32 color_text = settings_color(settings, COLOR_TEXT); Rect checkbox_rect = rect(pos, (vec2){checkbox_size, checkbox_size}); @@ -765,16 +762,16 @@ vec2 checkbox_frame(Ted *ted, bool *value, const char *label, vec2 pos) { } checkbox_rect.pos = vec2_add(checkbox_rect.pos, (vec2){0.5f, 0.5f}); - gl_geometry_rect_border(checkbox_rect, border_thickness, colors[COLOR_TEXT]); + gl_geometry_rect_border(checkbox_rect, border_thickness, color_text); if (*value) { Rect r = checkbox_rect; rect_shrink(&r, border_thickness + 2); - gl_geometry_rect(r, colors[COLOR_TEXT]); + gl_geometry_rect(r, color_text); } vec2 text_pos = vec2_add(pos, (vec2){checkbox_size + padding * 0.5f, 0}); vec2 size = text_get_size_vec2(font, label); - text_utf8(font, label, text_pos.x, text_pos.y, colors[COLOR_TEXT]); + text_utf8(font, label, text_pos.x, text_pos.y, color_text); gl_geometry_draw(); text_render(font); -- cgit v1.2.3