diff options
-rw-r--r-- | arr.c | 10 | ||||
-rw-r--r-- | config.c | 6 | ||||
-rw-r--r-- | menu.c | 6 | ||||
-rw-r--r-- | ted.cfg | 1 | ||||
-rw-r--r-- | ui.c | 27 |
5 files changed, 32 insertions, 18 deletions
@@ -208,18 +208,18 @@ static inline void arr_set_len_(void **arr, size_t member_size, size_t n) { } while (0) -static void arr_append_str_(char **a, char const *s) { +static void arr_append_strn_(char **a, char const *s, size_t s_len) { size_t curr_len = arr_len(*a); - size_t s_len = strlen(s); - if (curr_len) --curr_len; // don't include null terminator arr_set_len(*a, curr_len + s_len + 1); memcpy(*a + curr_len, s, s_len + 1); } -// appends a C-string array with -#define arr_append_str(a, s) arr_append_str_(&(a), (s)) +// append to a C-string array +#define arr_append_str(a, s) arr_append_strn_(&(a), (s), strlen(s)) +// take at most n bytes from s +#define arr_append_strn(a, s, n) arr_append_strn_(&(a), (s), (n)) static void arr_test(void) { u32 *arr = NULL; @@ -306,6 +306,12 @@ void config_read(Ted *ted, char const *filename) { } else { config_err(cfg, "Invalid max menu width: %s.", value); } + } else if (streq(key, "padding")) { + if (is_integer && integer >= 10 && integer < 100) { + settings->padding = (u8)integer; + } else { + config_err(cfg, "Invalid padding: %s.", value); + } } else { config_err(cfg, "Unrecognized core setting: %s.", key); } @@ -50,8 +50,8 @@ static void menu_update(Ted *ted, Menu menu) { } static void menu_render(Ted *ted, Menu menu) { - Settings *settings = &ted->settings; - u32 *colors = settings->colors; + Settings const *settings = &ted->settings; + u32 const *colors = settings->colors; float window_width = ted->window_width, window_height = ted->window_height; // render backdrop @@ -62,7 +62,7 @@ static void menu_render(Ted *ted, Menu menu) { if (menu == MENU_OPEN) { - float padding = 20; + float padding = settings->padding; float menu_x1 = window_width * 0.5f - 300; float menu_x2 = window_width * 0.5f + 300; menu_x1 = maxf(menu_x1, padding); @@ -12,6 +12,7 @@ undo-save-time = 6 text-size = 16 border-thickness = 1 max-menu-width = 600 +padding = 10 [keyboard] # motion and selection @@ -3,10 +3,11 @@ static bool file_selector_entry_pos(Ted const *ted, FileSelector const *fs, u32 i, Rect *r) { Rect bounds = fs->bounds; + float padding = ted->settings.padding; float char_height = text_font_char_height(ted->font); *r = rect(V2(bounds.pos.x, bounds.pos.y + char_height // make room for cwd - + char_height * 1.5f // make room for line buffer + + char_height * 1.5f + padding // make room for line buffer + char_height * (float)i), V2(bounds.size.x, char_height)); return rect_clip_to_rect(r, bounds); @@ -52,11 +53,15 @@ void file_selector_cd(Ted *ted, FileSelector *fs, char const *path) { // this is an absolute path. discard our previous cwd. arr_clear(fs->cwd); } - if (strlen(fs->cwd) > 0 && fs->cwd[strlen(fs->cwd) - 1] != PATH_SEPARATOR) { - // add path separator to end if not already there - arr_append_str(fs->cwd, PATH_SEPARATOR_STR); - } - arr_append_str(fs->cwd, path); + size_t path_len = strlen(path); + if (!path_len) return; + + if (path_len > 1 && path[path_len - 1] == PATH_SEPARATOR) + --path_len; + + // add path separator to end + arr_append_str(fs->cwd, PATH_SEPARATOR_STR); + arr_append_strn(fs->cwd, path, path_len); // clear search term buffer_clear(&ted->line_buffer); @@ -127,7 +132,6 @@ static char *file_selector_update(Ted *ted, FileSelector *fs) { char **files = fs_list_directory(fs->cwd); if (files) { char const *cwd = fs->cwd; - bool cwd_has_path_sep = cwd[strlen(cwd) - 1] == PATH_SEPARATOR; u32 nfiles; for (nfiles = 0; files[nfiles]; ++nfiles); @@ -161,7 +165,7 @@ static char *file_selector_update(Ted *ted, FileSelector *fs) { size_t path_size = strlen(name) + strlen(cwd) + 3; char *path = ted_calloc(ted, 1, path_size); if (path) { - snprintf(path, path_size - 1, "%s%s%s", cwd, cwd_has_path_sep ? "" : PATH_SEPARATOR_STR, name); + snprintf(path, path_size - 1, "%s%s%s", cwd, PATH_SEPARATOR_STR, name); entries[i].path = path; entries[i].type = fs_path_type(path); } else { @@ -189,12 +193,15 @@ static void file_selector_render(Ted *ted, FileSelector *fs) { u32 n_entries = fs->n_entries; FileEntry const *entries = fs->entries; Font *font = ted->font; + float padding = settings->padding; float char_height = text_font_char_height(ted->font); float x1, y1, x2, y2; rect_coords(bounds, &x1, &y1, &x2, &y2); - // current working directory @TODO - + // current working directory + gl_color_rgba(colors[COLOR_TEXT]); + text_render(font, fs->cwd, x1, y1); + y1 += char_height + padding; // search buffer float line_buffer_height = char_height * 1.5f; |