Skip to content

Commit

Permalink
refactor: file manager list files port
Browse files Browse the repository at this point in the history
  • Loading branch information
Otrebor671 committed Sep 20, 2024
1 parent df004c6 commit 05f6f3d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions firmware/main/modules/file_manager/file_manager_screens.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#include "file_manager_screens.h"
#include "oled_screen.h"

#define MAX_ITEMS_NUM 7
#ifdef CONFIG_RESOLUTION_128X64
#define MAX_ITEMS_NUM 8
#define ITEMOFFSET 1
#else // CONFIG_RESOLUTION_128X32
#define MAX_ITEMS_NUM 4
#define ITEMOFFSET 1
#endif

static void update_list(file_manager_context_t* ctx) {
static uint8_t items_offset = 0;
items_offset = MAX(ctx->selected_item - 6, items_offset);
items_offset = MIN(MAX(ctx->items_count - 7, 0), items_offset);
items_offset = MAX(ctx->selected_item - MAX_ITEMS_NUM + 2, items_offset);
items_offset =
MIN(MAX(ctx->items_count - MAX_ITEMS_NUM + 1, 0), items_offset);
items_offset = MIN(ctx->selected_item, items_offset);
oled_screen_clear_buffer();
oled_screen_display_text("< Back", 0, 0, OLED_DISPLAY_NORMAL);
if (ctx->items_count == 0) {
oled_screen_display_text(" Empty folder ", 0, 3, OLED_DISPLAY_NORMAL);
oled_screen_display_text("No files to show", 0, 4, OLED_DISPLAY_NORMAL);
} else {
for (uint8_t i = 0; i < (MIN(ctx->items_count, MAX_ITEMS_NUM)); i++) {
for (uint8_t i = 0; i < (MIN(ctx->items_count, MAX_ITEMS_NUM - 1)); i++) {
char* str = (char*) malloc(30);
sprintf(str, "%s%s", ctx->file_items_arr[i + items_offset]->name,
ctx->file_items_arr[i + items_offset]->is_dir ? ">" : "");
Expand Down

0 comments on commit 05f6f3d

Please sign in to comment.