Digole
©DIGITAL
SOLUTIONS

Serial Display emulator    New Display User manual

Forum login or
Login:
Password:
  
Forum Catagory
Digole Serial Display (215)
  12864 LCD/OLED module (24)
  24064 LCD module (3)
  Color LCD Modules (29)
  Color OLED module (21)
  Online Emulater (5)
  Universal GLCD module (1)
  Universal Text LCD module (2)
Mini Display Panels (0)
  Mini LCDs (0)
  Mini OLEDs (0)
Pattern Drive Module (0)
~Buy & Sell on Digole (2)
~Others~ (5)
Forum : Digole Serial Display :

 Search Forum.. 
 Creat New Topic   Reply 

Text in abs middle position

Hi to all.

I have an 160X128 color oled.

I try to find how to put a text like "SPDIF" in middle exactly position, but with automatic way, not with drawStr(5,0,"SPDIF").

Something like to count the word length and then to calculate the exactly position from set the string to (160-(word_length)/2)).

Somebody to help me, please?

 

RE:Text in abs middle position

I wrote my own function to do something similar, because you can not query the display to figure out how large a string will be in pixels (as it is very dependent on the font being used to draw the string).

What I do is a keep a table in flash that has the width of each character in my font and then wrote a function "uint8_t calculateStringWidth(const char* string, const uint8_t* table)".

This iterates through the string and sums up the widths of each character in the string and returns it to the caller. From that you can do calculations based on the size of the string and whatever else (i.e. the screen size, item size, etc.)

I could share this code if it would be of use, but remember, it needs to have a table you create based on the font you are using.

RE:Text in abs middle position

selgus thanks a lot for the reply.

If you could to share this code, I will be happy.

It will be a good start for me, because I am newbie in C++.

I have find another solution for the same, but it is for u8lib code (there is no compatibility with this display).

Copyright Digole Digital Solutions/Digole Technologies Inc., 2008-2026. All rights reserved.
Powered by Digole