diff options
| author | Jack Jamison <jackqjamison@gmail.com> | 2025-10-19 23:02:44 -0400 |
|---|---|---|
| committer | Jack Jamison <jackqjamison@gmail.com> | 2025-10-19 23:02:44 -0400 |
| commit | c47c01918eb271d3344923638c382fcc2f70487b (patch) | |
| tree | 1992697f2859d7a2f726364d604ef56afe865f73 | |
| parent | 6e6830eabed6ee8a38bebfa677dc3eaee322ec6c (diff) | |
sort by smallest
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | graphics.c | 13 | ||||
| -rw-r--r-- | input_field.c | 7 | ||||
| -rw-r--r-- | main.c | 10 |
4 files changed, 22 insertions, 14 deletions
@@ -2,16 +2,16 @@ To build: `make` - ## Todo - - [x] "selection" - [x] figure out whats going on with stderr and exit code - [X] fancy highlights - [X] scrolling - [X] special mode if there is no stdin -- [ ] unicode -- [ ] fuzzy filter and sort filtering by match % +- [x] sort filtering by match % - [ ] cursor +- [ ] fuzzy filter +- [ ] unicode - [ ] kerning - [ ] config file - [ ] emacs keybindings @@ -224,20 +224,23 @@ void render_frame(client_state *state) { glBindVertexArray(item->text_buffer.vao); glUniform2f(state->offset_uniform, x + state->horizontal_spacing / 2.0f, y - state->atlas.vert_shift); if (i == state->selected_filtered_item) { - glUniform3f(state->color_uniform, 1.0f, 1.0f, 1.0f); + // draw box glScissor(x, y, ((state->lines > 0) ? state->width : item->pixel_len + state->horizontal_spacing), state->line_height); glClearColor(0.0f, 0.4f, 0.8f, 1.0); glClear(GL_COLOR_BUFFER_BIT); - } - glDrawElements(GL_TRIANGLES, item->text_buffer.num_elements, GL_UNSIGNED_INT, 0); - if (i == state->selected_filtered_item) { - glUniform3f(state->color_uniform, 1.0f, 1.0f, 1.0f); if (state->lines > 0) { glScissor(0, 0, state->width, input_y); } else { glScissor(input_width, 0, state->width, state->line_height); } + + // draw text + glDrawElements(GL_TRIANGLES, item->text_buffer.num_elements, GL_UNSIGNED_INT, 0); + } else { + + // draw text + glDrawElements(GL_TRIANGLES, item->text_buffer.num_elements, GL_UNSIGNED_INT, 0); } } diff --git a/input_field.c b/input_field.c index 34f3fc2..290a5bd 100644 --- a/input_field.c +++ b/input_field.c @@ -4,9 +4,12 @@ #include "array.h" #include "graphics.h" +int compare(const void *a, const void *b) { + return strlen(((item_display_t*)a)->item->text) > strlen(((item_display_t*)b)->item->text); +} + void filter_items(client_state* state) { if (!state->items) return; - array_clear(state->filtered_items); // get null terminated input buffer size_t len = array_size(state->input_buffer); @@ -15,11 +18,13 @@ void filter_items(client_state* state) { input_buffer_string[len] = '\0'; // add all strings with substring + array_clear(state->filtered_items); array_for_all(item_t, i, state->items) { if (strstr(i->text, input_buffer_string) != NULL) { array_add(state->filtered_items, (item_display_t){ .item = i }); } } + qsort(state->filtered_items, array_size(state->filtered_items), sizeof(item_display_t), compare); // select item if (array_size(state->filtered_items) > 0) state->selected_filtered_item = 0; @@ -99,11 +99,11 @@ int main(int argc, char* argv[]) { } void poll_events(client_state* state) { - enum { DISPLAY_FD, KEYREPEAT_FD }; - struct pollfd fds[] = { - [DISPLAY_FD] = { wl_display_get_fd(state->display), POLLIN }, - [KEYREPEAT_FD] = { state->key_repeat_timer_fd, POLLIN }, - }; + enum { DISPLAY_FD, KEYREPEAT_FD }; + struct pollfd fds[] = { + [DISPLAY_FD] = { wl_display_get_fd(state->display), POLLIN }, + [KEYREPEAT_FD] = { state->key_repeat_timer_fd, POLLIN }, + }; bool event = false; while (!event) { |
