From 536da24a10e9d2e961fc2d2b73c372997452e752 Mon Sep 17 00:00:00 2001 From: Gabriele Monaco Date: Tue, 22 Aug 2023 17:56:02 +0200 Subject: [PATCH] Added card's colour in the card's page --- apps/cards/app.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/cards/app.js b/apps/cards/app.js index 3a2635e69..691baf987 100644 --- a/apps/cards/app.js +++ b/apps/cards/app.js @@ -50,6 +50,17 @@ function formatDay(date) { } } +function getColor(intColor) { + return "#"+(0x1000000+Number(intColor)).toString(16).padStart(6,"0"); +} +function isLight(color) { + var r = +("0x"+color.slice(1,3)); + var g = +("0x"+color.slice(3,5)); + var b = +("0x"+color.slice(5,7)); + var threshold = 0x88 * 3; + return (r+g+b) > threshold; +} + function printSquareCode(binary, size) { var padding = 5; var ratio = (g.getWidth()-(2*padding))/size; @@ -79,7 +90,6 @@ function printLinearCode(binary) { } function showCode(card) { - //FIXME tap doesn't work.. var listener = (data) => { if(data.double) showCard(card); Bangle.removeListener("tap", listener); @@ -140,14 +150,18 @@ function showCard(card) { if(card.note && card.note.trim()) lines = lines.concat("",g.wrapString(card.note, g.getWidth()-10)); lines = lines.concat("",/*LANG*/"< Back"); + var titleBgColor = card.color ? getColor(card.color) : g.theme.bg2; + var titleColor = g.theme.fg2; + if (card.color) + titleColor = isLight(titleBgColor) ? BLACK : WHITE; E.showScroller({ h : g.getFontHeight(), // height of each menu item in pixels c : lines.length, // number of menu items // a function to draw a menu item draw : function(idx, r) { // FIXME: in 2v13 onwards, clearRect(r) will work fine. There's a bug in 2v12 - g.setBgColor(idx