summaryrefslogtreecommitdiff
path: root/menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/menu.c b/menu.c
index 7c09d53..d82eb4a 100644
--- a/menu.c
+++ b/menu.c
@@ -54,10 +54,15 @@ static void menu_render(Ted *ted, Menu menu) {
rect_render_border(menu_rect, settings->border_thickness);
glEnd();
+ menu_x1 += inner_padding;
+ menu_y1 += inner_padding;
+ menu_x2 -= inner_padding;
+ menu_y2 -= inner_padding;
+
float line_buffer_height = char_height * 1.5f;
- float line_buffer_x1 = menu_x1 + inner_padding,
- line_buffer_y1 = menu_y1 + inner_padding,
- line_buffer_x2 = menu_x2 - inner_padding,
+ float line_buffer_x1 = menu_x1,
+ line_buffer_y1 = menu_y1,
+ line_buffer_x2 = menu_x2,
line_buffer_y2 = line_buffer_y1 + line_buffer_height;
buffer_render(&ted->line_buffer, line_buffer_x1, line_buffer_y1, line_buffer_x2, line_buffer_y2);
@@ -80,21 +85,47 @@ static void menu_render(Ted *ted, Menu menu) {
}
qsort(files, nfiles, sizeof *files, str_qsort_case_insensitive_cmp);
-
+ char const *file_to_open = NULL;
{ // render file names
- float x = menu_x1 + inner_padding, y = menu_y1 + line_buffer_height + inner_padding;
+ float start_x = menu_x1, start_y = line_buffer_y2 + inner_padding;
+ float x = start_x, y = start_y;
+
+ for (u32 i = 0; i < nfiles; ++i) {
+ // highlight entry user is mousing over
+ if (y >= menu_y2) break;
+ Rect r = rect4(x, y, menu_x2, minf(y + char_height, menu_y2));
+ y += char_height;
+ if (rect_contains_point(r, ted->mouse_pos)) {
+ glBegin(GL_QUADS);
+ gl_color_rgba(colors[COLOR_MENU_HL]);
+ rect_render(r);
+ glEnd();
+ }
+ for (u32 c = 0; c < ted->nmouse_clicks[SDL_BUTTON_LEFT]; ++c) {
+ if (rect_contains_point(r, ted->mouse_clicks[SDL_BUTTON_LEFT][c])) {
+ // this file got clicked on!
+ file_to_open = files[i];
+ }
+ }
+ }
+ x = start_x, y = start_y;
TextRenderState text_render_state = {.min_x = menu_x1, .max_x = menu_x2, .min_y = menu_y1, .max_y = menu_y2, .render = true};
gl_color_rgba(colors[COLOR_TEXT]);
for (u32 i = 0; i < nfiles; ++i) {
+ if (y >= menu_y2) break;
text_render_with_state(font, &text_render_state, files[i], x, y);
y += char_height;
}
}
+ if (file_to_open) {
+ ted_open_file(ted, file_to_open);
+ menu_close(ted, false);
+ }
+
for (u32 i = 0; i < nfiles; ++i) free(files[i]);
free(files);
}
free(search_term);
}
-
}