MCPcopy Create free account
hub / github.com/ajatkj/scriptable / placeDataElement

Function placeDataElement

LSWeather.js:616–646  ·  view source on GitHub ↗
(imgCanvas, rect, e, suffix, prefix, prefixColor, align, fontName, overrideColor, x,y,w,h, bold)

Source from the content-addressed store, hash-verified

614FUNCTION placeDataElement
615------------------------------------------------------------------*/
616async function placeDataElement(imgCanvas, rect, e, suffix, prefix, prefixColor, align, fontName, overrideColor, x,y,w,h, bold){
617 let element0 = e.slice(0, 1).toUpperCase() + e.slice(1, e.length) // Capitalize first letter of the data
618 if ( suffix !== null) {
619 element0 = element0 + suffix
620 }
621 // Prefix can be a text value or SFSymbol
622 if (prefix !== null) {
623 if (typeof prefix == 'object') { // if prefix is an image i.e. SFSymbol
624 const prefix0 = await prefixImage(prefix, element0, fontName, prefixColor, overrideColor, w, h, bold);
625 let newX;
626 const newY = y;
627 const newH = h;
628 let newW = prefix0.size.width;
629 if (newW > w) newW = w;
630 if (align == 'right'){
631 newX = x + w - newW;
632 } else if (align == 'left') {
633 newX = x
634 } else {
635 newX = x + (w/2) - (newW/2)
636 }
637 rect = new Rect(newX, newY, newW, newH);
638 imgCanvas.drawImageInRect(prefix0, rect);
639 return imgCanvas;
640 } else {
641 element0 = prefix + element0;
642 }
643 }
644 imgCanvas.drawTextInRect(element0,rect);
645 return imgCanvas;
646}
647/*------------------------------------------------------------------
648FUNCTION prefixImage
649------------------------------------------------------------------*/

Callers 1

createOverlayFunction · 0.85

Calls 1

prefixImageFunction · 0.85

Tested by

no test coverage detected