summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-08-06 13:32:05 -0400
committerpommicket <pommicket@gmail.com>2023-08-06 13:32:05 -0400
commitb4e2b3d2407cbad54169da707f72595246e4794a (patch)
treea7cbaa2d672f25aab855e649eb3a66354b3e9f6e
parent413e8f4ba1c5937de40f6366a88c26f540cbb222 (diff)
deal with really long paths in file menus
-rw-r--r--main.c6
-rw-r--r--ui.c28
2 files changed, 21 insertions, 13 deletions
diff --git a/main.c b/main.c
index 5728bf1..fcc3c01 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,4 @@
/*
-TODO:
-- deal with really long paths in file menus
-
FUTURE FEATURES:
- autodetect indentation (tabs vs spaces)
- robust find (results shouldn't move around when you type things)
@@ -9,9 +6,6 @@ FUTURE FEATURES:
- bind key to multiple commands
- convert macro to command list
- plugins?
- - TED_PLUGIN macro defined before including ted.h
- this can remove struct definitions to guarantee forwards compatibility
- - language dynamic registration
- built-in plugins
- "remove file..." menu
- with macros we can really test performance of buffer_insert_text_at_pos, etc. (which should ideally be fast)
diff --git a/ui.c b/ui.c
index e5f1666..df6ab9c 100644
--- a/ui.c
+++ b/ui.c
@@ -495,21 +495,35 @@ void file_selector_render(Ted *ted, FileSelector *fs) {
Font *font = ted->font, *font_bold = ted->font_bold;
float padding = settings->padding;
float char_height = text_font_char_height(font);
- float x1, y1, x2, y2;
- rect_coords(bounds, &x1, &y1, &x2, &y2);
if (*fs->title) {
- text_utf8(font_bold, fs->title, x1, y1, colors[COLOR_TEXT]);
- y1 += text_font_char_height(font_bold) * 0.75f + padding;
+ text_utf8(font_bold, fs->title, bounds.pos.x, bounds.pos.y, colors[COLOR_TEXT]);
+ bounds = rect_shrink_top(bounds, text_font_char_height(font_bold) * 0.75f + padding);
}
// current working directory
- text_utf8(font, fs->cwd, x1, y1, colors[COLOR_TEXT]);
- y1 += char_height + padding;
+ {
+ const char *cwd = fs->cwd;
+ const float text_width = text_get_size_vec2(font, cwd).x;
+ TextRenderState state = text_render_state_default;
+ state.x = bounds.pos.x;
+ if (text_width > bounds.size.x) {
+ // very long cwd
+ // make sure the end of the cwd is shown
+ state.x = rect_x2(bounds) - text_width - padding;
+ }
+ state.y = bounds.pos.y;
+ rgba_u32_to_floats(colors[COLOR_TEXT], state.color);
+ state.min_x = bounds.pos.x;
+ state.max_x = rect_x2(bounds);
+
+ text_utf8_with_state(font, &state, fs->cwd);
+ bounds = rect_shrink_top(bounds, char_height + padding);
+ }
// render selector
Selector *sel = &fs->sel;
- sel->bounds = rect4(x1, y1, x2, y2); // selector takes up remaining space
+ sel->bounds = bounds;
arr_clear(sel->entries);
for (u32 i = 0; i < fs->n_entries; ++i) {
ColorSetting color = 0;