fix: fix desktop app loading cap
This commit is contained in:
@@ -29,9 +29,23 @@ struct MenuRow {
|
||||
SvgIcon* icon; // loaded menu icon (null for categories/dividers)
|
||||
};
|
||||
|
||||
static constexpr int MAX_MENU_ROWS = 48;
|
||||
inline MenuRow menu_rows[MAX_MENU_ROWS];
|
||||
inline MenuRow* menu_rows = nullptr;
|
||||
inline int menu_row_count = 0;
|
||||
inline int menu_row_capacity = 0;
|
||||
|
||||
// Return the next menu row, doubling the array as needed.
|
||||
// Returns nullptr if allocation failed.
|
||||
inline MenuRow* menu_alloc_row() {
|
||||
if (menu_row_count >= menu_row_capacity) {
|
||||
int new_cap = menu_row_capacity ? menu_row_capacity * 2 : 64;
|
||||
auto* grown = (MenuRow*)montauk::realloc(
|
||||
menu_rows, (uint64_t)new_cap * sizeof(MenuRow));
|
||||
if (!grown) return nullptr;
|
||||
menu_rows = grown;
|
||||
menu_row_capacity = new_cap;
|
||||
}
|
||||
return &menu_rows[menu_row_count++];
|
||||
}
|
||||
|
||||
// Collapsible category state (categories 0-3 are toggleable; divider category always expanded)
|
||||
static constexpr int MENU_NUM_CATS = 5;
|
||||
@@ -81,8 +95,9 @@ inline int menu_total_height() {
|
||||
// ============================================================================
|
||||
|
||||
inline int menu_add_category(const char* label) {
|
||||
if (menu_row_count >= MAX_MENU_ROWS) return -1;
|
||||
MenuRow& r = menu_rows[menu_row_count++];
|
||||
MenuRow* rp = menu_alloc_row();
|
||||
if (!rp) return -1;
|
||||
MenuRow& r = *rp;
|
||||
r.is_category = true;
|
||||
montauk::strncpy(r.label, label, sizeof(r.label));
|
||||
r.app_id = DESKTOP_BUILTIN_NONE;
|
||||
@@ -94,8 +109,9 @@ inline int menu_add_category(const char* label) {
|
||||
}
|
||||
|
||||
inline int menu_add_embedded(const char* label, DesktopBuiltinId app_id, SvgIcon* icon) {
|
||||
if (menu_row_count >= MAX_MENU_ROWS) return -1;
|
||||
MenuRow& r = menu_rows[menu_row_count++];
|
||||
MenuRow* rp = menu_alloc_row();
|
||||
if (!rp) return -1;
|
||||
MenuRow& r = *rp;
|
||||
r.is_category = false;
|
||||
montauk::strncpy(r.label, label, sizeof(r.label));
|
||||
r.app_id = app_id;
|
||||
@@ -107,8 +123,9 @@ inline int menu_add_embedded(const char* label, DesktopBuiltinId app_id, SvgIcon
|
||||
}
|
||||
|
||||
inline int menu_add_external(const char* label, const char* binary, SvgIcon* icon, bool launch_with_home) {
|
||||
if (menu_row_count >= MAX_MENU_ROWS) return -1;
|
||||
MenuRow& r = menu_rows[menu_row_count++];
|
||||
MenuRow* rp = menu_alloc_row();
|
||||
if (!rp) return -1;
|
||||
MenuRow& r = *rp;
|
||||
r.is_category = false;
|
||||
montauk::strncpy(r.label, label, sizeof(r.label));
|
||||
r.app_id = DESKTOP_BUILTIN_NONE;
|
||||
|
||||
Reference in New Issue
Block a user