Can I get the currently set text size? [Solved]

Continuing the discussion from Reference Page for Development:

Currently there isn’t a library function to get the text size but it’s true that it could be useful. I’ll add getTextSize(), as well as getTextColor(), getTextBackground() and getTextWrap() when I get a chance.

For now, you could use a global variable to keep track of the current size, and create functions that use it.

byte currentTextSize = 1; // keeps track of the currently set text size

// Set the text size and keep track of what was set
void setTextSize(byte size) {
  currentTextSize = size;
  arduboy.setTextSize(size);
}

// Get the current text size
byte getTextSize() {
  return currentTextSize;
}

Whenever you want to set the text size. use setTextSize() instead of arduboy.setTextSize()

Whenever you need to get the text size, such as in your centering function, use getTextSize()

If/when getTextSize() is added to the library, you could delete your currentTextSize() variable and replace setTextSize() with arduboy.setTextSize() and replace getTextSize() with arduboy.getTextSize()

@scum and anyone else interested,

Arduboy2 Library version 4.1.0 has been released, which adds the above functions.

1 Like

This is amazing, thank you! It really is a wonderful community where the developers not only respond but take action that fast. :heart:

1 Like

It is true @MLXXXp is the hero we need