From 8b4ca720369d790ea330bc2189efa05cc557c2f7 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 26 Apr 2014 03:27:19 +0200 Subject: [PATCH] Added gwinListEnableRender() --- demos/modules/gwin/list/main.c | 12 ++++-------- docs/releases.txt | 1 + src/gwin/list.c | 20 ++++++++++++++++++++ src/gwin/list.h | 14 ++++++++++++++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/demos/modules/gwin/list/main.c b/demos/modules/gwin/list/main.c index 36820c23..3811c36f 100644 --- a/demos/modules/gwin/list/main.c +++ b/demos/modules/gwin/list/main.c @@ -52,10 +52,6 @@ static void createWidgets(void) { wi.text = "List 2: Smooth scrolling"; ghLabel1 = gwinLabelCreate(NULL, &wi); - // Make list widgets invisible by default as they would issue - // a re-render at every time an item is added - wi.g.show = FALSE; - // The first list widget wi.g.width = 150; wi.g.height = 100; @@ -112,6 +108,9 @@ int main(void) { gwinListAddItem(ghList1, "Item 13", FALSE); // Add some items to the second list widget + // This time we will disable the render until + // all the items have been added + gwinListEnableRender(ghList2, FALSE); gwinListAddItem(ghList2, "Item 0", FALSE); gwinListAddItem(ghList2, "Item 1", FALSE); gwinListAddItem(ghList2, "Item 2", FALSE); @@ -126,10 +125,7 @@ int main(void) { gwinListAddItem(ghList2, "Item 11", FALSE); gwinListAddItem(ghList2, "Item 12", FALSE); gwinListAddItem(ghList2, "Item 13", FALSE); - - // Make all the lists visible - gwinSetVisible(ghList1, TRUE); - gwinSetVisible(ghList2, TRUE); + gwinListEnableRender(ghList2, TRUE); while(1) { // Get an Event diff --git a/docs/releases.txt b/docs/releases.txt index 95bda6b1..3edfbf4c 100644 --- a/docs/releases.txt +++ b/docs/releases.txt @@ -23,6 +23,7 @@ FEATURE: Added LGDP4532 driver by user shilow FEATURE: Support for ChibiOS/RT 3.x FEATURE: Added gwinProgressbarStop() and gwinProgressbarReset() FEATURE: Added generic ILI93xx driver by xlh1460 +FEATURE: Added gwinListEnableRender() *** changes after 1.9 *** diff --git a/src/gwin/list.c b/src/gwin/list.c index 8374ff39..50c669f0 100644 --- a/src/gwin/list.c +++ b/src/gwin/list.c @@ -41,6 +41,7 @@ #define GLIST_FLG_HASIMAGES (GWIN_FIRST_CONTROL_FLAG << 1) #define GLIST_FLG_SCROLLALWAYS (GWIN_FIRST_CONTROL_FLAG << 2) #define GLIST_FLG_SCROLLSMOOTH (GWIN_FIRST_CONTROL_FLAG << 3) +#define GLIST_FLG_ENABLERENDER (GWIN_FIRST_CONTROL_FLAG << 4) // Flags on a ListItem. #define GLIST_FLG_SELECTED 0x0001 @@ -92,6 +93,11 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { coord_t sy; #endif + // dont render if render has been disabled + if (!(gw->g.flags & GLIST_FLG_ENABLERENDER)) { + return; + } + ps = (gw->g.flags & GWIN_FLG_ENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; x = 1; @@ -401,12 +407,26 @@ GHandle gwinGListCreate(GDisplay *g, GListObject* gobj, GWidgetInit* pInit, bool if (multiselect) gobj->w.g.flags |= GLIST_FLG_MULTISELECT; gobj->w.g.flags |= GLIST_FLG_SCROLLALWAYS; + gobj->w.g.flags |= GLIST_FLG_ENABLERENDER; gwinSetVisible(&gobj->w.g, pInit->g.show); return (GHandle)gobj; } +void gwinListEnableRender(GHandle gh, bool_t ena) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&listVMT) + return; + + if (ena) { + gh->flags |= GLIST_FLG_ENABLERENDER; + gwinRedraw(gh); + } else { + gh->flags &=~ GLIST_FLG_ENABLERENDER; + } +} + void gwinListSetScroll(GHandle gh, scroll_t flag) { // is it a valid handle? if (gh->vmt != (gwinVMT *)&listVMT) diff --git a/src/gwin/list.h b/src/gwin/list.h index eb800439..2cc525a2 100644 --- a/src/gwin/list.h +++ b/src/gwin/list.h @@ -102,6 +102,20 @@ extern "C" { GHandle gwinGListCreate(GDisplay *g, GListObject *widget, GWidgetInit *pInit, bool_t multiselect); #define gwinListCreate(w, pInit, m) gwinGListCreate(GDISP, w, pInit, m) +/** + * @brief Enable or disable the rendering of the list + * + * @details Usually the list is being re-rendered when an item is added to the list. This can cause + * flickering and performance issues when many items are added at once. This can be prevented + * by temporarely disabling the render using this function. + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] ena TRUE or FALSE + * + * @api + */ +void gwinListEnableRender(GHandle gh, bool_t ena); + /** * @brief Change the behaviour of the scroll bar *