Digital Solutions
iDigole Buyer ProtectioniDigole Buyer
My shopping cart
0 Items:
Secure Checkout
Top Rated Plus
Visit Our Live Auctions
99.9% Customer's Satisfaction
Search store:
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, 2008-2021. All rights reserved.
Powered by Victor Sun