U8g2: using different fontSize in same drawing?

Created on 14 Feb 2017  路  15Comments  路  Source: olikraus/u8g2

I'd give it a try but cannot make it. While I first set it to bigger font size, and drawStr something, and then set it to smaller font size and drawStr something. the bigger strings will move up to the top of the screen.

If it's possible, can you show a sample how to make it work?

Best regards

bug

All 15 comments

can you post the related non working code?

please check below code.

include "U8g2lib.h"

include

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=/ 12, / data=/ 14, / reset=*/ U8X8_PIN_NONE);

void setup() {
// Init oled
u8g2.begin();
u8g2.setDrawColor(1);
u8g2.setFontPosTop();
u8g2.setFontDirection(0);
}

void loop() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_logisoso34_tf);
u8g2.drawStr( 5, 12, "20");
u8g2.drawStr( 54, 12, "|");
u8g2.drawStr( 79, 12, "40");
// here mass the display
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(10,10,"T");
u8g2.sendBuffer();
}

Can you post a picture also? I mean it is difficult for me to understand the problem. At least the code seems fine for me and i actually did not understand the problem:
What is the current output? What is actually wrong? What did you expect instead?

Just to ensure, that this is not a font mode issue:
Did you play around with this command also?
u8g2_SetFontMode(u8g2_t *u8g2, uint8_t is_transparent);

https://github.com/olikraus/u8g2/wiki/u8g2reference#setfontmode

Although it should default to 1, it is probably best to set the font mode in the setup part of your .ino script:
u8g2.setFontMode(1);

2017-02-14 8 59 52
the above makes a correct display with only one font

2017-02-14 8 57 11
this one like a mass if using two different font

it's not the issue of setFontMode, please check above post for the image.

I'm using NodeMCU(ESP8266-12E) as MCU

I agree, this looks odd.
Let me try to reproduce the problem on my own systems.

I think the software behaves correctly and there is no problem. The only issue is, that setFont will reset the setFontPosTop command. This means, you need to call u8g2.setFontPosTop(); after each font change.

void loop() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_logisoso34_tf);
u8g2.setFontPosTop();
u8g2.drawStr( 5, 12, "20");
u8g2.drawStr( 54, 12, "|");
u8g2.drawStr( 79, 12, "40");
// here mass the display
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.setFontPosTop();
u8g2.drawStr(10,10,"T");
u8g2.sendBuffer();
for(;;)
  ;
}

I agree, that is should either document this behavior or change the behavior of the code itself.

thanks for solving this bug so quick!

Sorry that I had to re-open this issue.
It fixs the problem which cannot use different fontSize in same drawing, but creates another problem.

While using the new solution, the display will be freeze... without any update.

but as your above post, using setFontPosTop every time after setting the font, it works well.

Any example code which demonstrates the freezing?

Did you update the init code also?

I have placed the beta release here:
https://github.com/olikraus/U8g2_Arduino/archive/master.zip

Install the zip lib via the Arduino IDE Add Zip Lib menu.

Sorry, my fault, I forgot to modify the u8g2_setup.c file together, now all things running smooth.
Thank you for fixing the bug again!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

margce picture margce  路  7Comments

Bonnie12 picture Bonnie12  路  6Comments

13590787364 picture 13590787364  路  3Comments

luebbe picture luebbe  路  5Comments

Devilscave picture Devilscave  路  3Comments