aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2025-10-23 22:50:55 -0400
committerJack Jamison <jackqjamison@gmail.com>2025-10-23 22:50:55 -0400
commit34e31d33defb922ad464857487469c5659bbefcc (patch)
treeeef5920e3eed700c6af60378b6e2e401f3df14d3
parenta58e1bd66da70898144029ea3aef5d0692c37414 (diff)
fix fancy scroll freaking out if item is too long
-rw-r--r--README.md7
-rw-r--r--config.h2
-rw-r--r--graphics.c25
3 files changed, 21 insertions, 13 deletions
diff --git a/README.md b/README.md
index a43ab84..09a339c 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,8 @@ make
- [ ] emacs keybindings
- [ ] fuzzy filter
- [ ] "prompt"
-- [ ] unicode
- [ ] config file
-- [ ] input fluff
-- [ ] kerning
+- [ ] unicode + shaping
+
+Stretch:
+- [ ] input fluff (icons, descriptions, output names)
diff --git a/config.h b/config.h
index 1c67269..8deca15 100644
--- a/config.h
+++ b/config.h
@@ -2,11 +2,13 @@
#define CONFIG_H_
#include <stdint.h>
+#include <stdbool.h>
typedef struct {
float r,g,b,a;
} color_t;
+static const bool fancy_scroll = false;
static const uint32_t min_width = 500;
static const uint32_t font_size = 16;
static const color_t text_color = {0.85, 0.85, 0.85, 1.0};
diff --git a/graphics.c b/graphics.c
index 49e0a65..43d1069 100644
--- a/graphics.c
+++ b/graphics.c
@@ -205,7 +205,7 @@ void render_frame(client_state *state) {
glUniform4f(state->b_color_uniform, cursor_color.r,cursor_color.g,cursor_color.b,cursor_color.a);
glUniform2f(state->b_screen_size_uniform, state->width, state->height);
glUniform2f(state->b_start_uniform, atlas_get_strwidth_len(state, state->input_buffer, state->cursor_index) + state->horizontal_spacing / 2.0f, input_y);
- glUniform2f(state->b_size_uniform, state->atlas.metrics['M'].bitmap_width, state->line_height);
+ glUniform2f(state->b_size_uniform, state->cursor_index == array_size(state->input_buffer) ? state->atlas.metrics['M'].bitmap_width : state->atlas.metrics[(int)state->input_buffer[state->cursor_index]].bitmap_width, state->line_height);
glDrawArrays(GL_TRIANGLES, 0, 6);
float start;
@@ -235,17 +235,22 @@ void render_frame(client_state *state) {
if (array_size(state->filtered_items) != 0) {
// calc scroll
item_display_t* selected = &state->filtered_items[state->selected_filtered_item];
+ float selected_len = selected->item->pixel_len + state->horizontal_spacing;
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;
+ float selected_right = selected_left + selected_len;
+ float right_diff = selected_right - state->width;
+ float left_diff = selected_left - input_width;
+ if (selected_len > state->width - input_width) {
+ state->scroll -= left_diff;
+ start -= left_diff;
}
- diff = selected_left - input_width;
- if (diff < 0) {
- state->scroll -= diff;
- start -= diff;
+ else if (right_diff > 0) {
+ state->scroll -= right_diff;
+ start -= right_diff;
+ }
+ else if (left_diff < 0) {
+ state->scroll -= left_diff;
+ start -= left_diff;
}
}
}