summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-22 22:26:43 -0500
committerpommicket <pommicket@gmail.com>2022-12-22 22:26:43 -0500
commita9db20abd189c0d619a49583918c2784528838f6 (patch)
tree4e7e1f31001b03302ac4d85fbaf87dff4078d14e
parentc58f2247a9f9aaea86e461c176e4757e4d17292f (diff)
more exciting completion menu
-rw-r--r--autocomplete.c41
-rw-r--r--colors.c3
-rw-r--r--colors.h3
-rw-r--r--ted.cfg3
4 files changed, 43 insertions, 7 deletions
diff --git a/autocomplete.c b/autocomplete.c
index 24ca71b..930cd90 100644
--- a/autocomplete.c
+++ b/autocomplete.c
@@ -193,6 +193,24 @@ static void autocomplete_open(Ted *ted) {
}
}
+static char symbol_kind_icon(SymbolKind k) {
+ switch (k) {
+ case SYMBOL_FUNCTION:
+ return 'f';
+ case SYMBOL_FIELD:
+ return 'm';
+ case SYMBOL_TYPE:
+ return 't';
+ case SYMBOL_CONSTANT:
+ return 'c';
+ case SYMBOL_VARIABLE:
+ return 'v';
+ case SYMBOL_KEYWORD:
+ case SYMBOL_OTHER:
+ return ' ';
+ }
+}
+
static void autocomplete_frame(Ted *ted) {
Autocomplete *ac = &ted->autocomplete;
TextBuffer *buffer = ted->active_buffer;
@@ -243,10 +261,6 @@ static void autocomplete_frame(Ted *ted) {
ac->rect = menu_rect;
}
- // vertical padding
- start_y += padding;
- menu_height -= 2 * padding;
-
u16 cursor_entry = (u16)((ted->mouse_pos.y - start_y) / char_height);
if (cursor_entry < ncompletions) {
// highlight moused over entry
@@ -277,15 +291,32 @@ static void autocomplete_frame(Ted *ted) {
state.min_x = x + padding; state.min_y = y; state.max_x = x + menu_width - padding; state.max_y = y + menu_height;
rgba_u32_to_floats(colors[COLOR_TEXT], state.color);
+ u8 border_thickness = settings->border_thickness;
+
if (ac->waiting_for_lsp) {
state.x = x + padding; state.y = y;
text_utf8_with_state(font, &state, "Loading...");
} else {
for (size_t i = 0; i < ncompletions; ++i) {
- state.x = x + padding; state.y = y;
+
+ state.x = x; state.y = y;
+ 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);
rgba_u32_to_floats(colors[label_color], state.color);
+
+ // draw icon
+ char icon_text[2] = {symbol_kind_icon(completions[i].kind), 0};
+ state.x += padding;
+ text_utf8_with_state(font, &state, icon_text);
+ state.x += padding;
+ gl_geometry_rect(rect(V2((float)state.x, (float)state.y), V2(border_thickness, char_height)),
+ colors[COLOR_AUTOCOMPLETE_BORDER]);
+ state.x += padding;
+
+
text_utf8_with_state(font, &state, completions[i].label);
const char *detail = completions[i].detail;
diff --git a/colors.c b/colors.c
index aac5e00..a684508 100644
--- a/colors.c
+++ b/colors.c
@@ -57,11 +57,10 @@ static ColorSetting color_for_symbol_kind(SymbolKind kind) {
case SYMBOL_CONSTANT:
return COLOR_CONSTANT;
case SYMBOL_TYPE:
- case SYMBOL_FUNCTION:
case SYMBOL_FIELD:
- return COLOR_BUILTIN;
case SYMBOL_VARIABLE:
case SYMBOL_OTHER:
+ case SYMBOL_FUNCTION:
return COLOR_TEXT;
case SYMBOL_KEYWORD:
return COLOR_KEYWORD;
diff --git a/colors.h b/colors.h
index 5f9f330..0c8b1ea 100644
--- a/colors.h
+++ b/colors.h
@@ -24,6 +24,8 @@ typedef enum {
COLOR_ACTIVE_TAB_HL,
COLOR_SELECTED_TAB_HL,
COLOR_FIND_HL,
+
+ COLOR_AUTOCOMPLETE_BORDER,
COLOR_YES,
COLOR_NO,
@@ -82,6 +84,7 @@ static ColorName const color_names[] = {
{COLOR_STRING, "string"},
{COLOR_CHARACTER, "character"},
{COLOR_CONSTANT, "constant"},
+ {COLOR_AUTOCOMPLETE_BORDER, "autocomplete-border"},
{COLOR_YES, "yes"},
{COLOR_NO, "no"},
{COLOR_CANCEL, "cancel"},
diff --git a/ted.cfg b/ted.cfg
index 4b815f6..ff4f7e4 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -233,6 +233,9 @@ yes = #afa
no = #faa
cancel = #ffa
+# autocomplete
+autocomplete-border = #777
+
# Syntax highlighting
keyword = #0c0
preprocessor = #77f