MCPcopy Create free account
hub / github.com/BlueAndi/Pixelix / alignTextHorizontal

Method alignTextHorizontal

lib/YAWidgets/src/TextWidget.cpp:317–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

315 *****************************************************************************/
316
317int16_t TextWidget::alignTextHorizontal(YAGfx& gfx, const String& text, Alignment::Horizontal hAlign) const
318{
319 int16_t xPos = 0;
320
321 /* Horizontal alignment is supported for
322 * - Static text
323 * - Text scrolling from bottom to top
324 */
325 if ((false == m_scrollCtrl.isEnabled()) ||
326 ((true == m_scrollCtrl.isEnabled()) && (ScrollController::DIRECTION_VERTICAL == m_scrollCtrl.getDirection())))
327 {
328 uint16_t textBoxWidth = 0U;
329 uint16_t textBoxHeight = 0U;
330
331 if (true == m_gfxText.getTextBoundingBox(gfx.getWidth(), text.c_str(), textBoxWidth, textBoxHeight))
332 {
333 UTIL_NOT_USED(textBoxHeight);
334
335 switch (hAlign)
336 {
337 case Alignment::Horizontal::HORIZONTAL_LEFT:
338 xPos = 0;
339 break;
340
341 case Alignment::Horizontal::HORIZONTAL_CENTER:
342 xPos = (m_canvas.getWidth() - textBoxWidth) / 2;
343 break;
344
345 case Alignment::Horizontal::HORIZONTAL_RIGHT:
346 xPos = m_canvas.getWidth() - textBoxWidth;
347 break;
348
349 default:
350 break;
351 }
352 }
353 }
354
355 return xPos;
356}
357
358void TextWidget::alignTextVertical()
359{

Callers

nothing calls this directly

Calls 5

getDirectionMethod · 0.80
getTextBoundingBoxMethod · 0.80
c_strMethod · 0.80
isEnabledMethod · 0.45
getWidthMethod · 0.45

Tested by

no test coverage detected