1 List Menu Text Coloring
ghoulslash edited this page 2022-12-13 11:43:19 -07:00

List Menu Item Text Coloring

Credit to ghoulslash

List menu items are pointers to specific strings, meaning if you want a specific text color on an individual entry, you'll need to change the string pointer, which can be annoying. Instead, we can update the ListMenuItem structure to add in color override values, which are indices to specific colors in the palette of the assigned windowId

Update ListMenuItem

  1. Open include/list_menu.h and Replace struct ListMenuItem with:
struct ListMenuItem
{
    const u8 *name;
    s16 id;
    u8 colors[2];  // Override cursorPal and cursorShadowPal for specific list menu items
};

Update the code

  1. Open src/list_menu.c and find the function ListMenuPrint
  2. Add a parameter to the end the function, u8 colorOverride

static void ListMenuPrint(struct ListMenu *list, const u8 *str, u8 x, u8 y, u8 *colorOverrides)

  1. In this same function, replace all instances with the following:
-colors[1] = gListMenuOverride.cursorPal;
-colors[2] = gListMenuOverride.cursorShadowPal;
+colors[1] = (colorOverrides[0] == 0) ? gListMenuOverride.cursorPal : colorOverrides[0];
+colors[2] = (colorOverrides[1] == 0) ? gListMenuOverride.cursorShadowPal : colorOverrides[1];
  1. In ListMenuPrintEntries, change the following:
-ListMenuPrint(list, list->template.items[startIndex].name, x, y);
+ListMenuPrint(list, list->template.items[startIndex].name, x, y, list->template.items[startIndex].colors);
  1. In ListMenuDrawCursor add u8 colors[2] = {0}; before the switch statement, and then:
-ListMenuPrint(list, gText_SelectorArrow2, x, y);
+ListMenuPrint(list, gText_SelectorArrow2, x, y, colors);

Usage example

A practical usage example using some code from ShowScrollableMultichoice

for (i = 0; i < task->tNumItems; i++)
{
    sScrollableMultichoice_ListMenuItem[i].name = sScrollingMultichoiceLists[task->tScrollMultiId].list[i].name;
    sScrollableMultichoice_ListMenuItem[i].id = i;
    sScrollableMultichoice_ListMenuItem[i].colors[0] = TEXT_COLOR_RED; // all entries will have red text
}

Here's an example of turning a single entry green:

voyager-2