diff --git a/src/gui/screen_menu.c b/src/gui/screen_menu.c index 565ab31d70..d08e829377 100644 --- a/src/gui/screen_menu.c +++ b/src/gui/screen_menu.c @@ -8,6 +8,7 @@ #include "screen_menu.h" #include "config.h" #include "stdlib.h" +#include "resource.h" void window_set_capture(int16_t id); @@ -22,9 +23,10 @@ void screen_menu_item(window_menu_t *pwindow_menu, uint16_t index, *ppitem = &(psmd->items[index].item); } -void screen_menu_init(screen_t *screen, - const char *label, int count, uint8_t footer, uint8_t help) { - psmd->items = (menu_item_t *)malloc(sizeof(menu_item_t) * count); +void screen_menu_init(screen_t *screen, const char *label, + menu_item_t *p_items, size_t count, uint8_t footer, uint8_t help) { + + psmd->items = p_items; memset(psmd->items, '\0', sizeof(menu_item_t) * count); rect_ui16_t menu_rect = rect_ui16(10, 32, 220, 278); @@ -58,41 +60,33 @@ void screen_menu_init(screen_t *screen, window_set_focus(id); if (help) { - psmd->phelp = (window_text_t *)gui_malloc(sizeof(window_text_t)); + psmd->flags.has_help = 1; id = window_create_ptr(WINDOW_CLS_TEXT, root, (footer) ? rect_ui16(10, 154, 220, 115) : rect_ui16(10, 195, 220, 115), - psmd->phelp); - psmd->phelp->font = resource_font(IDR_FNT_SPECIAL); + &psmd->help); + psmd->help.font = resource_font(IDR_FNT_SPECIAL); } else { - psmd->phelp = NULL; + psmd->flags.has_help = 0; } if (footer) { - psmd->pfooter = (status_footer_t *)gui_malloc(sizeof(status_footer_t)); - status_footer_init(psmd->pfooter, root); + psmd->flags.has_footer = 1; + status_footer_init(&psmd->footer, root); } else { - psmd->pfooter = NULL; + psmd->flags.has_footer = 0; } } void screen_menu_done(screen_t *screen) { window_destroy(psmd->root.win.id); - if (psmd->phelp) { - free(psmd->phelp); - } - - if (psmd->pfooter) { - free(psmd->pfooter); - } - free(psmd->items); } void screen_menu_draw(screen_t *screen) {} int screen_menu_event(screen_t *screen, window_t *window, uint8_t event, void *param) { - if (psmd->pfooter) { - status_footer_event(psmd->pfooter, window, event, param); + if (psmd->flags.has_footer) { + status_footer_event(&psmd->footer, window, event, param); } window_header_events(&(psmd->header)); diff --git a/src/gui/screen_menu.h b/src/gui/screen_menu.h index 8d2eefaaf6..fbd9b1e4cf 100644 --- a/src/gui/screen_menu.h +++ b/src/gui/screen_menu.h @@ -16,6 +16,11 @@ #pragma pack(push) #pragma pack(1) +typedef struct { + uint8_t has_footer : 1; + uint8_t has_help : 1; +} menu_flags_t; + typedef struct _menu_item_t { window_menu_item_t item; screen_t *screen; @@ -28,8 +33,9 @@ typedef struct window_menu_t menu; menu_item_t *items; - window_text_t *phelp; - status_footer_t *pfooter; + menu_flags_t flags; + window_text_t help; + status_footer_t footer; } screen_menu_data_t; @@ -45,8 +51,8 @@ extern "C" { extern const menu_item_t menu_item_return; -void screen_menu_init(screen_t *screen, - const char *label, int count, uint8_t footer, uint8_t help); +void screen_menu_init(screen_t *screen, const char *label, + menu_item_t *p_items, size_t count, uint8_t footer, uint8_t help); void screen_menu_done(screen_t *screen); diff --git a/src/gui/screen_menu_calibration.c b/src/gui/screen_menu_calibration.c index eebbec4ab4..1b27ef36eb 100644 --- a/src/gui/screen_menu_calibration.c +++ b/src/gui/screen_menu_calibration.c @@ -22,6 +22,7 @@ typedef enum { #endif // MI_CALIB_XY, MI_CALIB_FIRST, + MI_COUNT } MI_t; const menu_item_t _menu_calibration_items[] = { @@ -38,12 +39,24 @@ const menu_item_t _menu_calibration_items[] = { { { "First Layer Cal.", 0, WI_LABEL }, SCREEN_MENU_NO_SCREEN }, }; +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[MI_COUNT]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_menu_calibration_init(screen_t *screen) { marlin_vars_t *vars; - int count = sizeof(_menu_calibration_items) / sizeof(menu_item_t); - screen_menu_init(screen, "CALIBRATION", count + 1, 0, 0); + screen_menu_init(screen, "CALIBRATION", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 0, 0); psmd->items[MI_RETURN] = menu_item_return; - memcpy(psmd->items + 1, _menu_calibration_items, count * sizeof(menu_item_t)); + memcpy(psmd->items + 1, _menu_calibration_items, (MI_COUNT - 1) * sizeof(menu_item_t)); vars = marlin_update_vars(MARLIN_VAR_MSK(MARLIN_VAR_Z_OFFSET)); psmd->items[MI_Z_OFFSET].item.wi_spin_fl.value = vars->z_offset; @@ -95,7 +108,7 @@ screen_t screen_menu_calibration = { screen_menu_done, screen_menu_draw, screen_menu_calibration_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/screen_menu_filament.c b/src/gui/screen_menu_filament.c index 766402b84c..94333b72b3 100644 --- a/src/gui/screen_menu_filament.c +++ b/src/gui/screen_menu_filament.c @@ -23,6 +23,7 @@ typedef enum { MI_UNLOAD, MI_CHANGE, MI_PURGE, + MI_COUNT } MI_t; const menu_item_t _menu_filament_items[] = { @@ -69,12 +70,24 @@ static void _deactivate_item(screen_t *screen) { } } +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[MI_COUNT]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_menu_filament_init(screen_t *screen) { //filament_not_loaded = -1; - int count = sizeof(_menu_filament_items) / sizeof(menu_item_t); - screen_menu_init(screen, "FILAMENT", count + 1, 1, 0); + screen_menu_init(screen, "FILAMENT", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 0); psmd->items[0] = menu_item_return; - memcpy(psmd->items + 1, _menu_filament_items, count * sizeof(menu_item_t)); + memcpy(psmd->items + 1, _menu_filament_items, (MI_COUNT - 1) * sizeof(menu_item_t)); _deactivate_item(screen); } @@ -115,7 +128,7 @@ screen_t screen_menu_filament = { screen_menu_done, screen_menu_draw, screen_menu_filament_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/screen_menu_fw_update.c b/src/gui/screen_menu_fw_update.c index b8c7a68d60..9fad8fdef6 100644 --- a/src/gui/screen_menu_fw_update.c +++ b/src/gui/screen_menu_fw_update.c @@ -17,8 +17,21 @@ typedef enum { MI_COUNT, } MI_t; +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[MI_COUNT]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_menu_fw_update_init(screen_t *screen) { - screen_menu_init(screen, "FW UPDATE", MI_COUNT, 1, 1); + screen_menu_init(screen, "FW UPDATE", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 1); psmd->items[MI_RETURN] = menu_item_return; psmd->items[MI_ALWAYS] = (menu_item_t) { { "Always", 0, WI_SWITCH, .wi_switch_select = { 0, opt_on_off } }, SCREEN_MENU_NO_SCREEN }; psmd->items[MI_ON_RESTART] = (menu_item_t) { { "On restart", 0, WI_SWITCH, .wi_switch_select = { 0, opt_on_off } }, SCREEN_MENU_NO_SCREEN }; @@ -30,8 +43,8 @@ void screen_menu_fw_update_init(screen_t *screen) { psmd->items[MI_ALWAYS].item.wi_switch_select.index = 1; psmd->items[MI_ON_RESTART].item.wi_switch_select.index = sys_fw_update_on_restart_is_enabled() ? 0 : 1; } - psmd->phelp[0].font = resource_font(IDR_FNT_SPECIAL); - window_set_text(psmd->phelp[0].win.id, "Select when you want\nto automatically flash\nupdated firmware\nfrom USB flash disk."); + psmd->help.font = resource_font(IDR_FNT_SPECIAL); + window_set_text(psmd->help.win.id, "Select when you want\nto automatically flash\nupdated firmware\nfrom USB flash disk."); } int screen_menu_fw_update_event(screen_t *screen, window_t *window, uint8_t event, void *param) { @@ -68,7 +81,7 @@ screen_t screen_menu_fw_update = { screen_menu_done, screen_menu_draw, screen_menu_fw_update_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/screen_menu_info.c b/src/gui/screen_menu_info.c index d2113aa731..f5d2a63eef 100644 --- a/src/gui/screen_menu_info.c +++ b/src/gui/screen_menu_info.c @@ -18,7 +18,8 @@ typedef enum { MI_FAIL_STAT, MI_SUPPORT, #endif //_DEBUG - MI_VERSIONS + MI_VERSIONS, + MI_COUNT } MI_t; const menu_item_t _menu_info_items[] = { @@ -47,11 +48,23 @@ const menu_item_t _menu_info_items[] = { #endif //_DEBUG }; +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[MI_COUNT]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_menu_info_init(screen_t *screen) { - int count = sizeof(_menu_info_items) / sizeof(menu_item_t); - screen_menu_init(screen, "INFO", count + 1, 1, 0); + screen_menu_init(screen, "INFO", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 0); psmd->items[MI_RETURN] = menu_item_return; - memcpy(psmd->items + 1, _menu_info_items, count * sizeof(menu_item_t)); + memcpy(psmd->items + 1, _menu_info_items, (MI_COUNT - 1) * sizeof(menu_item_t)); } int screen_menu_info_event(screen_t *screen, window_t *window, uint8_t event, void *param) { @@ -65,7 +78,7 @@ screen_t screen_menu_info = { screen_menu_done, screen_menu_draw, screen_menu_info_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/screen_menu_move.c b/src/gui/screen_menu_move.c index 14dcc17fa8..02fc510f4c 100644 --- a/src/gui/screen_menu_move.c +++ b/src/gui/screen_menu_move.c @@ -12,6 +12,7 @@ typedef enum { MI_MOVE_Y, MI_MOVE_Z, MI_MOVE_E, + MI_COUNT } MI_t; const menu_item_t _menu_move_items[] = { @@ -21,12 +22,24 @@ const menu_item_t _menu_move_items[] = { { { "Extruder", 0, WI_SPIN, .wi_spin = { 0, move_e } }, SCREEN_MENU_NO_SCREEN }, }; +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[MI_COUNT]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_menu_move_init(screen_t *screen) { marlin_vars_t *vars; - int count = sizeof(_menu_move_items) / sizeof(menu_item_t); - screen_menu_init(screen, "MOVE AXIS", count + 1, 1, 0); + screen_menu_init(screen, "MOVE AXIS", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 0); psmd->items[0] = menu_item_return; - memcpy(psmd->items + 1, _menu_move_items, count * sizeof(menu_item_t)); + memcpy(psmd->items + 1, _menu_move_items, (MI_COUNT - 1) * sizeof(menu_item_t)); vars = marlin_update_vars(MARLIN_VAR_MSK_POS_XYZE | MARLIN_VAR_MSK(MARLIN_VAR_TEMP_NOZ)); psmd->items[MI_MOVE_X].item.wi_spin.value = (int32_t)(vars->pos[0] * 1000); @@ -78,7 +91,7 @@ screen_t screen_menu_move = { screen_menu_done, 0, screen_menu_move_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/screen_menu_preheat.cpp b/src/gui/screen_menu_preheat.cpp index 4692fc486e..b8e8fd3e8c 100644 --- a/src/gui/screen_menu_preheat.cpp +++ b/src/gui/screen_menu_preheat.cpp @@ -13,14 +13,27 @@ uint8_t menu_preheat_type = 0; // 0 - preheat, 1 - load filament, 2 - unload filament +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[FILAMENTS_END + 1]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_menu_preheat_init(screen_t *screen) { switch (menu_preheat_type) { case 0: - screen_menu_init(screen, "PREHEAT", FILAMENTS_END + 1, 1, 0); + screen_menu_init(screen, "PREHEAT", ((this_screen_data_t *)screen->pdata)->items, FILAMENTS_END + 1, 1, 0); break; case 1: - screen_menu_init(screen, "LOAD FILAMENT", FILAMENTS_END, 1, 1); - window_set_text(psmd->phelp->win.id, + screen_menu_init(screen, "LOAD FILAMENT", ((this_screen_data_t *)screen->pdata)->items, FILAMENTS_END, 1, 1); + window_set_text(psmd->help.win.id, "The nozzle must be\npreheated before\ninserting the filament.\n" "Please, select the type\nof material"); break; @@ -86,7 +99,7 @@ screen_t screen_menu_preheat = { screen_menu_preheat_done, screen_menu_draw, screen_menu_preheat_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/screen_menu_service.c b/src/gui/screen_menu_service.c index 4aab9aba86..5874a55fd9 100644 --- a/src/gui/screen_menu_service.c +++ b/src/gui/screen_menu_service.c @@ -34,6 +34,19 @@ typedef enum { MI_COUNT } MI_t; +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[MI_COUNT]; + +} this_screen_data_t; + +#pragma pack(pop) + int16_t sscg_freq_kHz = 5; int16_t sscg_depth = 5; int16_t spi_prescaler = 0; @@ -44,7 +57,7 @@ const int32_t opt_sscg_depth[] = { 1000, 20000, 1000 }; const char *opt_spi[] = { "21M", "10.5M", "5.25M", "2.63M", "1.31M", "656k", "328k", "164k", NULL }; void screen_menu_service_init(screen_t *screen) { - screen_menu_init(screen, "SERVICE", MI_COUNT, 0, 0); + screen_menu_init(screen, "SERVICE", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 0, 0); psmd->items[MI_RETURN] = menu_item_return; psmd->items[MI_SYS_RESET] = (menu_item_t) { { "System reset", 0, WI_LABEL }, SCREEN_MENU_NO_SCREEN }; @@ -140,7 +153,7 @@ screen_t screen_menu_service = { screen_menu_done, screen_menu_draw, screen_menu_service_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/screen_menu_settings.c b/src/gui/screen_menu_settings.c index 69fc067c65..d180acf61a 100644 --- a/src/gui/screen_menu_settings.c +++ b/src/gui/screen_menu_settings.c @@ -57,6 +57,7 @@ typedef enum { MI_EE_SAVE, MI_EE_SAVEXML, #endif //_DEBUG + MI_COUNT } MI_t; const menu_item_t _menu_settings_items[] = { @@ -91,11 +92,23 @@ const menu_item_t _menu_settings_items[] = { #endif //_DEBUG }; +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[MI_COUNT]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_menu_settings_init(screen_t *screen) { - int count = sizeof(_menu_settings_items) / sizeof(menu_item_t); - screen_menu_init(screen, "SETTINGS", count + 1, 1, 0); + screen_menu_init(screen, "SETTINGS", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 0); psmd->items[MI_RETURN] = menu_item_return; - memcpy(psmd->items + 1, _menu_settings_items, count * sizeof(menu_item_t)); + memcpy(psmd->items + 1, _menu_settings_items, (MI_COUNT - 1) * sizeof(menu_item_t)); fsensor_t fs = fs_wait_inicialized(); if (fs == FS_NOT_CONNECTED) { @@ -201,7 +214,7 @@ screen_t screen_menu_settings = { screen_menu_done, screen_menu_draw, screen_menu_settings_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/screen_menu_temperature.c b/src/gui/screen_menu_temperature.c index a55ae1a6ff..76f0099bb7 100644 --- a/src/gui/screen_menu_temperature.c +++ b/src/gui/screen_menu_temperature.c @@ -12,6 +12,7 @@ typedef enum { MI_HEATBED, MI_PRINTFAN, MI_COOLDOWN, + MI_COUNT } MI_t; const menu_item_t _menu_temperature_items[] = { @@ -21,12 +22,24 @@ const menu_item_t _menu_temperature_items[] = { { { "Cooldown", 0, WI_LABEL }, SCREEN_MENU_NO_SCREEN }, }; +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[MI_COUNT]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_menu_temperature_init(screen_t *screen) { marlin_vars_t *vars; - int count = sizeof(_menu_temperature_items) / sizeof(menu_item_t); - screen_menu_init(screen, "TEMPERATURE", count + 1, 1, 0); + screen_menu_init(screen, "TEMPERATURE", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 0); psmd->items[MI_RETURN] = menu_item_return; - memcpy(psmd->items + 1, _menu_temperature_items, count * sizeof(menu_item_t)); + memcpy(psmd->items + 1, _menu_temperature_items, (MI_COUNT - 1) * sizeof(menu_item_t)); vars = marlin_update_vars( MARLIN_VAR_MSK(MARLIN_VAR_TTEM_NOZ) | MARLIN_VAR_MSK(MARLIN_VAR_TTEM_BED) | MARLIN_VAR_MSK(MARLIN_VAR_FANSPEED)); @@ -69,7 +82,7 @@ screen_t screen_menu_temperature = { screen_menu_done, screen_menu_draw, screen_menu_temperature_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/screen_menu_tune.cpp b/src/gui/screen_menu_tune.cpp index 0211aec7a3..9d700e809e 100644 --- a/src/gui/screen_menu_tune.cpp +++ b/src/gui/screen_menu_tune.cpp @@ -27,6 +27,7 @@ enum { MI_TEST, #endif //_DEBUG MI_MESSAGES, + MI_COUNT }; //cannot use .wi_spin = { 0, feedrate_range } ... @@ -46,15 +47,27 @@ const menu_item_t _menu_tune_items[] = { { { "Messages", 0, WI_LABEL }, &screen_messages }, }; +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[MI_COUNT]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_menu_tune_timer(screen_t *screen, uint32_t mseconds); void screen_menu_tune_chanege_filament(screen_t *screen); void screen_menu_tune_init(screen_t *screen) { marlin_vars_t *vars; - int count = sizeof(_menu_tune_items) / sizeof(menu_item_t); - screen_menu_init(screen, "TUNE", count + 1, 1, 0); + screen_menu_init(screen, "TUNE", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 0); psmd->items[MI_RETURN] = menu_item_return; - memcpy(psmd->items + 1, _menu_tune_items, count * sizeof(menu_item_t)); + memcpy(psmd->items + 1, _menu_tune_items, (MI_COUNT - 1) * sizeof(menu_item_t)); vars = marlin_update_vars( MARLIN_VAR_MSK_TEMP_TARG | MARLIN_VAR_MSK(MARLIN_VAR_Z_OFFSET) | MARLIN_VAR_MSK(MARLIN_VAR_FANSPEED) | MARLIN_VAR_MSK(MARLIN_VAR_PRNSPEED) | MARLIN_VAR_MSK(MARLIN_VAR_FLOWFACT)); @@ -197,7 +210,7 @@ screen_t screen_menu_tune = { screen_menu_done, screen_menu_draw, screen_menu_tune_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/screen_version_info.cpp b/src/gui/screen_version_info.cpp index 0ba4ac9b37..e6a74a1777 100644 --- a/src/gui/screen_version_info.cpp +++ b/src/gui/screen_version_info.cpp @@ -10,6 +10,7 @@ #include "screen_menu.h" #include #include "version.h" +#include "resource.h" #define BOOTLOADER_VERSION_ADDRESS 0x801FFFA #define OTP_START_ADDR 0x1FFF7800 @@ -28,18 +29,30 @@ struct version_t { #define VERSION_INFO_STR_MAXLEN 150 char *version_info_str = nullptr; +#pragma pack(push) +#pragma pack(1) + +//"C inheritance" of screen_menu_data_t with data items +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[1]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_menu_version_info_init(screen_t *screen) { //=============SCREEN INIT=============== - screen_menu_init(screen, "VERSION INFO", 1, 0, 0); + screen_menu_init(screen, "VERSION INFO", ((this_screen_data_t *)screen->pdata)->items, 1, 0, 0); version_info_str = (char *)gui_malloc(VERSION_INFO_STR_MAXLEN * sizeof(char)); p_window_header_set_icon(&(psmd->header), IDR_PNG_header_icon_info); psmd->items[0] = menu_item_return; - psmd->phelp = (window_text_t *)gui_malloc(sizeof(window_text_t)); - uint16_t id = window_create_ptr(WINDOW_CLS_TEXT, psmd->root.win.id, rect_ui16(10, 80, 220, 200), &(psmd->phelp[0])); - psmd->phelp[0].font = resource_font(IDR_FNT_NORMAL); + uint16_t id = window_create_ptr(WINDOW_CLS_TEXT, psmd->root.win.id, rect_ui16(10, 80, 220, 200), &(psmd->help)); + psmd->help.font = resource_font(IDR_FNT_NORMAL); //=============VARIABLES================= @@ -100,7 +113,7 @@ screen_t screen_version_info = { screen_menu_version_info_done, screen_menu_draw, screen_menu_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata }; diff --git a/src/gui/test/screen_test_temperature.cpp b/src/gui/test/screen_test_temperature.cpp index b2a3dd7c1d..aa6a0e0a8c 100644 --- a/src/gui/test/screen_test_temperature.cpp +++ b/src/gui/test/screen_test_temperature.cpp @@ -30,8 +30,21 @@ typedef enum { MI_COUNT } MI_t; +//"C inheritance" of screen_menu_data_t with data items +#pragma pack(push) +#pragma pack(1) + +typedef struct +{ + screen_menu_data_t base; + menu_item_t items[MI_COUNT]; + +} this_screen_data_t; + +#pragma pack(pop) + void screen_test_temperature_init(screen_t *screen) { - screen_menu_init(screen, "TEMPERATURE", MI_COUNT, 1, 0); + screen_menu_init(screen, "TEMPERATURE", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 0); psmd->items[MI_RETURN] = menu_item_return; @@ -102,7 +115,7 @@ screen_t screen_test_temperature = { screen_menu_done, screen_menu_draw, screen_test_temperature_event, - sizeof(screen_menu_data_t), //data_size + sizeof(this_screen_data_t), //data_size 0, //pdata };