greiman / SSD1306Ascii

Text only Arduino Library for SSD1306 OLED displays
MIT License
490 stars 120 forks source link

Is there a way to programmatically determine what Font is current? #88

Closed JonRobert closed 2 years ago

JonRobert commented 2 years ago

Thank you very much for this great library and for your support. I've been using it for quite a while and absolutely love it.

My question: I want to make a small macro (or function) to make the "oled.SSD1306Ascii::setCursor(0,0);" Row and column inputs more "natural". I thought if I could determine the current font after calling "oled.setFont(CalLite24); " it would be easy to implement. If not its not a show stopper, I would just have to make the font a variable and use it to read _WIDTH and _HEIGHT

Thanks again for your work and for sharing.

Jon

greiman commented 2 years ago

Not sure what you want. These functions return properties of the current font:

//------------------------------------------------------------------------------
uint8_t SSD1306Ascii::fontHeight() const {
  return m_font ? m_magFactor*readFontByte(m_font + FONT_HEIGHT) : 0;
}
//------------------------------------------------------------------------------
uint8_t SSD1306Ascii::fontRows() const {
  return m_font ? m_magFactor*((readFontByte(m_font + FONT_HEIGHT) + 7)/8) : 0;
}
//------------------------------------------------------------------------------
uint16_t SSD1306Ascii::fontSize() const {
  return (readFontByte(m_font) << 8) | readFontByte(m_font + 1);
}
//------------------------------------------------------------------------------
uint8_t SSD1306Ascii::fontWidth() const {
  return m_font ? m_magFactor*readFontByte(m_font + FONT_WIDTH) : 0;
}

setCursor(x, y) is pretty much the standard way to set the cursor in a graphics library. It allows you to position to the finest address on the display.

greiman commented 2 years ago
 /**
   * @return The current font pointer.
   */
  const uint8_t* font() const {return m_font;}
JonRobert commented 2 years ago

Bill,

Perfect ! The functions you show below is just what I was looking for. Sorry to bother you if it was in the examples or documentation.

And again thank you for your library and continued support.

Regards

John (aka JohnRob)

From: Bill Greiman @.> Sent: Monday, March 14, 2022 8:23 AM To: greiman/SSD1306Ascii @.> Cc: JonRobert @.>; Author @.> Subject: Re: [greiman/SSD1306Ascii] Is there a way to programmatically determine what Font is current? (Issue #88)

Not sure what you want. These functions return properties of the current font:

//------------------------------------------------------------------------------ uint8_t SSD1306Ascii::fontHeight() const { return m_font ? m_magFactorreadFontByte(m_font + FONT_HEIGHT) : 0; } //------------------------------------------------------------------------------ uint8_t SSD1306Ascii::fontRows() const { return m_font ? m_magFactor((readFontByte(m_font + FONT_HEIGHT) + 7)/8) : 0; } //------------------------------------------------------------------------------ uint16_t SSD1306Ascii::fontSize() const { return (readFontByte(m_font) << 8) | readFontByte(m_font + 1); } //------------------------------------------------------------------------------ uint8_t SSD1306Ascii::fontWidth() const { return m_font ? m_magFactor*readFontByte(m_font + FONT_WIDTH) : 0; }

setCursor(x, y) is pretty much the standard way to set the cursor in a graphics library. It allows you to position to the finest address on the display.

— Reply to this email directly, view it on GitHub https://github.com/greiman/SSD1306Ascii/issues/88#issuecomment-1066722934 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ADXP3JIHQ3GVZS45B5MRTA3U74VSJANCNFSM5QUWU3DQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . You are receiving this because you authored the thread.Message ID: @.***>

greiman commented 2 years ago

I think these functions are documented in the html here.

Click on SD1306Ascii.html. I will regenerate the html next time I update the library to make sure it matches the source.

JonRobert commented 2 years ago

Hi Bill,

After you sent me the functions I read through the documentation again and found them. I hadn’t used then in a while and was going on my old code that used was kind of clumsy.

Thank you so much for your follow up emails.

Regards

John

From: Bill Greiman @.> Sent: Tuesday, March 15, 2022 8:04 AM To: greiman/SSD1306Ascii @.> Cc: JonRobert @.>; Author @.> Subject: Re: [greiman/SSD1306Ascii] Is there a way to programmatically determine what Font is current? (Issue #88)

I think these functions are documented in the html here https://github.com/greiman/SSD1306Ascii/tree/master/doc .

Click on SD1306Ascii.html. I will regenerate the html next time I update the library to make sure it matches the source.

— Reply to this email directly, view it on GitHub https://github.com/greiman/SSD1306Ascii/issues/88#issuecomment-1067908397 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ADXP3JJWPQLBSG7H4WTN7KDVAB4D5ANCNFSM5QUWU3DQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub . You are receiving this because you authored the thread.Message ID: @.***>