widget - swipe list - change background color

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • widget - swipe list - change background color

      Hi !

      I'am intensively using the swipe liste widget.
      I used all the function API to change its apperance : SWIPELIST_SetDefault....
      However I did not manager to change the black background that appears when items list do not fill the screen.
      I tried using WM_SetDesktopColor, WINDOW_SetDefaultBkColor, RAMEWIN_SetDefaultClientColor... but they do not impact the swipe background.
      I thought that the "separator item color" would be used ?

      Thank for any answer.
    • Hi,

      Did you tried the function SWIPELIST_SetBkColor()?

      Which emWin version are you using (can be found in GUI_Version.h)?

      Regards
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Yes we do use this function to impact items colors :

      Source Code

      1. void SWIPELIST_SetBkColor(SWIPELIST_Handle hObj, unsigned Index,
      2. GUI_COLOR Color);


      As documented, it only concerns item colors, the empty area is not concerned and stays black.

      We use st Emwin V5.40 :

      #define GUI_VERSION 54002

      Regards,
      Selso.
    • Hi,

      Can send me the code how you set up the SWIPELIST?

      Also your configuration files can be interesting (LCDConf.c, GUIConf.c/.h).

      Regards
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Hello !

      Here is the part where I setup widget styles :

      Source Code

      1. void ews_setCustomSyle( void )
      2. {
      3. ...
      4. WM_SetDesktopColor(EWS_RGB2EMWIN(EWS_WINBKG_DFT_COLOR));
      5. WINDOW_SetDefaultBkColor(EWS_RGB2EMWIN(EWS_WINBKG_DFT_COLOR));
      6. FRAMEWIN_SetDefaultClientColor(EWS_RGB2EMWIN(EWS_WINBKG_DFT_COLOR));
      7. ...
      8. // Swipelist
      9. SWIPELIST_SetDefaultBkColor(SWIPELIST_CI_BK_ITEM_SEL, EWS_RGB2EMWIN(EWS_SWIPELIST_BKITEM_SEL_COLOR));
      10. SWIPELIST_SetDefaultBkColor(SWIPELIST_CI_BK_ITEM_UNSEL, EWS_RGB2EMWIN(EWS_SWIPELIST_BKITEM_UNSEL_COLOR));
      11. SWIPELIST_SetDefaultBkColor(SWIPELIST_CI_BK_SEP_ITEM, EWS_RGB2EMWIN(EWS_SWIPELIST_BKSEPITEM_COLOR) );
      12. SWIPELIST_SetDefaultSepColor(EWS_SWIPELIST_SEP_COLOR);
      13. SWIPELIST_SetDefaultFont(SWIPELIST_FI_ITEM_HEADER, GUI_FONT_24B_1);
      14. SWIPELIST_SetDefaultFont(SWIPELIST_FI_ITEM_TEXT, GUI_FONT_20B_1);
      15. SWIPELIST_SetDefaultFont(SWIPELIST_FI_SEP_ITEM, GUI_FONT_32B_1);
      16. SWIPELIST_SetDefaultTextColor(SWIPELIST_CI_ITEM_HEADER_UNSEL, EWS_SWIPELIST_TEXT_COLOR);
      17. SWIPELIST_SetDefaultTextColor(SWIPELIST_CI_ITEM_HEADER_SEL, EWS_SWIPELIST_TEXT_COLOR);
      18. SWIPELIST_SetDefaultTextColor(SWIPELIST_CI_ITEM_TEXT_UNSEL, EWS_SWIPELIST_TEXT_COLOR);
      19. SWIPELIST_SetDefaultTextColor(SWIPELIST_CI_ITEM_TEXT_SEL, EWS_SWIPELIST_TEXT_COLOR);
      20. SWIPELIST_SetDefaultTextColor(SWIPELIST_CI_SEP_ITEM_TEXT, EWS_SWIPELIST_TEXT_SEPITEM_COLOR);
      21. ... Skinning of spinbox, buttons, scrollbar, checkbox...
      22. }
      Display All



      In the header file :

      Source Code

      1. /** Macro de conversion pour passer la bonne couleur à l'API emwin
      2. *
      3. */
      4. #define EWS_RGB2EMWIN(col) GUI_MAKE_COLOR(EWS_RGB2BRG(col))
      5. /*=============================================================================
      6. * VARIABLES et CONSTANTES
      7. *===========================================================================*/
      8. /** Couleur par défaut de l'arrière plan des fenêtres
      9. * Il faut utiliser la macro EWS_RGB2EMWIN avec ces définitions
      10. * */
      11. #define EWS_WINBKG_DFT_COLOR 0x00e6eaf1 //0x00BAA9D6
      12. /*=============================================================================
      13. * PROPRIETE GRAPHIQUE DES SWIPELIST
      14. *===========================================================================*/
      15. /** Couleur fond item selectionné */
      16. #define EWS_SWIPELIST_BKITEM_SEL_COLOR 0x0000a0ce //EWS_BUTT_FOCUS_COLOR
      17. /** Couleur fond item non selectionné */
      18. #define EWS_SWIPELIST_BKITEM_UNSEL_COLOR 0x00ffffff //EWS_WINBKG_DFT_COLOR
      19. /** Couleur fond Entête de groupe (ou item séparateur) */
      20. #define EWS_SWIPELIST_BKSEPITEM_COLOR GUI_DARKGRAY
      21. /** Couleur ligne séparation d'items */
      22. #define EWS_SWIPELIST_SEP_COLOR 0x00E6EAF1 //GUI_BLACK
      23. /** Couleur des textes
      24. On applique la même couleur pour tous les textes sauf l'item séparateur
      25. */
      26. #define EWS_SWIPELIST_TEXT_COLOR 0x00293444 //GUI_BLACK
      27. /** Couleur des textes
      28. On applique la même couleur pour tous les textes sauf l'item séparateur
      29. */
      30. #define EWS_SWIPELIST_TEXT_SEPITEM_COLOR GUI_WHITE
      Display All
      Files
      • emwin_conf.7z

        (5.89 kB, downloaded 260 times, last: )
    • I also tried by replacing :

      Source Code

      1. WM_SetDesktopColor(EWS_RGB2EMWIN(EWS_WINBKG_DFT_COLOR));


      At begin of emwin_setStyle :

      Source Code

      1. WM_SetCallback(WM_HBKWIN, _cbBk);
      2. /*********************************************************************
      3. *
      4. * _cbBk
      5. */
      6. static void _cbBk(WM_MESSAGE * pMsg) {
      7. switch (pMsg->MsgId) {
      8. case WM_PAINT:
      9. GUI_SetBkColor(GUI_WHITE);
      10. GUI_Clear();
      11. break;
      12. default:
      13. WM_DefaultProc(pMsg);
      14. break;
      15. }
      16. }
      Display All


      The empty area of swipe list still stays black.
    • Hi,

      It seems you are using a precompiled version of emWin provided by ST.
      Have you made changes to the GUIConf.h (which is not recommended because those defines are compile time switches and might lead to strange behavior if changed later on)?
      Which device are you using?

      According to your GUIConf.h and the version you use the default color management of emWin. This means that emWin calculates internally in this color format and expects colors in this format:

      ABGR - a 32 bit color value where 8 bits for alpha (0 means opaque and 255 fully transparent).

      In your LCDConf.c it looks like you use GUICC_M8888I as color conversion. This means that the output into the framebuffer has the following format:

      ARGB - also 32 bit but alpha inverted (0 means transparent and 255 opaque) and the R and B channels are swapped.

      These two configurations do not really match. This has the disadvantage that emWin has to convert each pixel from ABGR to ARGB which has a big impact on the performance.But, as far as I know ST provides the newer libraries compiled for the second color format. So you should add a GUI_USE_ARGB 1 to your GUIConf.h:

      #define GUI_USE_ARGB 1

      Depending on which format is used in your library you have to take about how the colors are defined.

      According to your code you define your colors like this:
      #define EWS_SWIPELIST_BKITEM_SEL_COLOR 0x0000a0ce //EWS_BUTT_FOCUS_COLOR

      This color would be opaque with values for green and red (ABGR - A=0-> opaque). If the library uses the ARGB format this color would be transparent, which might lead to your problem.

      I recommend to use either GUI_MAKE_COLOR() (it will convert the a color in the ABGR format to the ARGB format) or define the colors directly in the correct format.

      I know this can be a bit hard to understand (and to explain) and tricky to play with, so do not hesitate to ask.
      You might also take a look into the configuration files provided by ST and compare them to yours (this is especially important for compile time switches).

      Regards
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • "It seems you are using a precompiled version of emWin provided by ST.

      I actually link with the precompiled STemWin540_CM4_GCC_ot_ARGB, so I think I am using the ARGB color format.
      There is also the precompiled STemWin540_CM4_GCC_ot (ABRG version I think), would it better to use this version of library ?
      "Have you made changes to the GUIConf.h"


      Yes, because I wanted to make changes easier, and explicitely use sdram attribute instead of setting a pointer to sdram area. ST code deserves somes modifications.
      Also, their code do not rely on stmCube MX Generator.

      "In your LCDConf.c it looks like you use GUICC_M8888I as color
      conversion. This means that the output into the framebuffer has the
      following format:..."


      In LCD_conf.h I set :
      "#define COLOR_CONVERSION_0 GUICC_M565"

      I use this space color in order to reduce memory footprint and data bandwith.
      According to you manual §15.6 I use the right mode for the library :
      GUICC_565 65536 0xFFFF -> BBBBBGGGGGGRRRRR
      GUICC_M565 65536 0xFFFF -> RRRRRGGGGGGBBBBB
      "#define GUI_USE_ARGB 1"

      It is set in GUI_ConfDefaults.h

      "According to your code you define your colors like this:" ....
      I let the user define its color in ARGB format, but then in the call I use a macro that calls GUI_MAKE_COLOR()

      Source Code

      1. #define EWS_RGB2EMWIN(col) GUI_MAKE_COLOR(EWS_RGB2BRG(col))


      But there is something wrong, because GUI_MAKE_COLOR is defined that way in GUI.h :

      Source Code

      1. #if (GUI_USE_ARGB)
      2. #define GUI_MAKE_COLOR(ABGR) (((((U32)ABGR) & 0xFF000000ul) ^ 0xFF000000ul) | ((((U32)ABGR) & 0x00FF0000ul) >> 16) | (((U32)ABGR) & 0x0000FF00ul) | ((((U32)ABGR) & 0x000000FFul) << 16))
      3. #define GUI_MAKE_TRANS(Alpha) (255 - (Alpha))
      4. #else
      5. #define GUI_MAKE_COLOR(ABGR) (ABGR)
      6. #define GUI_MAKE_TRANS(Alpha) (Alpha)
      7. #endif


      Si it expects that I am provinding ABRG color when in fact I was providing ARGB format, thats why I also convert to ABRG color before passing to this macro (and invert the Alpha)
      GUI_MAKE_COLOR should be called ABRG_TO_ARGB() and be used only if necessary : I shall remove it because I use ARB definitions.

      Anyway I used various color when trying to set swipe list empty area, and it still stays black.
    • To be sur....

      I have setup the x86 simulation and used the WIDGET_SwipeList.
      I've just changer screen size to 480x640 in order to be sure that the swipe list do not fille the screen area.
      then I try to fill the swipe list empty area in RED, and can't do it.
      should I define some processing in the WM_PAINT message ?
      Files

      The post was edited 1 time, last by Selso ().

    • Hi,

      Please try the example below. Does it work on your side?

      C Source Code

      1. #include "DIALOG.h"
      2. #include <stdio.h>
      3. /*********************************************************************
      4. *
      5. * Externals
      6. *
      7. **********************************************************************
      8. */
      9. /*********************************************************************
      10. *
      11. * Defines
      12. *
      13. **********************************************************************
      14. */
      15. /*********************************************************************
      16. *
      17. * Static data
      18. *
      19. **********************************************************************
      20. */
      21. /*********************************************************************
      22. *
      23. * Static code
      24. *
      25. **********************************************************************
      26. */
      27. /*********************************************************************
      28. *
      29. * _cbBk
      30. */
      31. static void _cbBk(WM_MESSAGE * pMsg) {
      32. switch (pMsg->MsgId) {
      33. case WM_PAINT:
      34. GUI_SetBkColor(GUI_BLACK);
      35. GUI_Clear();
      36. break;
      37. default:
      38. WM_DefaultProc(pMsg);
      39. break;
      40. }
      41. }
      42. /*********************************************************************
      43. *
      44. * Public code
      45. *
      46. **********************************************************************
      47. */
      48. /*********************************************************************
      49. *
      50. * MainTask
      51. */
      52. void MainTask(void) {
      53. WM_HWIN hSwipe;
      54. char acBuffer[32];
      55. int i;
      56. GUI_COLOR aColor[] = { GUI_RED, GUI_GREEN, GUI_BLUE };
      57. int Index;
      58. GUI_Init();
      59. WM_SetCallback(WM_HBKWIN, _cbBk);
      60. hSwipe = SWIPELIST_CreateEx(10, 10, 120, 200, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_SWIPELIST0);
      61. for (i = 0; i < 20; i++) {
      62. sprintf(acBuffer, "Item %i", i);
      63. SWIPELIST_AddItem(hSwipe, acBuffer, 30);
      64. }
      65. Index = 0;
      66. SWIPELIST_SetBkColor(hSwipe, SWIPELIST_CI_BK_ITEM_UNSEL, aColor[Index++]);
      67. while (1) {
      68. Index = (Index == GUI_COUNTOF(aColor)) ? 0 : Index;
      69. GUI_Delay(1000);
      70. SWIPELIST_SetBkColor(hSwipe, SWIPELIST_CI_BK_ITEM_UNSEL, aColor[Index++]);
      71. }
      72. }
      73. /*************************** End of file ****************************/
      Display All


      I've just changer screen size to 480x640 in order to be sure that the swipe list do not fille the screen area.
      But in your last example you create the SWIPELIST with the size of the screen, so it will always fill the complete screen.

      C Source Code

      1. hSwipelist = SWIPELIST_CreateEx(0, 0, GUI_GetScreenSizeX(), GUI_GetScreenSizeY(), WM_HBKWIN, WM_CF_SHOW, 0, 0);

      then I try to fill the swipe list empty area in RED, and can't do it.
      Not sure what you mean with the 'empty area'. The swipelist covers the complete screen. The items are red and the sparators are dark gray.



      Regards
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Hello Sven,

      Thanks for following my post


      [img]http://forum.segger.com/wcf/icon/quoteS.png[/img]
      Quoted




      I've just changer screen size to 480x640 in order to be sure that the swipe list do not fille the screen area.
      But in your last example you create the SWIPELIST with the size of the screen, so it will always fill the complete screen.
      Yes it filling the area, but the item list is not, see my attached capture.
      I 'am checking your suggestion and tell you this result.
      Images
      • 2018-04-05 15_23_23-Target device.png

        32.37 kB, 548×948, viewed 384 times
    • Hello !

      I have tried your code, changing the background in white and resizing the swipe list (see capture).
      This empty area is not the bakcground area. Maybe using a ownerdraw would help ?

      C Source Code

      1. #include "DIALOG.h"
      2. #include <stdio.h>
      3. /*********************************************************************
      4. *
      5. * Externals
      6. *
      7. **********************************************************************
      8. */
      9. /*********************************************************************
      10. *
      11. * Defines
      12. *
      13. **********************************************************************
      14. */
      15. /*********************************************************************
      16. *
      17. * Static data
      18. *
      19. **********************************************************************
      20. */
      21. /*********************************************************************
      22. *
      23. * Static code
      24. *
      25. **********************************************************************
      26. */
      27. /*********************************************************************
      28. *
      29. * _cbBk
      30. */
      31. static void _cbBk(WM_MESSAGE * pMsg) {
      32. switch (pMsg->MsgId) {
      33. case WM_PAINT:
      34. GUI_SetBkColor(GUI_WHITE);
      35. GUI_Clear();
      36. break;
      37. default:
      38. WM_DefaultProc(pMsg);
      39. break;
      40. }
      41. }
      42. /*********************************************************************
      43. *
      44. * Public code
      45. *
      46. **********************************************************************
      47. */
      48. /*********************************************************************
      49. *
      50. * MainTask
      51. */
      52. void MainTask(void) {
      53. WM_HWIN hSwipe;
      54. char acBuffer[32];
      55. int i;
      56. GUI_COLOR aColor[] = { GUI_RED, GUI_GREEN, GUI_BLUE };
      57. int Index;
      58. GUI_Init();
      59. WM_SetCallback(WM_HBKWIN, _cbBk);
      60. hSwipe = SWIPELIST_CreateEx(0, 0, GUI_GetScreenSizeX(), GUI_GetScreenSizeY(), WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_SWIPELIST0);
      61. for (i = 0; i < 20; i++) {
      62. sprintf(acBuffer, "Item %i", i);
      63. SWIPELIST_AddItem(hSwipe, acBuffer, 30);
      64. }
      65. Index = 0;
      66. SWIPELIST_SetBkColor(hSwipe, SWIPELIST_CI_BK_ITEM_UNSEL, aColor[Index++]);
      67. while (1) {
      68. Index = (Index == GUI_COUNTOF(aColor)) ? 0 : Index;
      69. GUI_Delay(1000);
      70. SWIPELIST_SetBkColor(hSwipe, SWIPELIST_CI_BK_ITEM_UNSEL, aColor[Index++]);
      71. }
      72. }
      73. /*************************** End of file ****************************/
      Display All
      Images
      • 2018-04-05 17_06_27-Target device.png

        29.67 kB, 548×948, viewed 399 times
    • Hi,

      Yes a owner function will work. With newer emWin versions it is possible to make the SWIPELIST transparent but with emWin V5.40 it's not.

      Here is an owner draw you can use to clear the area.

      I react on WIDGET_ITEM_DRAW_TEXT because it is the very last operation and I clear the area after drawing the last string.

      Just set this function with SWIPELIST_SetOwnerDraw():

      C Source Code

      1. /*********************************************************************
      2. *
      3. * _OwnerDraw
      4. */
      5. static int _OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
      6. GUI_RECT Rect;
      7. GUI_COLOR Color;
      8. switch (pDrawItemInfo->Cmd) {
      9. case WIDGET_ITEM_DRAW_TEXT:
      10. //
      11. // Call default owner draw to draw the text
      12. //
      13. SWIPELIST_OwnerDraw(pDrawItemInfo);
      14. //
      15. // The last item to be drawn
      16. //
      17. if (pDrawItemInfo->ItemIndex == SWIPELIST_GetNumItems(pDrawItemInfo->hWin) - 1) {
      18. //
      19. // Set a bk color
      20. //
      21. GUI_SetBkColor(SLI_COLOR);
      22. //
      23. // set up a rectangle to be cleared
      24. //
      25. Rect.x0 = WM_GetWindowOrgX(pDrawItemInfo->hWin);
      26. Rect.y0 = pDrawItemInfo->y1;
      27. Rect.x1 = WM_GetWindowSizeX(pDrawItemInfo->hWin);
      28. Rect.y1 = LCD_GetYSize();
      29. //
      30. // Set a user clip rect, otherwise nothing would be drawn due to clipping
      31. //
      32. WM_SetUserClipRect(&Rect);
      33. //
      34. // Clear the rectangle
      35. //
      36. GUI_ClearRectEx(&Rect);
      37. //
      38. // Restore clip rect
      39. //
      40. WM_SetUserClipRect(NULL);
      41. }
      42. return 0;
      43. default:
      44. return SWIPELIST_OwnerDraw(pDrawItemInfo);
      45. }
      46. }
      Display All


      Regards
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Hello Sven !

      Thanks for this reply, so I can already return a response about this features.
      I tested your example it is actually filling the empty zone, still there is some artefact when I don't use the item background, see capture attached...
      Its is as if the item does not fill the area between separators.
      OK I checked the manual and it defines top and bottom border by default (5 pix).
      Right, I think that the subject is resolved.
      Thank you.
      Images
      • 2018-04-06 11_48_09-Target device.png

        31.4 kB, 548×948, viewed 381 times