MCPcopy Create free account
hub / github.com/OpenStickCommunity/GP2040-CE / obdMenuGetItem

Function obdMenuGetItem

lib/OneBitDisplay/OneBitDisplay.cpp:911–937  ·  view source on GitHub ↗

Get the text and centering position for a specific menu item returns the X position

Source from the content-addressed store, hash-verified

909// returns the X position
910//
911static int obdMenuGetItem(SIMPLEMENU *sm, int iItem, char *szText)
912{
913 int x, cx, len;
914
915 if (iItem > sm->iMenuLen)
916 return -1; // invalid request
917
918 if (sm->iFontSize == FONT_6x8)
919 cx = 6;
920 else if (sm->iFontSize == FONT_8x8)
921 cx = 8;
922 else
923 cx = 16;
924 strcpy(szText, sm->pMenuText[iItem]);
925 if (sm->pfnCallback && iItem > 0) // don't add callback for menu title
926 {
927 strcat(szText, " ");
928 strcat(szText, (*sm->pfnCallback)(iItem - 1));
929 }
930 x = 0;
931 if (sm->bCenter || iItem == 0) // always center the menu title
932 {
933 len = strlen(szText);
934 x = (sm->iDispX - (len * cx)) / 2;
935 }
936 return x;
937} /* obdMenuGetItem() */
938
939//
940// Erase the display and show the given menu

Callers 3

obdMenuShowFunction · 0.85
obdMenuFlashFunction · 0.85
obdMenuDeltaFunction · 0.85

Calls 1

strlenFunction · 0.85

Tested by

no test coverage detected