Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

Centre()

Mammad900 edited this page Aug 29, 2020 · 1 revision

Centre(Length, wid, Left, CHwid)

Summary

Calculates the X position for aligning a text (or any object) to center.

It is designed for monospace text, but can be used for any object.

Parameters

  1. Length (int) : The number of characters in the text
  2. wid (int) optional: The width of the text container. Default: TFT screen size
  3. Left (int) optional: The X position of the container. Default: 0
  4. CHwid (int) optional: Width of every character. Default: 6 (for NULL font)

Returns

Nothing

Examples

// Only Centre() is in the library's API
object.X = Centre(object.width, object.container.width, object.container.X, 1);

Output

This code aligns an object to center (the object uses another library's API)


Monospace text example

int X = Centre(strlen(str)); // str is a c-string

Source

int Centre(int Length, int wid = AUTO, int Left = 0, int CHwid = 6) {
  if (wid == AUTO)
    wid = tft.width();
  return ((wid / 2) - (Length * CHwid / 2)) + Left;
}
Clone this wiki locally