messagesoverlay - Dynamically choose title font

master
Martin Boonk 2024-04-06 21:54:07 +02:00
parent ca124e4090
commit abe6160396
1 changed files with 27 additions and 16 deletions

View File

@ -26,8 +26,7 @@ let settings = Object.assign(
settings = Object.assign({ settings = Object.assign({
fontSmall:"6x8", fontSmall:"6x8",
fontMedium:"6x15", fontMedium:"6x15",
fontBig: "12x20", fontBig: "12x20"
fontLarge:"Vector:30"
}, settings); }, settings);
const ovrx = settings.border; const ovrx = settings.border;
@ -35,7 +34,7 @@ const ovry = ovrx;
const ovrw = g.getWidth()-2*ovrx; const ovrw = g.getWidth()-2*ovrx;
const ovrh = g.getHeight()-2*ovry; const ovrh = g.getHeight()-2*ovry;
const LOG=()=>{}; let LOG=()=>{};
//LOG = function() { print.apply(null, arguments);}; //LOG = function() { print.apply(null, arguments);};
const isQuiet = function(){ const isQuiet = function(){
@ -94,7 +93,7 @@ const manageEvent = function(ovr, event) {
if (!callInProgress && eventQueue[0] !== undefined && eventQueue[0].id == event.id) if (!callInProgress && eventQueue[0] !== undefined && eventQueue[0].id == event.id)
next(ovr); next(ovr);
else else
eventQueue = []; eventQueue = [];
break; break;
@ -137,7 +136,7 @@ const drawScreen = function(ovr, title, src, iconcolor, icon){
const w = ovr.getWidth() - 35 - 26; const w = ovr.getWidth() - 35 - 26;
if (title) if (title)
drawTitle(title, textCenter, w, divider, 1); drawTitle(title, textCenter, w, 8, divider - 8, 0);
if (src) if (src)
drawSource(src, textCenter, w, 2, -1); drawSource(src, textCenter, w, 2, -1);
@ -165,19 +164,31 @@ const drawSource = function(src, center, w, y, align) {
ovr.drawString(src, center, y); ovr.drawString(src, center, y);
}; };
const drawTitle = function(title, center, w, y, align) { const drawTitle = function(title, center, w, y, h) {
let titleFont = settings.fontLarge, let size = 30;
lines;
if (ovr.setFont(titleFont).stringWidth(title) > w) while (ovr.setFont("Vector:" + size).stringWidth(title) > w){
titleFont = settings.fontMedium; size -= 2;
if (ovr.setFont(titleFont).stringWidth(title) > w) { if (size < 14){
lines = ovr.wrapString(title, w); ovr.setFont(settings.fontMedium);
title = (lines.length > 2) ? lines.slice(0, 2).join("\n") + "..." : lines.join("\n"); break;
}
} }
ovr.setFontAlign(0,align); if (ovr.stringWidth(title) > w) {
ovr.setFont(titleFont); let ws = ovr.wrapString(title, w);
ovr.drawString(title, center, y+2); if (ws.length >= 2 && ovr.stringWidth(ws[1]) > w - 8){
ws[1] = ws[1].substring(0, ws[1].length - 2);
ws[1] += "...";
}
title = ws.slice(0, 2).join("\n");
ovr.setFontAlign(0,-1);
ovr.drawString(title, center, y + 2);
} else {
ovr.setFontAlign(0,0);
ovr.drawString(title, center, y + h/2);
}
}; };
const showMessage = function(ovr, msg) { const showMessage = function(ovr, msg) {