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/2] 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/2] 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; }