From 266af5ed551765ca22cb90819f570ff9371e279b Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 22 Dec 2022 22:36:27 -0500 Subject: even better-looking autocomplete --- autocomplete.c | 17 +++++++++++------ colors.c | 5 ++++- colors.h | 8 ++++++++ ted.cfg | 6 +++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/autocomplete.c b/autocomplete.c index 930cd90..db7a045 100644 --- a/autocomplete.c +++ b/autocomplete.c @@ -231,7 +231,7 @@ static void autocomplete_frame(Ted *ted) { break; } - float menu_width = 400, menu_height = (float)ncompletions * char_height + 2 * padding; + float menu_width = 400, menu_height = (float)ncompletions * char_height; if (ac->waiting_for_lsp) { menu_height = 200.f; @@ -256,8 +256,8 @@ static void autocomplete_frame(Ted *ted) { start_y += char_height; // put menu below cursor { Rect menu_rect = rect(V2(x, start_y), V2(menu_width, menu_height)); - gl_geometry_rect(menu_rect, colors[COLOR_MENU_BG]); - //gl_geometry_rect_border(menu_rect, 1, colors[COLOR_BORDER]); + gl_geometry_rect(menu_rect, colors[COLOR_AUTOCOMPLETE_BG]); + gl_geometry_rect_border(menu_rect, 1, colors[COLOR_AUTOCOMPLETE_BORDER]); ac->rect = menu_rect; } @@ -300,11 +300,16 @@ static void autocomplete_frame(Ted *ted) { for (size_t i = 0; i < ncompletions; ++i) { state.x = x; state.y = y; - gl_geometry_rect(rect(V2(x, y + char_height), - V2(menu_width, border_thickness)), - colors[COLOR_AUTOCOMPLETE_BORDER]); + if (i != ncompletions-1) { + gl_geometry_rect(rect(V2(x, y + char_height), + V2(menu_width, border_thickness)), + colors[COLOR_AUTOCOMPLETE_BORDER]); + } ColorSetting label_color = color_for_symbol_kind(completions[i].kind); + if (!settings->syntax_highlighting) + label_color = COLOR_TEXT; + rgba_u32_to_floats(colors[label_color], state.color); // draw icon diff --git a/colors.c b/colors.c index a684508..8e0ea52 100644 --- a/colors.c +++ b/colors.c @@ -57,10 +57,13 @@ static ColorSetting color_for_symbol_kind(SymbolKind kind) { case SYMBOL_CONSTANT: return COLOR_CONSTANT; case SYMBOL_TYPE: + return COLOR_AUTOCOMPLETE_TYPE; case SYMBOL_FIELD: case SYMBOL_VARIABLE: - case SYMBOL_OTHER: + return COLOR_AUTOCOMPLETE_VARIABLE; case SYMBOL_FUNCTION: + return COLOR_AUTOCOMPLETE_FUNCTION; + case SYMBOL_OTHER: return COLOR_TEXT; case SYMBOL_KEYWORD: return COLOR_KEYWORD; diff --git a/colors.h b/colors.h index 0c8b1ea..247261d 100644 --- a/colors.h +++ b/colors.h @@ -25,7 +25,11 @@ typedef enum { COLOR_SELECTED_TAB_HL, COLOR_FIND_HL, + COLOR_AUTOCOMPLETE_BG, COLOR_AUTOCOMPLETE_BORDER, + COLOR_AUTOCOMPLETE_FUNCTION, + COLOR_AUTOCOMPLETE_VARIABLE, + COLOR_AUTOCOMPLETE_TYPE, COLOR_YES, COLOR_NO, @@ -84,7 +88,11 @@ static ColorName const color_names[] = { {COLOR_STRING, "string"}, {COLOR_CHARACTER, "character"}, {COLOR_CONSTANT, "constant"}, + {COLOR_AUTOCOMPLETE_BG, "autocomplete-bg"}, {COLOR_AUTOCOMPLETE_BORDER, "autocomplete-border"}, + {COLOR_AUTOCOMPLETE_VARIABLE, "autocomplete-variable"}, + {COLOR_AUTOCOMPLETE_FUNCTION, "autocomplete-function"}, + {COLOR_AUTOCOMPLETE_TYPE, "autocomplete-type"}, {COLOR_YES, "yes"}, {COLOR_NO, "no"}, {COLOR_CANCEL, "cancel"}, diff --git a/ted.cfg b/ted.cfg index ff4f7e4..5bab390 100644 --- a/ted.cfg +++ b/ted.cfg @@ -234,7 +234,11 @@ no = #faa cancel = #ffa # autocomplete -autocomplete-border = #777 +autocomplete-bg = #000 +autocomplete-border = #fff +autocomplete-variable = #bfb +autocomplete-function = #aaf +autocomplete-type = #fac # Syntax highlighting keyword = #0c0 -- cgit v1.2.3