diff options
| author | Riley Beckett <rbeckettvt@gmail.com> | 2025-10-19 19:49:52 -0400 |
|---|---|---|
| committer | Riley Beckett <rbeckettvt@gmail.com> | 2025-10-19 19:49:52 -0400 |
| commit | a3edeef3d506d3a498c727fc4ba96cfa99673622 (patch) | |
| tree | a7a48edbcf030d571f93ce4bb40f8a004a2d9993 | |
| parent | 25f0c213ed8d9d0912c0de8c2506d0820939aafd (diff) | |
selected background
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | config.h | 2 | ||||
| -rw-r--r-- | font.c | 2 | ||||
| -rw-r--r-- | graphics.c | 76 | ||||
| -rwxr-xr-x | swenu-path.sh | 6 | ||||
| -rwxr-xr-x | swenu-run.sh | 2 |
7 files changed, 59 insertions, 41 deletions
@@ -53,9 +53,13 @@ clean: install: all install -m 755 ./$(BIN) $(PREFIX)/usr/bin + install -m 755 ./swenu-run $(PREFIX)/usr/bin + install -m 755 ./swenu-path $(PREFIX)/usr/bin uninstall: - rm -rf $(PREFIX)/usr/bin/$(BIN) + rm -f $(PREFIX)/usr/bin/$(BIN) + rm -f $(PREFIX)/usr/bin/swenu-run + rm -f $(PREFIX)/usr/bin/swenu-path run: all ./swenu-run.sh @@ -6,14 +6,14 @@ 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 % - [ ] cursor -- [ ] fancy highlights -- [ ] scrolling - [ ] kerning - [ ] config file - [ ] emacs keybindings -- [ ] special mode if there is no stdin - [ ] input fluff - [ ] "prompt" @@ -3,7 +3,7 @@ #include <stdint.h> -static const uint32_t min_width = 600; +static const uint32_t min_width = 500; static const uint32_t font_size = 15; #endif @@ -66,7 +66,7 @@ bool freetype_init(client_state* state, const char* file) { } state->load_flags = FT_LOAD_RENDER; state->line_height = state->ft_face->size->metrics.height >> 6; - state->horizontal_spacing = state->line_height / 2.0f; + state->horizontal_spacing = state->line_height; return true; } @@ -154,7 +154,12 @@ void render_frame(client_state *state) { else { input_width = state->width / 3.0f; } // draw input buffer - glScissor(0, input_y, input_width - state->horizontal_spacing / 2.0f, state->line_height); + if (array_size(state->filtered_items) != 0) { + glScissor(0, input_y, input_width - state->horizontal_spacing / 2.0f, state->line_height); + } + else { + glScissor(0, 0, state->width, state->height); + } glBindVertexArray(state->input_buffer_grafix.vao); glUniform2f(state->offset_uniform, state->horizontal_spacing / 2.0f, input_y - state->atlas.vert_shift); glDrawElements(GL_TRIANGLES, state->input_buffer_grafix.num_elements, GL_UNSIGNED_INT, 0); @@ -165,35 +170,39 @@ void render_frame(client_state *state) { glScissor(0, 0, state->width, input_y); start = input_y - state->line_height + state->scroll; - // calc scroll - float selected_bot = start - state->filtered_items[state->selected_filtered_item].offset; - float selected_top = selected_bot + state->line_height; - if (selected_bot < 0) { - state->scroll -= selected_bot; - start -= selected_bot; - } - float diff = selected_top - input_y; - if (diff > 0) { - state->scroll -= diff; - start -= diff; + if (array_size(state->filtered_items) != 0) { + // calc scroll + float selected_bot = start - state->filtered_items[state->selected_filtered_item].offset; + float selected_top = selected_bot + state->line_height; + if (selected_bot < 0) { + state->scroll -= selected_bot; + start -= selected_bot; + } + float diff = selected_top - input_y; + if (diff > 0) { + state->scroll -= diff; + start -= diff; + } } } else { glScissor(input_width, 0, state->width, state->line_height); start = input_width + state->scroll; - // calc scroll - item_display_t* selected = &state->filtered_items[state->selected_filtered_item]; - float selected_left = start + selected->offset; - float selected_right = selected_left + selected->item->pixel_len + state->horizontal_spacing; - float diff = selected_right - state->width; - if (diff > 0) { - state->scroll -= diff; - start -= diff; - } - diff = selected_left - input_width; - if (diff < 0) { - state->scroll -= diff; - start -= diff; + if (array_size(state->filtered_items) != 0) { + // calc scroll + item_display_t* selected = &state->filtered_items[state->selected_filtered_item]; + float selected_left = start + selected->offset; + float selected_right = selected_left + selected->item->pixel_len + state->horizontal_spacing; + float diff = selected_right - state->width; + if (diff > 0) { + state->scroll -= diff; + start -= diff; + } + diff = selected_left - input_width; + if (diff < 0) { + state->scroll -= diff; + start -= diff; + } } } @@ -214,9 +223,22 @@ 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, 0.0f, 0.4f, 0.8f); + if (i == state->selected_filtered_item) { + glUniform3f(state->color_uniform, 1.0f, 1.0f, 1.0f); + 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 (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); + } + } } // present screen diff --git a/swenu-path.sh b/swenu-path.sh deleted file mode 100755 index a720d5c..0000000 --- a/swenu-path.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -IFS=: -for dir in $PATH; do - [ -e ${dir} ] && find ${dir} -executable -printf '%f\n' -done | sort -u diff --git a/swenu-run.sh b/swenu-run.sh deleted file mode 100755 index 956fe64..0000000 --- a/swenu-run.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -./swenu-path.sh | ./swenu "$@" | ${SHELL:-"/bin/sh"} & |
