This repository has been archived by the owner on Dec 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Centre()
Mammad900 edited this page Aug 29, 2020
·
1 revision
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.
- Length (
int
) : The number of characters in the text - wid (
int
) optional: The width of the text container. Default: TFT screen size - Left (
int
) optional: The X position of the container. Default: 0 - CHwid (
int
) optional: Width of every character. Default: 6 (forNULL
font)
Nothing
// Only Centre() is in the library's API
object.X = Centre(object.width, object.container.width, object.container.X, 1);
This code aligns an object to center (the object uses another library's API)
int X = Centre(strlen(str)); // str is a c-string
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;
}