Need help passing a font into a library

KrisKasprzak

Well-known member
All,

I'm porting my menu code over to a ST7735 using the Adafruit_ST7735 library and small displays and will be for use on Teensy LC and Arduino NANO.

My Library and usage work fine on a Teeny LC, I can set menu items, pass in neat fonts--life is good.

However, compiling to an Arduino NANO, the use of d->setFont(&PassedInFont) fails where not text is drawn

In my library i added a cheezey debug line Serial.println(sizeof(PassedInFont)); and 9 is printed. I'm guessing the font is not being passed in correctly--but I have no idea what the issue is.

I'm happy to submit all my code and library, but I doubt anyone will want to sift through it. Hence I've include snippets so you can see how I'm passing in fonts.




my .h file for the init prototype has publics for the init and the variables, notice the use of the & to pass by reference (something Adafruit GFX fonts need)

Code:
void init(uint16_t TextColor, uint16_t BackgroundColor,
          uint16_t HighlightTextColor, uint16_t HighlightColor,
          uint16_t SelectedTextColor, uint16_t SelectedColor,
          uint16_t MenuColumn, uint16_t ItemRowHeight, uint16_t MaxRow,
          const char *TitleText, const GFXfont &ItemFont, const GFXfont &TitleFont);


GFXfont itemf;
GFXfont titlef;


my .cpp file for the init simply assigns the passed font to a GFXFont-based variable
Code:
void EditMenu::init(uint16_t TextColor, uint16_t BackgroundColor,
                    uint16_t HighlightTextColor, uint16_t HighlightColor,
                    uint16_t SelectedTextColor, uint16_t SelectedColor,
                    uint16_t MenuColumn, uint16_t ItemRowHeight, uint16_t MaxRow,
                    const char *TitleText, const GFXfont &ItemFont, const GFXfont &TitleFont) {

  itemf = ItemFont;     // item font
  titlef = TitleFont;     // title font

in my library where I want to draw text and such i simply use SetFont and pass by ref (again something Adafruit GFX fonts need)

Code:
 d->setFont(&titlef);


My .ino implementation code
Code:
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include "Adafruit_ST7735_Menu.h"
#include "fonts\FreeSansBold12pt7b.h"
#include "fonts\FreeSans12pt7b.h"



OptionMenu.init(C_WHITE, C_BLACK, C_WHITE, C_DKBLUE, C_WHITE, C_RED, 80, 20, 4, "Options", FreeSans12pt7b, FreeSansBold12pt7b);
 
Back
Top