summaryrefslogtreecommitdiff
path: root/menu.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-18 16:37:51 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-18 16:37:51 -0500
commita3adbe5ea6015a76a3df84ee5942b89fbb762947 (patch)
tree712d0fdfaf23818ebf2b361306dbb9d4452e6540 /menu.c
parent37102a766e1913cd0548a981e5c601852ae47963 (diff)
opening files kinda working
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/menu.c b/menu.c
index 6862d0e..9ef2245 100644
--- a/menu.c
+++ b/menu.c
@@ -1,3 +1,23 @@
+static void menu_open(Ted *ted, Menu menu) {
+ ted->menu = menu;
+ ted->prev_active_buffer = ted->active_buffer;
+ ted->active_buffer = NULL;
+
+ switch (menu) {
+ case MENU_NONE: assert(0); break;
+ case MENU_OPEN:
+ ted->active_buffer = &ted->line_buffer;
+ break;
+ }
+}
+
+static void menu_close(Ted *ted, bool restore_prev_active_buffer) {
+ ted->menu = MENU_NONE;
+ if (restore_prev_active_buffer) ted->active_buffer = ted->prev_active_buffer;
+ ted->prev_active_buffer = NULL;
+
+ buffer_clear(&ted->line_buffer);
+}
static void menu_render(Ted *ted, Menu menu) {
Settings *settings = &ted->settings;
@@ -22,6 +42,7 @@ static void menu_render(Ted *ted, Menu menu) {
float menu_y1 = padding;
float menu_y2 = window_height - padding;
Rect menu_rect = rect4(menu_x1, menu_y1, menu_x2, menu_y2);
+ float inner_padding = 10;
// menu rectangle & border
glBegin(GL_QUADS);
@@ -30,6 +51,14 @@ static void menu_render(Ted *ted, Menu menu) {
gl_color_rgba(colors[COLOR_BORDER]);
rect_render_border(menu_rect, settings->border_thickness);
glEnd();
+
+ 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,
+ 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);
char **files = fs_list_directory(directory);
if (files) {
@@ -38,8 +67,8 @@ static void menu_render(Ted *ted, Menu menu) {
qsort(files, nfiles, sizeof *files, str_qsort_case_insensitive_cmp);
{ // render file names
- float x = menu_x1 + 10, y = menu_y1 + char_height * 0.75f + 10;
- TextRenderState text_render_state = {.min_x = menu_x1, .max_x = menu_x2, .min_y = menu_y1, .max_y = menu_y2};
+ float x = menu_x1 + inner_padding, y = menu_y1 + line_buffer_height + inner_padding;
+ 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) {
text_render_with_state(font, &text_render_state, files[i], x, y);
@@ -50,6 +79,5 @@ static void menu_render(Ted *ted, Menu menu) {
for (u32 i = 0; i < nfiles; ++i) free(files[i]);
free(files);
}
-
}
}