Skip to content

Commit 9dc70f3

Browse files
committed
make format
1 parent e632bcc commit 9dc70f3

2 files changed

Lines changed: 89 additions & 93 deletions

File tree

main/menu/file_explorer.c

Lines changed: 86 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,56 @@
33
#include "bsp/input.h"
44
#include "common/display.h"
55
#include "esp_vfs.h"
6-
#include "gui_style.h"
76
#include "gui_menu.h"
7+
#include "gui_style.h"
88
#include "icons.h"
99
#include "menu/message_dialog.h"
1010
#include "pax_gfx.h"
1111
#include "pax_types.h"
1212

13-
14-
static void populate_menu(menu_t* menu, char* path){
15-
DIR* dir = opendir(path);
16-
if(dir==NULL)return;
17-
struct dirent* entry;
18-
while ((entry = readdir(dir)) != NULL) {
19-
menu_insert_item(menu,entry->d_name, NULL, (void*)entry->d_type, -1);
20-
}
21-
closedir(dir);
13+
static void populate_menu(menu_t* menu, char* path) {
14+
DIR* dir = opendir(path);
15+
if (dir == NULL) return;
16+
struct dirent* entry;
17+
while ((entry = readdir(dir)) != NULL) {
18+
menu_insert_item(menu, entry->d_name, NULL, (void*)entry->d_type, -1);
19+
}
20+
closedir(dir);
2221
}
2322

2423
#if defined(CONFIG_BSP_TARGET_TANMATSU) || defined(CONFIG_BSP_TARGET_KONSOOL) || \
2524
defined(CONFIG_BSP_TARGET_HACKERHOTEL_2026)
26-
#define FOOTER_LEFT \
27-
((gui_element_icontext_t[]){{get_icon(ICON_ESC), "/"}, \
28-
{get_icon(ICON_F1), "Quit"}, \
29-
{get_icon(ICON_F2), "Back"}}), \
30-
3
25+
#define FOOTER_LEFT \
26+
((gui_element_icontext_t[]){{get_icon(ICON_ESC), "/"}, {get_icon(ICON_F1), "Quit"}, {get_icon(ICON_F2), "Back"}}), 3
3127
#define FOOTER_RIGHT ((gui_element_icontext_t[]){{NULL, "↑ / ↓ Select | ⏎ Open"}}), 1
3228
#elif defined(CONFIG_BSP_TARGET_MCH2022)
33-
#define FOOTER_LEFT NULL, 0
29+
#define FOOTER_LEFT NULL, 0
3430
#define FOOTER_RIGHT ((gui_element_icontext_t[]){{NULL, "🅰 Open"}, {NULL, "🅱"Back"}}), 2
3531
#else
3632
#define FOOTER_LEFT NULL, 0
3733
#define FOOTER_RIGHT NULL, 0
3834
#endif
3935

40-
static void render(pax_buf_t* buffer, gui_theme_t* theme, menu_t*menu, char*path, pax_vec2_t position, bool partial, bool icons){
41-
if(!partial || icons) {
42-
render_base_screen_statusbar(buffer, theme, !partial, !partial||icons, !partial,
43-
((gui_element_icontext_t[]){{get_icon(ICON_SD), path}}), 1,
44-
FOOTER_LEFT,FOOTER_RIGHT);
45-
}
46-
if(menu_get_length(menu)!=0){
47-
menu_render(buffer, menu, position, theme, partial);
48-
}else{
49-
pax_draw_text(buffer, theme->palette.color_foreground, theme->footer.text_font, 16, position.x0, position.y0+18 * 0, "Directory empty");
50-
}
51-
display_blit_buffer(buffer);
36+
static void render(pax_buf_t* buffer, gui_theme_t* theme, menu_t* menu, char* path, pax_vec2_t position, bool partial,
37+
bool icons) {
38+
if (!partial || icons) {
39+
render_base_screen_statusbar(buffer, theme, !partial, !partial || icons, !partial,
40+
((gui_element_icontext_t[]){{get_icon(ICON_SD), path}}), 1, FOOTER_LEFT,
41+
FOOTER_RIGHT);
42+
}
43+
if (menu_get_length(menu) != 0) {
44+
menu_render(buffer, menu, position, theme, partial);
45+
} else {
46+
pax_draw_text(buffer, theme->palette.color_foreground, theme->footer.text_font, 16, position.x0,
47+
position.y0 + 18 * 0, "Directory empty");
48+
}
49+
display_blit_buffer(buffer);
5250
}
5351

5452
// returns true upon quit, false upon back
55-
static bool file_explorer(pax_buf_t* buffer, gui_theme_t* theme, char*path){
56-
QueueHandle_t input_event_queue = NULL;
57-
ESP_ERROR_CHECK(bsp_input_get_queue(&input_event_queue));
53+
static bool file_explorer(pax_buf_t* buffer, gui_theme_t* theme, char* path) {
54+
QueueHandle_t input_event_queue = NULL;
55+
ESP_ERROR_CHECK(bsp_input_get_queue(&input_event_queue));
5856

5957
int header_height = theme->header.height + (theme->header.vertical_margin * 2);
6058
int footer_height = theme->footer.height + (theme->footer.vertical_margin * 2);
@@ -63,69 +61,67 @@ static bool file_explorer(pax_buf_t* buffer, gui_theme_t* theme, char*path){
6361
.x0 = theme->menu.horizontal_margin + theme->menu.horizontal_padding,
6462
.y0 = header_height + theme->menu.vertical_margin + theme->menu.vertical_padding,
6563
.x1 = pax_buf_get_width(buffer) - theme->menu.horizontal_margin - theme->menu.horizontal_padding,
66-
.y1 = pax_buf_get_height(buffer) - footer_height - theme->menu.vertical_margin
67-
- theme->menu.vertical_padding,
68-
};
69-
64+
.y1 = pax_buf_get_height(buffer) - footer_height - theme->menu.vertical_margin - theme->menu.vertical_padding,
65+
};
7066

71-
menu_t menu = {0};
72-
menu_initialize(&menu);
67+
menu_t menu = {0};
68+
menu_initialize(&menu);
7369

74-
populate_menu(&menu,path);
75-
render(buffer, theme, &menu, path, position, false, true);
70+
populate_menu(&menu, path);
71+
render(buffer, theme, &menu, path, position, false, true);
7672

77-
while(1){
78-
bsp_input_event_t event;
79-
if (xQueueReceive(input_event_queue, &event, pdMS_TO_TICKS(1000)) == pdTRUE){
80-
switch(event.type) {
81-
case INPUT_EVENT_TYPE_NAVIGATION:
82-
if(event.args_navigation.state) {
83-
switch(event.args_navigation.key){
84-
case BSP_INPUT_NAVIGATION_KEY_ESC:
85-
case BSP_INPUT_NAVIGATION_KEY_F1:
86-
menu_free(&menu);
87-
return true;
88-
case BSP_INPUT_NAVIGATION_KEY_F2:
89-
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_B:
90-
menu_free(&menu);
91-
return false;
92-
case BSP_INPUT_NAVIGATION_KEY_UP:
93-
menu_navigate_previous(&menu);
94-
render(buffer, theme, &menu, path, position, true, false);
95-
break;
96-
case BSP_INPUT_NAVIGATION_KEY_DOWN:
97-
menu_navigate_next(&menu);
98-
render(buffer, theme, &menu, path, position, true, false);
99-
break;
100-
case BSP_INPUT_NAVIGATION_KEY_RETURN:
101-
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_A:
102-
if(menu_get_length(&menu) < 1)break;
103-
menu_item_t*menu_item = menu_find_item(&menu, menu_get_position(&menu));
104-
int newpathlen = strlen(path)+strlen(menu_item->label)+2;
105-
char*newpath=malloc(newpathlen);
106-
snprintf(newpath,newpathlen,"%s/%s",path,menu_item->label);
107-
unsigned char dtype = (unsigned char)menu_item->callback_arguments;
108-
switch(dtype){
109-
case DT_DIR:
110-
if(file_explorer(buffer,theme,newpath)){
111-
free(newpath);
112-
menu_free(&menu);
113-
return true;
114-
}
115-
}
116-
free(newpath);
117-
render(buffer, theme, &menu, path, position, false, true);
118-
default:break;
119-
}
120-
}
121-
default:break;
122-
}
73+
while (1) {
74+
bsp_input_event_t event;
75+
if (xQueueReceive(input_event_queue, &event, pdMS_TO_TICKS(1000)) == pdTRUE) {
76+
switch (event.type) {
77+
case INPUT_EVENT_TYPE_NAVIGATION:
78+
if (event.args_navigation.state) {
79+
switch (event.args_navigation.key) {
80+
case BSP_INPUT_NAVIGATION_KEY_ESC:
81+
case BSP_INPUT_NAVIGATION_KEY_F1:
82+
menu_free(&menu);
83+
return true;
84+
case BSP_INPUT_NAVIGATION_KEY_F2:
85+
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_B:
86+
menu_free(&menu);
87+
return false;
88+
case BSP_INPUT_NAVIGATION_KEY_UP:
89+
menu_navigate_previous(&menu);
90+
render(buffer, theme, &menu, path, position, true, false);
91+
break;
92+
case BSP_INPUT_NAVIGATION_KEY_DOWN:
93+
menu_navigate_next(&menu);
94+
render(buffer, theme, &menu, path, position, true, false);
95+
break;
96+
case BSP_INPUT_NAVIGATION_KEY_RETURN:
97+
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_A:
98+
if (menu_get_length(&menu) < 1) break;
99+
menu_item_t* menu_item = menu_find_item(&menu, menu_get_position(&menu));
100+
int newpathlen = strlen(path) + strlen(menu_item->label) + 2;
101+
char* newpath = malloc(newpathlen);
102+
snprintf(newpath, newpathlen, "%s/%s", path, menu_item->label);
103+
unsigned char dtype = (unsigned char)menu_item->callback_arguments;
104+
switch (dtype) {
105+
case DT_DIR:
106+
if (file_explorer(buffer, theme, newpath)) {
107+
free(newpath);
108+
menu_free(&menu);
109+
return true;
110+
}
111+
}
112+
free(newpath);
113+
render(buffer, theme, &menu, path, position, false, true);
114+
default:
115+
break;
116+
}
117+
}
118+
default:
119+
break;
120+
}
121+
}
123122
}
124-
}
125123
}
126124

127-
void menu_file_explorer(pax_buf_t* buffer, gui_theme_t* theme){
128-
file_explorer(buffer,theme,"/sd");
125+
void menu_file_explorer(pax_buf_t* buffer, gui_theme_t* theme) {
126+
file_explorer(buffer, theme, "/sd");
129127
}
130-
131-

main/menu/home.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ static void execute_action(pax_buf_t* fb, menu_home_action_t action, gui_theme_t
5555
case ACTION_REPOSITORY:
5656
menu_repository_client(fb, theme);
5757
break;
58-
case ACTION_FILES:
59-
menu_file_explorer(fb, theme);
58+
case ACTION_FILES:
59+
menu_file_explorer(fb, theme);
6060
default:
6161
break;
6262
}
@@ -125,7 +125,7 @@ void menu_home(void) {
125125
menu_t menu = {0};
126126
menu_initialize(&menu);
127127
menu_insert_item_icon(&menu, "Apps", NULL, (void*)ACTION_APPS, -1, get_icon(ICON_APPS));
128-
menu_insert_item_icon(&menu, "Files", NULL, (void*)ACTION_FILES, -1, get_icon(ICON_SD));
128+
menu_insert_item_icon(&menu, "Files", NULL, (void*)ACTION_FILES, -1, get_icon(ICON_SD));
129129
if (access("/sd/nametag.png", F_OK) == 0 || access("/int/nametag.png", F_OK) == 0) {
130130
menu_insert_item_icon(&menu, "Nametag", NULL, (void*)ACTION_NAMETAG, -1, get_icon(ICON_TAG));
131131
}

0 commit comments

Comments
 (0)