Simplify menu_entry_get_sublabel

This commit is contained in:
twinaphex 2017-09-28 06:37:48 +02:00
parent b8e900cd32
commit db7e1a4fdf
3 changed files with 18 additions and 11 deletions

View File

@ -678,6 +678,7 @@ static void mui_compute_entries_box(mui_handle_t* mui, int width)
for (i = 0; i < entries_end; i++) for (i = 0; i < entries_end; i++)
{ {
menu_entry_t entry;
char sublabel_str[255]; char sublabel_str[255];
unsigned lines = 0; unsigned lines = 0;
mui_node_t *node = (mui_node_t*) mui_node_t *node = (mui_node_t*)
@ -685,11 +686,14 @@ static void mui_compute_entries_box(mui_handle_t* mui, int width)
sublabel_str[0] = '\0'; sublabel_str[0] = '\0';
menu_entry_init(&entry);
menu_entry_get(&entry, 0, i, NULL, true);
/* set texture_switch2 */ /* set texture_switch2 */
if (node->texture_switch2_set) if (node->texture_switch2_set)
texture_switch2 = node->texture_switch2; texture_switch2 = node->texture_switch2;
if (menu_entry_get_sublabel(i, sublabel_str, sizeof(sublabel_str))) if (menu_entry_get_sublabel(&entry, sublabel_str, sizeof(sublabel_str)))
{ {
int icon_margin = texture_switch2 ? mui->icon_size : 0; int icon_margin = texture_switch2 ? mui->icon_size : 0;
@ -814,6 +818,7 @@ static void mui_render_label_value(mui_handle_t *mui, mui_node_t *node,
1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00,
}; };
menu_entry_t entry;
menu_animation_ctx_ticker_t ticker; menu_animation_ctx_ticker_t ticker;
char label_str[255]; char label_str[255];
char sublabel_str[255]; char sublabel_str[255];
@ -831,6 +836,9 @@ static void mui_render_label_value(mui_handle_t *mui, mui_node_t *node,
label_str[0] = value_str[0] = label_str[0] = value_str[0] =
sublabel_str[0] = '\0'; sublabel_str[0] = '\0';
menu_entry_init(&entry);
menu_entry_get(&entry, 0, i, NULL, true);
if (value_len * mui->glyph_width > usable_width / 2) if (value_len * mui->glyph_width > usable_width / 2)
value_len = (int)((usable_width/2) / mui->glyph_width); value_len = (int)((usable_width/2) / mui->glyph_width);
@ -917,7 +925,7 @@ static void mui_render_label_value(mui_handle_t *mui, mui_node_t *node,
} }
/* Sublabel */ /* Sublabel */
if (menu_entry_get_sublabel(i, sublabel_str, sizeof(sublabel_str))) if (menu_entry_get_sublabel(&entry, sublabel_str, sizeof(sublabel_str)))
{ {
int icon_margin = texture_switch2 ? mui->icon_size : 0; int icon_margin = texture_switch2 ? mui->icon_size : 0;
@ -965,6 +973,8 @@ static void mui_render_label_value(mui_handle_t *mui, mui_node_t *node,
1, 1,
switch_is_on ? &label_color[0] : &pure_white[0] switch_is_on ? &label_color[0] : &pure_white[0]
); );
menu_entry_free(&entry);
} }
static void mui_render_menu_list( static void mui_render_menu_list(

View File

@ -113,17 +113,14 @@ void menu_entry_get_rich_label(menu_entry_t *entry, char *s, size_t len)
strlcpy(s, entry->path, len); strlcpy(s, entry->path, len);
} }
bool menu_entry_get_sublabel(uint32_t i, char *s, size_t len) bool menu_entry_get_sublabel(menu_entry_t *entry, char *s, size_t len)
{ {
menu_entry_t entry; if (!entry)
return false;
menu_entry_init(&entry); if (string_is_empty(entry->sublabel))
menu_entry_get(&entry, 0, i, NULL, true);
if (string_is_empty(entry.sublabel))
return false; return false;
strlcpy(s, entry.sublabel, len); strlcpy(s, entry->sublabel, len);
return true; return true;
} }

View File

@ -95,7 +95,7 @@ void menu_entry_reset(uint32_t i);
void menu_entry_get_rich_label(menu_entry_t *entry, char *s, size_t len); void menu_entry_get_rich_label(menu_entry_t *entry, char *s, size_t len);
bool menu_entry_get_sublabel(uint32_t i, char *s, size_t len); bool menu_entry_get_sublabel(menu_entry_t *entry, char *s, size_t len);
void menu_entry_get_value(menu_entry_t *entry, char *s, size_t len); void menu_entry_get_value(menu_entry_t *entry, char *s, size_t len);