how to store font references in an array?


I am developing an interactive touchscreen app and it needs to be flexible in every aspects. User can change not only colors of text but can change the fonts.

I am using adafruit GFX and fonts, so far everything is good. The problem starts with multiple font selection.
I included a couple fonts and use it like


that works. I can use this technique by putting in a if or switch statement like

#define MONO 1
#define SANS 2
void selectFont(int selection){
switch(selection) {
case MONO:
case SANS:

this method works however it costs speed and program memory, thats why i tried to store font references in an array like

GFXfont *myfonts[] = {&FreeMono9pt7b,&FreeSans9pt7b,&FreeSerif9pt7b};

but it gives me millions of error like

SerialConsole.h:49:14: error: initializer for flexible array member 'GFXfont* SerialConsole::myfonts []'

i trieed this code int my computer nimgw copliler and it works but it didnt arduino too. i think the compiler manages pointer differently.

    struct myStruct{        
    int number;

    myStruct no1,no2,no3;


   myStruct *arrayOfPointers[] ={&no1,&no2,&no3};

    for(int i = 0;i<sizeof(arrayOfPointers);i++){

any guidence will be much appreciated, thanks.

Hello again i made a deep searching and found out it is not about the compiler or structs it is about the memory the fonts are stored. Since they are not stored in ram, they stored in flash memory, the arrays of your pointers must be stored in const and predefined size. So my final array looks like this:

    const GFXfont *myfonts[7]= {

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.