How to center a text?
-
Hello everyone,
Quiz, I have a question, how can I do to center my text on the screen.My code:void Display_WiFi_Connected() {
M5.Lcd.clear(BLACK);
M5.Lcd.setTextSize(2);
M5.Lcd.print("M5Stack has been connected");
}I know I can use the function M5.Lcd.setCursor(); but I would like it to center my text according to its size ????
Thanks -
use:
setTextDatum(uint8_t datum);https://github.com/m5stack/M5Stack/blob/master/src/utility/In_eSPI.h#L554
and available options:
https://github.com/m5stack/M5Stack/blob/master/src/utility/In_eSPI.h#L331 -
Thank you so much, I did'nt see this function
But where should I put the function in my code?void Display_WiFi_Connected() {
M5.Lcd.clear(BLACK);
M5.Lcd.setTextSize(2);
M5.Lcd.print("M5Stack has been connected");
} -
@pĆ©pĆ©max åØ How to center a text? äøčÆ“ļ¼
Hello everyone,
Quiz, I have a question, how can I do to center my text on the screen.My code:void Display_WiFi_Connected() {
M5.Lcd.clear(BLACK);
M5.Lcd.setTextSize(2);
M5.Lcd.print("M5Stack has been connected");
}I know I can use the function M5.Lcd.setCursor(); but I would like it to center my text according to its size ????
ThanksTry this:
M5.Lcd.drawCentreString("your string", x, y, font);
So your code should be:
M5.Lcd.drawCentreString("M5Stack has been connected", 160, 120, 2);
to write a string size 2 on the center of the screen.
You also have the option to write a right aligned string.
I love reading C++ headers :)
-
For safe use in the future, better way is:
void Display_WiFi_Connected() { M5.Lcd.clear(BLACK); M5.Lcd.setTextDatum(CC_DATUM); M5.Lcd.drawString("M5Stack has been connected", 160, 120, 2); }because drawCentreString is marked as deprecated
-
-
what is your screen orientation? landscape or portrait ??
where is your text?
try to swap values 160 with 120 for portrait mode
or use this instead:M5.Lcd.drawString("M5Stack has been connected", (int)(M5.Lcd.width()/2), (int)(M5.Lcd.height()/2), 2);which calculates values for current orientation.
I do not have hw for tests
-
Excuse me but it's my fault
-
but it's working or not?
-
Yes yes it's working
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better š
Register Login