Skip to content

Commit 46b2eba

Browse files
committed
use generic message_dialog_... functions everywhere
1 parent c56b74d commit 46b2eba

7 files changed

Lines changed: 86 additions & 109 deletions

File tree

main/menu/app_inspect.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@
3737
#define TEXT_SIZE 9
3838
#endif
3939

40-
// static void delete_app(app_t*app){
41-
// appfsDeleteFile(app->slug);
42-
//
43-
// }
44-
4540
static void render(pax_buf_t* buffer, gui_theme_t* theme, pax_vec2_t position, bool partial, bool icons, app_t* app) {
4641

4742
char text_buffer[256];
@@ -122,11 +117,9 @@ bool menu_app_inspect(pax_buf_t* buffer, gui_theme_t* theme, app_t* app) {
122117
render(buffer, theme, position, false, false, app);
123118
break;
124119
case BSP_INPUT_NAVIGATION_KEY_F5:
125-
bsp_input_navigation_key_t dia_result =
126-
message_dialog(buffer, theme, "Delete App", "Do you really want to delete the app?",
127-
MESSAGE_DIALOG_FOOTER_YES_NO);
128-
if (dia_result == BSP_INPUT_NAVIGATION_KEY_F4 ||
129-
dia_result == BSP_INPUT_NAVIGATION_KEY_GAMEPAD_A) {
120+
message_dialog_return_type_t msg_ret = message_dialog_yes_no(
121+
buffer, theme, "Delete App", "Do you really want to delete the app?");
122+
if (msg_ret == MSG_DIALOG_RETURN_OK) {
130123
appfsDeleteFile(app->slug);
131124
char text_buffer[256];
132125
snprintf(text_buffer, sizeof(text_buffer), "/sd/apps/%s", app->slug);

main/menu/apps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern bool wifi_stack_get_task_done(void);
3535
void execute_app(pax_buf_t* buffer, gui_theme_t* theme, pax_vec2_t position, app_t* app) {
3636

3737
if (app == NULL) {
38-
message_dialog(buffer, theme, "Error", "No app selected", MESSAGE_DIALOG_FOOTER_OK);
38+
message_dialog_ok(buffer, theme, "Error", "No app selected");
3939
return;
4040
}
4141

@@ -56,7 +56,7 @@ void execute_app(pax_buf_t* buffer, gui_theme_t* theme, pax_vec2_t position, app
5656
usb_mode_set(USB_DEBUG);
5757
esp_restart();
5858
} else {
59-
message_dialog(buffer, theme, "Error", "App not found", MESSAGE_DIALOG_FOOTER_OK);
59+
message_dialog_ok(buffer, theme, "Error", "App not found");
6060
}
6161
}
6262

main/menu/message_dialog.c

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -232,54 +232,56 @@ bsp_input_navigation_key_t message_dialog(pax_buf_t* buffer, gui_theme_t* theme,
232232
}
233233
}
234234

235-
message_dialog_return_type_t message_dialog_ok(pax_buf_t* buffer, gui_theme_t* theme, const char* title, const char* message){
236-
bsp_input_navigation_key_t key;
237-
while(1){
238-
key = message_dialog(buffer, theme, title, message, MESSAGE_DIALOG_FOOTER_OK);
239-
switch(key){
240-
case BSP_INPUT_NAVIGATION_KEY_ESC:
241-
case BSP_INPUT_NAVIGATION_KEY_F1:
242-
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_A:
243-
return MSG_DIALOG_RETURN_OK;
244-
default:
235+
message_dialog_return_type_t message_dialog_ok(pax_buf_t* buffer, gui_theme_t* theme, const char* title,
236+
const char* message) {
237+
bsp_input_navigation_key_t key;
238+
while (1) {
239+
key = message_dialog(buffer, theme, title, message, MESSAGE_DIALOG_FOOTER_OK);
240+
switch (key) {
241+
case BSP_INPUT_NAVIGATION_KEY_ESC:
242+
case BSP_INPUT_NAVIGATION_KEY_F1:
243+
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_A:
244+
return MSG_DIALOG_RETURN_OK;
245+
default:
246+
}
245247
}
246-
}
247248
}
248249

249-
message_dialog_return_type_t message_dialog_yes_no(pax_buf_t* buffer, gui_theme_t* theme, const char* title, const char* message){
250-
bsp_input_navigation_key_t key;
251-
while(1){
252-
key = message_dialog(buffer, theme, title, message, MESSAGE_DIALOG_FOOTER_YES_NO);
253-
switch(key){
254-
case BSP_INPUT_NAVIGATION_KEY_ESC:
255-
case BSP_INPUT_NAVIGATION_KEY_F1:
256-
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_B:
257-
return MSG_DIALOG_RETURN_NO;
258-
case BSP_INPUT_NAVIGATION_KEY_F4:
259-
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_A:
260-
return MSG_DIALOG_RETURN_OK;
261-
default:
250+
message_dialog_return_type_t message_dialog_yes_no(pax_buf_t* buffer, gui_theme_t* theme, const char* title,
251+
const char* message) {
252+
bsp_input_navigation_key_t key;
253+
while (1) {
254+
key = message_dialog(buffer, theme, title, message, MESSAGE_DIALOG_FOOTER_YES_NO);
255+
switch (key) {
256+
case BSP_INPUT_NAVIGATION_KEY_ESC:
257+
case BSP_INPUT_NAVIGATION_KEY_F1:
258+
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_B:
259+
return MSG_DIALOG_RETURN_NO;
260+
case BSP_INPUT_NAVIGATION_KEY_F4:
261+
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_A:
262+
return MSG_DIALOG_RETURN_OK;
263+
default:
264+
}
262265
}
263-
}
264266
}
265267

266-
message_dialog_return_type_t message_dialog_yes_no_cancel(pax_buf_t* buffer, gui_theme_t* theme, const char* title, const char* message){
267-
bsp_input_navigation_key_t key;
268-
while(1){
269-
key = message_dialog(buffer, theme, title, message, MESSAGE_DIALOG_FOOTER_YES_NO_CANCEL);
270-
switch(key){
271-
case BSP_INPUT_NAVIGATION_KEY_ESC:
272-
case BSP_INPUT_NAVIGATION_KEY_F1:
273-
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_B:
274-
return MSG_DIALOG_RETURN_NO;
275-
case BSP_INPUT_NAVIGATION_KEY_F4:
276-
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_A:
277-
return MSG_DIALOG_RETURN_OK;
278-
case BSP_INPUT_NAVIGATION_KEY_F6:
279-
case BSP_INPUT_NAVIGATION_KEY_MENU:
280-
return MSG_DIALOG_RETURN_CANCEL;
281-
default:
268+
message_dialog_return_type_t message_dialog_yes_no_cancel(pax_buf_t* buffer, gui_theme_t* theme, const char* title,
269+
const char* message) {
270+
bsp_input_navigation_key_t key;
271+
while (1) {
272+
key = message_dialog(buffer, theme, title, message, MESSAGE_DIALOG_FOOTER_YES_NO_CANCEL);
273+
switch (key) {
274+
case BSP_INPUT_NAVIGATION_KEY_ESC:
275+
case BSP_INPUT_NAVIGATION_KEY_F1:
276+
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_B:
277+
return MSG_DIALOG_RETURN_NO;
278+
case BSP_INPUT_NAVIGATION_KEY_F4:
279+
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_A:
280+
return MSG_DIALOG_RETURN_OK;
281+
case BSP_INPUT_NAVIGATION_KEY_F6:
282+
case BSP_INPUT_NAVIGATION_KEY_MENU:
283+
return MSG_DIALOG_RETURN_CANCEL;
284+
default:
285+
}
282286
}
283-
}
284287
}
285-

main/menu/message_dialog.h

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
#include "gui_style.h"
66
#include "pax_types.h"
77

8-
9-
108
typedef enum {
11-
MSG_DIALOG_RETURN_OK,
12-
MSG_DIALOG_RETURN_NO,
13-
MSG_DIALOG_RETURN_CANCEL,
9+
MSG_DIALOG_RETURN_OK,
10+
MSG_DIALOG_RETURN_NO,
11+
MSG_DIALOG_RETURN_CANCEL,
1412
} message_dialog_return_type_t;
1513

16-
17-
1814
void render_base_screen(pax_buf_t* buffer, gui_theme_t* theme, bool background, bool header, bool footer,
1915
gui_header_field_t* header_left, size_t header_left_count, gui_header_field_t* header_right,
2016
size_t header_right_count, gui_header_field_t* footer_left, size_t footer_left_count,
@@ -27,47 +23,37 @@ void render_base_screen_statusbar(pax_buf_t* buffer, gui_theme_t* theme, bool ba
2723
bsp_input_navigation_key_t message_dialog(pax_buf_t* buffer, gui_theme_t* theme, const char* title, const char* message,
2824
gui_header_field_t* headers, int header_count);
2925

30-
31-
32-
message_dialog_return_type_t message_dialog_ok(pax_buf_t* buffer, gui_theme_t* theme, const char* title, const char* message);
33-
message_dialog_return_type_t message_dialog_yes_no(pax_buf_t* buffer, gui_theme_t* theme, const char* title, const char* message);
34-
message_dialog_return_type_t message_dialog_yes_no_cancel(pax_buf_t* buffer, gui_theme_t* theme, const char* title, const char* message);
35-
26+
message_dialog_return_type_t message_dialog_ok(pax_buf_t* buffer, gui_theme_t* theme, const char* title,
27+
const char* message);
28+
message_dialog_return_type_t message_dialog_yes_no(pax_buf_t* buffer, gui_theme_t* theme, const char* title,
29+
const char* message);
30+
message_dialog_return_type_t message_dialog_yes_no_cancel(pax_buf_t* buffer, gui_theme_t* theme, const char* title,
31+
const char* message);
3632

3733
#if defined(CONFIG_BSP_TARGET_TANMATSU) || defined(CONFIG_BSP_TARGET_KONSOOL) || \
3834
defined(CONFIG_BSP_TARGET_HACKERHOTEL_2026)
39-
#define MESSAGE_DIALOG_FOOTER_OK ((gui_header_field_t[]){ \
40-
{get_icon(ICON_ESC), "/"}, \
41-
{get_icon(ICON_F1), "OK"}}), 2
42-
#define MESSAGE_DIALOG_FOOTER_GOBACK ((gui_header_field_t[]){ \
43-
{get_icon(ICON_ESC), "/"}, \
44-
{get_icon(ICON_F1), "Go back"}}), 2
45-
#define MESSAGE_DIALOG_FOOTER_YES_NO ((gui_header_field_t[]){ \
46-
{get_icon(ICON_ESC), "/"}, \
47-
{get_icon(ICON_F1), "No"}, \
48-
{get_icon(ICON_F4), "Yes"}}), 3
49-
#define MESSAGE_DIALOG_FOOTER_YES_NO_CANCEL ((gui_header_field_t[]){ \
50-
{get_icon(ICON_ESC), "/"}, \
51-
{get_icon(ICON_F1), "No"}, \
52-
{get_icon(ICON_F4), "Yes"}, \
53-
{get_icon(ICON_F6), "Cancel"}}), 4
35+
#define MESSAGE_DIALOG_FOOTER_OK ((gui_header_field_t[]){{get_icon(ICON_ESC), "/"}, {get_icon(ICON_F1), "OK"}}), 2
36+
#define MESSAGE_DIALOG_FOOTER_GOBACK \
37+
((gui_header_field_t[]){{get_icon(ICON_ESC), "/"}, {get_icon(ICON_F1), "Go back"}}), 2
38+
#define MESSAGE_DIALOG_FOOTER_YES_NO \
39+
((gui_header_field_t[]){{get_icon(ICON_ESC), "/"}, {get_icon(ICON_F1), "No"}, {get_icon(ICON_F4), "Yes"}}), 3
40+
#define MESSAGE_DIALOG_FOOTER_YES_NO_CANCEL \
41+
((gui_header_field_t[]){{get_icon(ICON_ESC), "/"}, \
42+
{get_icon(ICON_F1), "No"}, \
43+
{get_icon(ICON_F4), "Yes"}, \
44+
{get_icon(ICON_F6), "Cancel"}}), \
45+
4
5446

5547
#elif defined(CONFIG_BSP_TARGET_MCH2022)
56-
#define MESSAGE_DIALOG_FOOTER_OK ((gui_header_field_t[]){ \
57-
{NULL, "🅱"}, {NULL, "Ok"}}), 2
58-
#define MESSAGE_DIALOG_FOOTER_GOBACK ((gui_header_field_t[]){ \
59-
{NULL, "🅱"}, {NULL, "Go back"}}), 2
60-
#define MESSAGE_DIALOG_FOOTER_YES_NO ((gui_header_field_t[]){ \
61-
{NULL, "🅰"}, {NULL, "Yes"}, \
62-
{NULL, "🅱"}, {NULL, "No"}}), 4
63-
#define MESSAGE_DIALOG_FOOTER_YES_NO_CANCEL ((gui_header_field_t[]){ \
64-
{NULL, "🅰"}, {NULL, "Yes"}, \
65-
{NULL, "🅱"}, {NULL, "No"}, \
66-
{NULL, "Menu Cancel"}}), 5
48+
#define MESSAGE_DIALOG_FOOTER_OK ((gui_header_field_t[]){{NULL, "🅱"}, {NULL, "Ok"}}), 2
49+
#define MESSAGE_DIALOG_FOOTER_GOBACK ((gui_header_field_t[]){{NULL, "🅱"}, {NULL, "Go back"}}), 2
50+
#define MESSAGE_DIALOG_FOOTER_YES_NO ((gui_header_field_t[]){{NULL, "🅰"}, {NULL, "Yes"}, {NULL, "🅱"}, {NULL, "No"}}), 4
51+
#define MESSAGE_DIALOG_FOOTER_YES_NO_CANCEL \
52+
((gui_header_field_t[]){{NULL, "🅰"}, {NULL, "Yes"}, {NULL, "🅱"}, {NULL, "No"}, {NULL, "Menu Cancel"}}), 5
6753

6854
#else
69-
#define MESSAGE_DIALOG_FOOTER_OK NULL, 0
70-
#define MESSAGE_DIALOG_FOOTER_GOBACK NULL, 0
71-
#define MESSAGE_DIALOG_FOOTER_YES_NO NULL, 0
55+
#define MESSAGE_DIALOG_FOOTER_OK NULL, 0
56+
#define MESSAGE_DIALOG_FOOTER_GOBACK NULL, 0
57+
#define MESSAGE_DIALOG_FOOTER_YES_NO NULL, 0
7258
#define MESSAGE_DIALOG_FOOTER_YES_NO_CANCEL NULL, 0
7359
#endif

main/menu/wifi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ static void render(pax_buf_t* buffer, gui_theme_t* theme, menu_t* menu, pax_vec2
5959
static void add_manually(pax_buf_t* buffer, gui_theme_t* theme) {
6060
int index = wifi_settings_find_empty_slot();
6161
if (index == -1) {
62-
message_dialog(buffer, theme, "Error", "No empty slot, can not add another network",
63-
MESSAGE_DIALOG_FOOTER_GOBACK);
62+
message_dialog_ok(buffer, theme, "Error", "No empty slot, can not add another network");
6463
}
6564
menu_wifi_edit(buffer, theme, index, true, "", 0);
6665
}

main/menu/wifi_edit.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ bool menu_wifi_edit(pax_buf_t* buffer, gui_theme_t* theme, uint8_t index, bool n
334334
snprintf(message, sizeof(message), "%s, failed to read WiFi settings at index %u", esp_err_to_name(res),
335335
index);
336336
printf("%s\r\n", message);
337-
message_dialog(buffer, theme, "An error occurred", message, MESSAGE_DIALOG_FOOTER_GOBACK);
337+
message_dialog_ok(buffer, theme, "An error occurred", message);
338338
return false;
339339
}
340340
}
@@ -398,8 +398,7 @@ bool menu_wifi_edit(pax_buf_t* buffer, gui_theme_t* theme, uint8_t index, bool n
398398
if (res == ESP_OK) {
399399
return true;
400400
} else {
401-
message_dialog(buffer, theme, "Error", "Failed to save WiFi settings",
402-
MESSAGE_DIALOG_FOOTER_GOBACK);
401+
message_dialog_ok(buffer, theme, "Error", "Failed to save WiFi settings");
403402
}
404403
}
405404
case BSP_INPUT_NAVIGATION_KEY_UP:

main/menu/wifi_scan.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ static esp_err_t scan_for_networks(pax_buf_t* buffer, gui_theme_t* theme, wifi_a
119119
free(aps);
120120
}
121121
} else {
122-
message_dialog(buffer, theme, "WiFi stack not initialized",
123-
"The WiFi stack is not initialized. Please try again later.", MESSAGE_DIALOG_FOOTER_OK);
122+
message_dialog_ok(buffer, theme, "WiFi stack not initialized",
123+
"The WiFi stack is not initialized. Please try again later.");
124124
return ESP_ERR_NOT_FOUND;
125125
}
126126
return ESP_OK;
@@ -174,8 +174,7 @@ void menu_wifi_scan(pax_buf_t* buffer, gui_theme_t* theme) {
174174
if (res != ESP_OK) {
175175
ESP_LOGE(TAG, "WiFi scan failed (%d)", res);
176176
if (res != ESP_ERR_NOT_FOUND) {
177-
message_dialog(buffer, theme, "An error occurred", "Scanning for WiFi networks failed",
178-
MESSAGE_DIALOG_FOOTER_OK);
177+
message_dialog_ok(buffer, theme, "An error occurred", "Scanning for WiFi networks failed");
179178
}
180179
return;
181180
}
@@ -236,9 +235,8 @@ void menu_wifi_scan(pax_buf_t* buffer, gui_theme_t* theme) {
236235
return;
237236
}
238237
} else {
239-
message_dialog(buffer, theme, "Error",
240-
"No empty slot, can not add another network",
241-
MESSAGE_DIALOG_FOOTER_OK);
238+
message_dialog_ok(buffer, theme, "Error",
239+
"No empty slot, can not add another network");
242240
}
243241
render(buffer, theme, &menu, position, false, false, false);
244242
}

0 commit comments

Comments
 (0)