fix: Disks app UI elements, file manager list view rendering

This commit is contained in:
2026-04-06 10:05:58 +02:00
parent c1c06a0438
commit 2c35a7adf4
3 changed files with 49 additions and 37 deletions
@@ -353,8 +353,31 @@ void filemanager_on_draw(Window* win, Framebuffer& fb) {
int cx = tx + text_width(prefix);
c.vline(cx, ty, fm_sfh, colors::ACCENT);
} else {
if (ty >= list_y && ty + fm_sfh <= c.h)
c.text(tx, ty, fm->entry_names[i], colors::TEXT_COLOR);
if (ty >= list_y && ty + fm_sfh <= c.h) {
// Truncate name to fit the name column width
const char* name = fm->entry_names[i];
int name_max_w = size_col_x - tx - 8;
if (name_max_w < 20) name_max_w = c.w - FM_SCROLLBAR_W - tx - 8;
char label[64];
montauk::strncpy(label, name, 63);
if (text_width(label) > name_max_w && montauk::slen(name) > 3) {
int ellipsis_w = text_width("...");
int final_len = montauk::slen(name);
while (final_len > 1) {
label[final_len] = '\0';
int w = text_width(label);
if (w + ellipsis_w <= name_max_w) break;
final_len--;
}
if (final_len > 60) final_len = 60;
label[final_len] = '.';
label[final_len + 1] = '.';
label[final_len + 2] = '.';
label[final_len + 3] = '\0';
}
c.text(tx, ty, label, colors::TEXT_COLOR);
}
}
// Size
+2
View File
@@ -110,6 +110,8 @@ struct DiskToolState {
uint64_t status_time;
FormatDialog fmt_dlg;
NewPartDialog np_dlg;
int mouse_x;
int mouse_y;
};
// ============================================================================
+22 -35
View File
@@ -84,8 +84,19 @@ static int font_h() {
static void px_button(uint32_t* px, int bw, int bh,
int x, int y, int w, int h,
const char* label, Color bg, Color fg, int r) {
px_fill_rounded(px, bw, bh, x, y, w, h, r, bg);
const char* label, bool enabled, bool hovered, bool primary) {
Color bg, fg;
if (!enabled) {
bg = Color::from_rgb(0xF0, 0xF0, 0xF0);
fg = Color::from_rgb(0x9A, 0x9A, 0x9A);
} else if (primary) {
bg = hovered ? Color::from_rgb(0x2B, 0x6B, 0xE0) : colors::ACCENT;
fg = WHITE;
} else {
bg = hovered ? Color::from_rgb(0xDC, 0xDC, 0xDC) : Color::from_rgb(0xE8, 0xE8, 0xE8);
fg = TEXT_COLOR;
}
px_fill_rounded(px, bw, bh, x, y, w, h, 6, bg);
int tw = text_w(label);
int fh = font_h();
px_text(px, bw, bh, x + (w - tw) / 2, y + (h - fh) / 2, label, fg);
@@ -107,11 +118,7 @@ static void render_toolbar(uint32_t* px) {
char label[8];
snprintf(label, sizeof(label), "Disk %d", i);
int lw = text_w(label) + 16;
Color bg = (i == dt.selected_disk)
? Color::from_rgb(0x42, 0x7A, 0xB5)
: Color::from_rgb(0xDD, 0xDD, 0xDD);
Color fg = (i == dt.selected_disk) ? WHITE : TEXT_COLOR;
px_button(px, g_win_w, g_win_h, bx, TB_BTN_Y, lw, TB_BTN_H, label, bg, fg, TB_BTN_RAD);
px_button(px, g_win_w, g_win_h, bx, TB_BTN_Y, lw, TB_BTN_H, label, true, false, false);
bx += lw + 6;
}
@@ -126,26 +133,22 @@ static void render_toolbar(uint32_t* px) {
int ref_w = 64; rx -= ref_w;
px_button(px, g_win_w, g_win_h, rx, TB_BTN_Y, ref_w, TB_BTN_H,
"Refresh", Color::from_rgb(0xE0, 0xE0, 0xE0), TEXT_COLOR, TB_BTN_RAD);
"Refresh", true, false, false);
rx -= 6;
int mnt_w = 60; rx -= mnt_w;
px_button(px, g_win_w, g_win_h, rx, TB_BTN_Y, mnt_w, TB_BTN_H,
"Mount",
has_sel ? Color::from_rgb(0x42, 0x7A, 0xB5) : Color::from_rgb(0xBB, 0xBB, 0xBB),
WHITE, TB_BTN_RAD);
"Mount", has_sel, false, true);
rx -= 6;
int fmt_w = 64; rx -= fmt_w;
px_button(px, g_win_w, g_win_h, rx, TB_BTN_Y, fmt_w, TB_BTN_H,
"Format",
has_sel ? Color::from_rgb(0x42, 0x7A, 0xB5) : Color::from_rgb(0xBB, 0xBB, 0xBB),
WHITE, TB_BTN_RAD);
"Format", has_sel, false, true);
rx -= 6;
int np_w = 74; rx -= np_w;
px_button(px, g_win_w, g_win_h, rx, TB_BTN_Y, np_w, TB_BTN_H,
"New Part", Color::from_rgb(0x42, 0x7A, 0xB5), WHITE, TB_BTN_RAD);
"New Part", true, false, true);
}
static void render_content(uint32_t* px) {
@@ -334,15 +337,8 @@ void render_format_window() {
int total_w = btn_w * 2 + gap;
int bx = (dw - total_w) / 2;
Color fmt_bg = dlg.hover_format
? Color::from_rgb(0xDD, 0x44, 0x44)
: Color::from_rgb(0xCC, 0x33, 0x33);
px_button(px, dw, dh, bx, btn_y, btn_w, btn_h, "Format", fmt_bg, WHITE, 6);
Color can_bg = dlg.hover_cancel
? Color::from_rgb(0x99, 0x99, 0x99)
: Color::from_rgb(0x88, 0x88, 0x88);
px_button(px, dw, dh, bx + btn_w + gap, btn_y, btn_w, btn_h, "Cancel", can_bg, WHITE, 6);
px_button(px, dw, dh, bx, btn_y, btn_w, btn_h, "Format", true, dlg.hover_format, true);
px_button(px, dw, dh, bx + btn_w + gap, btn_y, btn_w, btn_h, "Cancel", true, dlg.hover_cancel, false);
}
// ============================================================================
@@ -386,18 +382,9 @@ void render_newpart_window() {
int total_w = btn_w * 2 + gap;
int bx = (dw - total_w) / 2;
Color confirm_bg = dlg.will_init_gpt
? (dlg.hover_confirm ? Color::from_rgb(0xDD, 0x44, 0x44)
: Color::from_rgb(0xCC, 0x33, 0x33))
: (dlg.hover_confirm ? Color::from_rgb(0x4A, 0x88, 0xC8)
: Color::from_rgb(0x42, 0x7A, 0xB5));
const char* confirm_label = dlg.will_init_gpt ? "Initialize" : "Create";
px_button(px, dw, dh, bx, btn_y, btn_w, btn_h, confirm_label, confirm_bg, WHITE, 6);
Color can_bg = dlg.hover_cancel
? Color::from_rgb(0x99, 0x99, 0x99)
: Color::from_rgb(0x88, 0x88, 0x88);
px_button(px, dw, dh, bx + btn_w + gap, btn_y, btn_w, btn_h, "Cancel", can_bg, WHITE, 6);
px_button(px, dw, dh, bx, btn_y, btn_w, btn_h, confirm_label, true, dlg.hover_confirm, true);
px_button(px, dw, dh, bx + btn_w + gap, btn_y, btn_w, btn_h, "Cancel", true, dlg.hover_cancel, false);
}
// ============================================================================