changeset 481:89f6857276f8 Improve_Button_Sleep

Bugfix calculation of string center position: Strings shown on the right side at surface mode use special characters ('\016' and '\017') to switch font size. Headline strings like "Desaturation" could also be set to the target font directly, because they do not contain mixed font sizes, but nethertheless they are using the special characters. The function calculating the offset needed to display the strinter with center alignment did not consider the small font size => misalignment during string display. To avoid this an evaluation of the special characters has been added to the helper function.
author ideenmodellierer
date Mon, 18 May 2020 21:51:08 +0200
parents 3fe9cc747c5c
children 230aed360da0
files Discovery/Src/gfx_engine.c Discovery/Src/t7.c
diffstat 2 files changed, 30 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/gfx_engine.c	Wed May 13 21:56:35 2020 +0200
+++ b/Discovery/Src/gfx_engine.c	Mon May 18 21:51:08 2020 +0200
@@ -3085,6 +3085,8 @@
 	uint8_t gfx_selected_language;
 	uint32_t pText;
 	uint16_t decodeUTF8;
+	uint8_t tinyState = 0;		/* used to identify the usage of tiny font */
+	tFont* ptargetFont;
 
 #ifndef BOOTLOADER_STANDALONE
 	SSettings *pSettings;
@@ -3102,6 +3104,22 @@
 	j = 0;
 	while (*(char*)pText != 0)// und fehlend: Abfrage window / image size
 	{
+		if(*(char*)pText == '\016')	/* request font change */
+		{
+			tinyState++;
+		}
+		if(*(char*)pText == '\017')	/* request font reset */
+		{
+			tinyState = 0;
+		}
+		if(tinyState > 1)
+		{
+			ptargetFont = (tFont *)cfg->TinyFont;
+		}
+		else
+		{
+			ptargetFont = (tFont *)cfg->font;
+		}
 		if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */
 		{
 			decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */
@@ -3113,20 +3131,20 @@
 			decodeUTF8 = *(char*)pText; /* place ASCII char */
 		}
 
-		for(i=0;i<((tFont *)cfg->font)->length;i++)
+		for(i=0;i<ptargetFont->length;i++)
 		{
-			if(((tFont *)cfg->font)->chars[i].code == decodeUTF8)
+			if(ptargetFont->chars[i].code == decodeUTF8)
 			{
-				Xsum += ((tFont *)cfg->font)->chars[i].image->width;
+				Xsum += ptargetFont->chars[i].image->width;
 				break;
 			}
 		}
 		pText++;
 		j++;
-		if(((tFont *)cfg->font == &FontT144) && (*(char*)pText != 0))
+		if((ptargetFont == &FontT144) && (*(char*)pText != 0))
 			Xsum += 3;
 		else
-		if(((tFont *)cfg->font == &FontT105) && (*(char*)pText != 0))
+		if((ptargetFont == &FontT105) && (*(char*)pText != 0))
 			Xsum += 2;
 	}
 	pText -= j;
--- a/Discovery/Src/t7.c	Wed May 13 21:56:35 2020 +0200
+++ b/Discovery/Src/t7.c	Mon May 18 21:51:08 2020 +0200
@@ -789,16 +789,18 @@
     {
         text[0] = '\001';
         text[1] = '\004';
-        text[2] = TXT_2BYTE;
-        text[3] = TXT2BYTE_Sunday;
-        text[4] = 0;
+        text[2] = '\016';
+        text[3] = '\016';
+        text[4] = TXT_2BYTE;
+        text[5] = TXT2BYTE_Sunday;
+        text[6] = 0;
         if(Sdate.WeekDay != RTC_WEEKDAY_SUNDAY)
-            text[3] += Sdate.WeekDay;
+            text[5] += Sdate.WeekDay;
 
         if(!(Stime.Seconds % 2) && (dateNotSet == 1))
             text[1] = '\021';
 
-        GFX_write_string(&FontT24,&t7surfaceR,text,4);
+        GFX_write_string(&FontT48,&t7surfaceR,text,4);
     }
 
     /* DEBUG uTick Pressure and Compass */