From 5a5461e68fd60001d3807d8cd58d184290de2800 Mon Sep 17 00:00:00 2001 From: Dirk-Willem van Gulik Date: Sat, 5 Feb 2022 11:26:26 +0100 Subject: [PATCH 1/4] Use the address of the item rather than copying it (and subsequently limiting its length). As it is fairly common for list items to be lengthy strings. Removes the need for a constant (note that the boilerplate still does a copy up to MAX_STR in the users code). --- src/elem/XListbox.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/elem/XListbox.c b/src/elem/XListbox.c index c84704d0f..aa1b5bf6f 100644 --- a/src/elem/XListbox.c +++ b/src/elem/XListbox.c @@ -65,10 +65,6 @@ extern const char GSLC_PMEM ERRSTR_PXD_NULL[]; // ---------------------------------------------------------------------------- -// TODO: Combine with GUIslice MAX_STR -// Defines the maximum length of a listbox item -#define XLISTBOX_MAX_STR 20 - // ============================================================================ // Extended Element: Listbox // - A Listbox control @@ -620,7 +616,7 @@ bool gslc_ElemXListboxDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw // Determine top-left coordinate of list matrix nItemBaseX = nX0 + pListbox->nMarginW; nItemBaseY = nY0 + pListbox->nMarginH; - char acStr[XLISTBOX_MAX_STR+1] = ""; + char * acStr = (char *)""; // Loop through the items in the list @@ -645,8 +641,7 @@ bool gslc_ElemXListboxDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw } // Fetch the list item - bool bOk = gslc_ElemXListboxGetItem(pGui, pElemRef, nItemInd, acStr, XLISTBOX_MAX_STR); - if (!bOk) { + if (NULL == (acStr = gslc_ElemXListboxGetItemAddr(pListbox, nItemInd))) { // TODO: Erorr handling break; } From bbf4dc452057ada8ba608b0998f7b6f61552b289 Mon Sep 17 00:00:00 2001 From: Dirk-Willem van Gulik Date: Sat, 5 Feb 2022 11:27:42 +0100 Subject: [PATCH 2/4] Follow style used elesewhere, fixes #434 --- src/elem/XListbox.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/elem/XListbox.c b/src/elem/XListbox.c index aa1b5bf6f..1009a0a52 100644 --- a/src/elem/XListbox.c +++ b/src/elem/XListbox.c @@ -618,7 +618,6 @@ bool gslc_ElemXListboxDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw nItemBaseY = nY0 + pListbox->nMarginH; char * acStr = (char *)""; - // Loop through the items in the list int16_t nItemTop = pListbox->nItemTop; int16_t nItemCnt = pListbox->nItemCnt; @@ -641,7 +640,8 @@ bool gslc_ElemXListboxDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw } // Fetch the list item - if (NULL == (acStr = gslc_ElemXListboxGetItemAddr(pListbox, nItemInd))) { + acStr = gslc_ElemXListboxGetItemAddr(pListbox, nItemInd); + if (NULL == acStr) { // TODO: Erorr handling break; } From 798bedbcb704b51beb176a8333cc4569aaa5b4be Mon Sep 17 00:00:00 2001 From: Dirk-Willem van Gulik Date: Sat, 5 Feb 2022 13:27:50 +0100 Subject: [PATCH 3/4] Pragmatic solution to at least give the keypad as much room as we can when the right/bottom part is off screen. --- src/elem/XKeyPad.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/elem/XKeyPad.c b/src/elem/XKeyPad.c index 8264575e1..2ab9786c8 100644 --- a/src/elem/XKeyPad.c +++ b/src/elem/XKeyPad.c @@ -321,6 +321,15 @@ gslc_tsElemRef* gslc_XKeyPadCreateBase(gslc_tsGui* pGui, int16_t nElemId, int16_ rElem.w = (nButtonSzW * pConfig->nMaxCols) + (2 * pConfig->nFrameMargin); rElem.h = (nButtonSzH * pConfig->nMaxRows) + (2 * pConfig->nFrameMargin); + // Things tend to drop off on very small screens + // Move it as far left/up as it goes. And ignore + // the issue if it is still too large. + // + if (rElem.x + rElem.w > pGui->DispW) + rElem.x = pGui->DispW - rElem.w; + if (rElem.y + rElem.h > pGui->DispH) + rElem.y = pGui->DispH - rElem.h; + gslc_tsElem sElem; gslc_tsElemRef* pElemRef = NULL; From f1909569146509a81959a338433ac2314a50d129 Mon Sep 17 00:00:00 2001 From: Dirk-Willem van Gulik Date: Sat, 5 Feb 2022 13:35:42 +0100 Subject: [PATCH 4/4] Fix rotate issue too. fixes #436 --- src/elem/XKeyPad.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/elem/XKeyPad.c b/src/elem/XKeyPad.c index 2ab9786c8..46dc3373b 100644 --- a/src/elem/XKeyPad.c +++ b/src/elem/XKeyPad.c @@ -325,10 +325,10 @@ gslc_tsElemRef* gslc_XKeyPadCreateBase(gslc_tsGui* pGui, int16_t nElemId, int16_ // Move it as far left/up as it goes. And ignore // the issue if it is still too large. // - if (rElem.x + rElem.w > pGui->DispW) - rElem.x = pGui->DispW - rElem.w; - if (rElem.y + rElem.h > pGui->DispH) - rElem.y = pGui->DispH - rElem.h; + if (rElem.x + rElem.w > pGui->nDispW) + rElem.x = pGui->nDispW - rElem.w; + if (rElem.y + rElem.h > pGui->nDispH) + rElem.y = pGui->nDispH - rElem.h; gslc_tsElem sElem; gslc_tsElemRef* pElemRef = NULL; @@ -358,8 +358,8 @@ gslc_tsElemRef* gslc_XKeyPadCreateBase(gslc_tsGui* pGui, int16_t nElemId, int16_ // Determine offset coordinate of compound element so that we can // specify relative positioning during the sub-element Create() operations. - int16_t nOffsetX = nX0 + pConfig->nFrameMargin; - int16_t nOffsetY = nY0 + pConfig->nFrameMargin; + int16_t nOffsetX = rElem.x + pConfig->nFrameMargin; + int16_t nOffsetY = rElem.y + pConfig->nFrameMargin; // Reset buffer and associated state gslc_ElemXKeyPadReset(pXData);