Skip to content

Instantly share code, notes, and snippets.

@rozek
Last active December 6, 2019 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rozek/0066b055749b14d680b5a67033b9a0d7 to your computer and use it in GitHub Desktop.
Save rozek/0066b055749b14d680b5a67033b9a0d7 to your computer and use it in GitHub Desktop.
Bangle.js: lists the names of all built in fonts
const CharsPerLine = 60;
const LineHeight = 10;
let yPosition;
/**** clear ****/
function clear () {
Bangle.setLCDMode(); // use normal display mode
g.clear();
g.setFont("4x6");
yPosition = 0;
}
/**** println ****/
function println () {
let StringToDraw = '';
for (let i = 0, l = arguments.length; i < l; i++) {
StringToDraw += arguments[i]; // implicitly also does "toString"
}
g.drawString(StringToDraw, 0,yPosition);
yPosition += LineHeight;
}
/**** list all built-in fonts ****/
clear();
println('List of built-in fonts');
let FontList = g.getFonts();
switch (true) {
case (FontList.length === 0):
println();
println('no built-in fonts found');
break;
case (FontList.length <= 23):
for (let i = 0, l = FontList.length; i < l; i++) {
println(' - "' + FontList[i] + '"');
}
break;
default:
let StringToDraw = '';
for (let i = 0, l = FontList.length; i < l; i++) {
let FontName = ' "' + FontList[i] + '"';
if (i < l-1) { FontName += ',' }
if (StringToDraw.length + FontName.length > 60) {
println(StringToDraw);
StringToDraw = FontName;
} else {
StringToDraw += FontName;
}
}
println(StringToDraw);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment