<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to center a text?]]></title><description><![CDATA[<p dir="auto">Hello everyone,<br />
Quiz, I have a question, how can I do to center my text on the screen.</p>
<p dir="auto">My code:void Display_WiFi_Connected() {<br />
M5.Lcd.clear(BLACK);<br />
M5.Lcd.setTextSize(2);<br />
M5.Lcd.print("M5Stack has been connected");<br />
}</p>
<p dir="auto">I know I can use the function M5.Lcd.setCursor(); but I would like it to center my text according to its size ????<br />
Thanks</p>
]]></description><link>https://community.m5stack.com/topic/246/how-to-center-a-text</link><generator>RSS for Node</generator><lastBuildDate>Tue, 17 Mar 2026 03:54:17 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/246.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 Jun 2018 07:48:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to center a text? on Mon, 02 Jul 2018 08:01:19 GMT]]></title><description><![CDATA[<p dir="auto">Yes yes it's working</p>
]]></description><link>https://community.m5stack.com/post/1222</link><guid isPermaLink="true">https://community.m5stack.com/post/1222</guid><dc:creator><![CDATA[PépéMax]]></dc:creator><pubDate>Mon, 02 Jul 2018 08:01:19 GMT</pubDate></item><item><title><![CDATA[Reply to How to center a text? on Fri, 29 Jun 2018 20:25:02 GMT]]></title><description><![CDATA[<p dir="auto">but it's working or not?</p>
]]></description><link>https://community.m5stack.com/post/1218</link><guid isPermaLink="true">https://community.m5stack.com/post/1218</guid><dc:creator><![CDATA[reaper7]]></dc:creator><pubDate>Fri, 29 Jun 2018 20:25:02 GMT</pubDate></item><item><title><![CDATA[Reply to How to center a text? on Thu, 28 Jun 2018 12:37:45 GMT]]></title><description><![CDATA[<p dir="auto">Excuse me but it's my fault</p>
]]></description><link>https://community.m5stack.com/post/1204</link><guid isPermaLink="true">https://community.m5stack.com/post/1204</guid><dc:creator><![CDATA[PépéMax]]></dc:creator><pubDate>Thu, 28 Jun 2018 12:37:45 GMT</pubDate></item><item><title><![CDATA[Reply to How to center a text? on Thu, 28 Jun 2018 11:07:07 GMT]]></title><description><![CDATA[<p dir="auto">what is your screen orientation? landscape or portrait ??<br />
where is your text?<br />
try to swap values 160 with 120 for portrait mode<br />
or use this instead:</p>
<pre><code>M5.Lcd.drawString("M5Stack has been connected", (int)(M5.Lcd.width()/2), (int)(M5.Lcd.height()/2), 2);
</code></pre>
<p dir="auto">which calculates values for current orientation.</p>
<p dir="auto">I do not have hw for tests</p>
]]></description><link>https://community.m5stack.com/post/1203</link><guid isPermaLink="true">https://community.m5stack.com/post/1203</guid><dc:creator><![CDATA[reaper7]]></dc:creator><pubDate>Thu, 28 Jun 2018 11:07:07 GMT</pubDate></item><item><title><![CDATA[Reply to How to center a text? on Thu, 28 Jun 2018 07:46:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/160">@reaper7</a>  <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/269">@Calin</a> Thanks mens<br />
but my text was not center in my display</p>
<pre><code class="language-c++">M5.Lcd.drawString("M5Stack has been connected", 160, 120, 2);
</code></pre>
<p dir="auto">I think it's because of 160 and 120 values.<br />
I would like my text to be centered in height and width.</p>
]]></description><link>https://community.m5stack.com/post/1202</link><guid isPermaLink="true">https://community.m5stack.com/post/1202</guid><dc:creator><![CDATA[PépéMax]]></dc:creator><pubDate>Thu, 28 Jun 2018 07:46:44 GMT</pubDate></item><item><title><![CDATA[Reply to How to center a text? on Thu, 28 Jun 2018 05:13:53 GMT]]></title><description><![CDATA[<p dir="auto">For safe use in the future, better way is:</p>
<pre><code>void Display_WiFi_Connected() {
  M5.Lcd.clear(BLACK);
  M5.Lcd.setTextDatum(CC_DATUM);
  M5.Lcd.drawString("M5Stack has been connected", 160, 120, 2);
}
</code></pre>
<p dir="auto">because <em>drawCentreString</em> is marked as deprecated</p>
]]></description><link>https://community.m5stack.com/post/1201</link><guid isPermaLink="true">https://community.m5stack.com/post/1201</guid><dc:creator><![CDATA[reaper7]]></dc:creator><pubDate>Thu, 28 Jun 2018 05:13:53 GMT</pubDate></item><item><title><![CDATA[Reply to How to center a text? on Wed, 27 Jun 2018 16:11:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/429">@pépémax</a> 在 <a href="/post/1186">How to center a text?</a> 中说：</p>
<blockquote>
<p dir="auto">Hello everyone,<br />
Quiz, I have a question, how can I do to center my text on the screen.</p>
<p dir="auto">My code:void Display_WiFi_Connected() {<br />
M5.Lcd.clear(BLACK);<br />
M5.Lcd.setTextSize(2);<br />
M5.Lcd.print("M5Stack has been connected");<br />
}</p>
<p dir="auto">I know I can use the function M5.Lcd.setCursor(); but I would like it to center my text according to its size ????<br />
Thanks</p>
</blockquote>
<p dir="auto">Try this:</p>
<p dir="auto">M5.Lcd.drawCentreString("your string", x, y, font);</p>
<p dir="auto">So your code should be:</p>
<blockquote>
<p dir="auto">M5.Lcd.drawCentreString("M5Stack has been connected", 160, 120, 2);</p>
</blockquote>
<p dir="auto">to write a string size 2 on the center of the screen.</p>
<p dir="auto">You also have the option to write a right aligned string.</p>
<p dir="auto">I love reading C++ headers  :)</p>
]]></description><link>https://community.m5stack.com/post/1189</link><guid isPermaLink="true">https://community.m5stack.com/post/1189</guid><dc:creator><![CDATA[Calin]]></dc:creator><pubDate>Wed, 27 Jun 2018 16:11:07 GMT</pubDate></item><item><title><![CDATA[Reply to How to center a text? on Wed, 27 Jun 2018 09:33:16 GMT]]></title><description><![CDATA[<p dir="auto">Thank you so much,  I did'nt see this function<br />
But where should I put the function in my code?</p>
<p dir="auto">void Display_WiFi_Connected() {<br />
M5.Lcd.clear(BLACK);<br />
M5.Lcd.setTextSize(2);<br />
M5.Lcd.print("M5Stack has been connected");<br />
}</p>
]]></description><link>https://community.m5stack.com/post/1188</link><guid isPermaLink="true">https://community.m5stack.com/post/1188</guid><dc:creator><![CDATA[PépéMax]]></dc:creator><pubDate>Wed, 27 Jun 2018 09:33:16 GMT</pubDate></item><item><title><![CDATA[Reply to How to center a text? on Wed, 27 Jun 2018 09:17:21 GMT]]></title><description><![CDATA[<p dir="auto">use:<br />
<code>setTextDatum(uint8_t datum);</code></p>
<p dir="auto"><a href="https://github.com/m5stack/M5Stack/blob/master/src/utility/In_eSPI.h#L554" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/m5stack/M5Stack/blob/master/src/utility/In_eSPI.h#L554</a></p>
<p dir="auto">and available options:<br />
<a href="https://github.com/m5stack/M5Stack/blob/master/src/utility/In_eSPI.h#L331" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/m5stack/M5Stack/blob/master/src/utility/In_eSPI.h#L331</a></p>
]]></description><link>https://community.m5stack.com/post/1187</link><guid isPermaLink="true">https://community.m5stack.com/post/1187</guid><dc:creator><![CDATA[reaper7]]></dc:creator><pubDate>Wed, 27 Jun 2018 09:17:21 GMT</pubDate></item></channel></rss>