Thursday, April 26th 2018, 9:46am UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

1

Friday, March 30th 2018, 11:23am

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.

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 562

2

Tuesday, April 3rd 2018, 4:32pm

Hi,

Did you tried the function SWIPELIST_SetBkColor()?

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

Regards
Sven

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

3

Tuesday, April 3rd 2018, 6:08pm

Yes we do use this function to impact items colors :

Source code

1
2
void SWIPELIST_SetBkColor(SWIPELIST_Handle hObj, unsigned Index,
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.

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 562

4

Wednesday, April 4th 2018, 8:52am

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

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

5

Wednesday, April 4th 2018, 9:58am

Hello !

Here is the part where I setup widget styles :

Source code

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



In the header file :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/** Macro de conversion pour passer la bonne couleur à l'API emwin
 *
 */
#define EWS_RGB2EMWIN(col) GUI_MAKE_COLOR(EWS_RGB2BRG(col))

/*=============================================================================
 *							VARIABLES et CONSTANTES
 *===========================================================================*/



/** Couleur par défaut de l'arrière plan des fenêtres
 * Il faut utiliser la macro EWS_RGB2EMWIN avec ces définitions
 * */
#define EWS_WINBKG_DFT_COLOR 0x00e6eaf1 //0x00BAA9D6

/*=============================================================================
 *							PROPRIETE GRAPHIQUE DES SWIPELIST
 *===========================================================================*/

/** Couleur fond item selectionné */
#define EWS_SWIPELIST_BKITEM_SEL_COLOR 	0x0000a0ce //EWS_BUTT_FOCUS_COLOR
/** Couleur fond item non selectionné */
#define EWS_SWIPELIST_BKITEM_UNSEL_COLOR   0x00ffffff //EWS_WINBKG_DFT_COLOR
/** Couleur fond Entête de groupe (ou item séparateur) */
#define EWS_SWIPELIST_BKSEPITEM_COLOR  	GUI_DARKGRAY
/** Couleur ligne séparation d'items */
#define EWS_SWIPELIST_SEP_COLOR         	0x00E6EAF1 //GUI_BLACK
/** Couleur des textes
	On applique la même couleur pour tous les textes sauf l'item séparateur
*/
#define EWS_SWIPELIST_TEXT_COLOR 			0x00293444 //GUI_BLACK

/** Couleur des textes
	On applique la même couleur pour tous les textes sauf l'item séparateur
*/
#define EWS_SWIPELIST_TEXT_SEPITEM_COLOR GUI_WHITE
Selso has attached the following file:
  • emwin_conf.7z (5.89 kB - 28 times downloaded - Last download: Apr 24th 2018, 3:02am)

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

6

Wednesday, April 4th 2018, 10:16am

I also tried by replacing :

Source code

1
WM_SetDesktopColor(EWS_RGB2EMWIN(EWS_WINBKG_DFT_COLOR));


At begin of emwin_setStyle :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
WM_SetCallback(WM_HBKWIN, _cbBk);

/*********************************************************************
*
*   	_cbBk
*/
static void _cbBk(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  case WM_PAINT:
	GUI_SetBkColor(GUI_WHITE);
	GUI_Clear();
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}


The empty area of swipe list still stays black.

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 562

7

Wednesday, April 4th 2018, 10:45am

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

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

8

Wednesday, April 4th 2018, 12:10pm

Quoted

"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 ?

Quoted

"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.

Quoted

"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

Quoted

"#define GUI_USE_ARGB 1"

It is set in GUI_ConfDefaults.h

Quoted

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

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

9

Wednesday, April 4th 2018, 2:59pm

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 ?
Selso has attached the following file:

This post has been edited 1 times, last edit by "Selso" (Apr 4th 2018, 3:04pm)


SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 562

10

Thursday, April 5th 2018, 9:33am

Hi,

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

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "DIALOG.h"
#include <stdio.h>

/*********************************************************************
*
*   	Externals
*
**********************************************************************
*/

/*********************************************************************
*
*   	Defines
*
**********************************************************************
*/

/*********************************************************************
*
*   	Static data
*
**********************************************************************
*/

/*********************************************************************
*
*   	Static code
*
**********************************************************************
*/
/*********************************************************************
*
*   	_cbBk
*/
static void _cbBk(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  case WM_PAINT:
	GUI_SetBkColor(GUI_BLACK);
	GUI_Clear();
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}

/*********************************************************************
*
*   	Public code
*
**********************************************************************
*/
/*********************************************************************
*
*   	MainTask
*/
void MainTask(void) {
  WM_HWIN hSwipe;
  char acBuffer[32];
  int  i;
  GUI_COLOR aColor[] = { GUI_RED, GUI_GREEN, GUI_BLUE };
  int Index;

  GUI_Init();
  WM_SetCallback(WM_HBKWIN, _cbBk);
  hSwipe = SWIPELIST_CreateEx(10, 10, 120, 200, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_SWIPELIST0);

  for (i = 0; i < 20; i++) {
	sprintf(acBuffer, "Item %i", i);
	SWIPELIST_AddItem(hSwipe, acBuffer, 30);
  }
  Index = 0;
  SWIPELIST_SetBkColor(hSwipe, SWIPELIST_CI_BK_ITEM_UNSEL, aColor[Index++]);
  
  while (1) {
	Index = (Index == GUI_COUNTOF(aColor)) ? 0 : Index;
	GUI_Delay(1000);
	SWIPELIST_SetBkColor(hSwipe, SWIPELIST_CI_BK_ITEM_UNSEL, aColor[Index++]);
  }
}

/*************************** End of file ****************************/


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.

C/C++ Source code

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

Quoted

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

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

11

Thursday, April 5th 2018, 3:26pm

Hello Sven,

Thanks for following my post

Quoted

Quoted



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.
Selso has attached the following image:
  • 2018-04-05 15_23_23-Target device.png

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

12

Thursday, April 5th 2018, 5:06pm

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 ?

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "DIALOG.h"
#include <stdio.h>

/*********************************************************************
*
*   	Externals
*
**********************************************************************
*/

/*********************************************************************
*
*   	Defines
*
**********************************************************************
*/

/*********************************************************************
*
*   	Static data
*
**********************************************************************
*/

/*********************************************************************
*
*   	Static code
*
**********************************************************************
*/
/*********************************************************************
*
*   	_cbBk
*/
static void _cbBk(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  case WM_PAINT:
	GUI_SetBkColor(GUI_WHITE);
	GUI_Clear();
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}

/*********************************************************************
*
*   	Public code
*
**********************************************************************
*/
/*********************************************************************
*
*   	MainTask
*/
void MainTask(void) {
  WM_HWIN hSwipe;
  char acBuffer[32];
  int  i;
  GUI_COLOR aColor[] = { GUI_RED, GUI_GREEN, GUI_BLUE };
  int Index;

  GUI_Init();
  WM_SetCallback(WM_HBKWIN, _cbBk);
  hSwipe = SWIPELIST_CreateEx(0, 0, GUI_GetScreenSizeX(), GUI_GetScreenSizeY(), WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_SWIPELIST0);

  for (i = 0; i < 20; i++) {
	sprintf(acBuffer, "Item %i", i);
	SWIPELIST_AddItem(hSwipe, acBuffer, 30);
  }
  Index = 0;
  SWIPELIST_SetBkColor(hSwipe, SWIPELIST_CI_BK_ITEM_UNSEL, aColor[Index++]);

  while (1) {
	Index = (Index == GUI_COUNTOF(aColor)) ? 0 : Index;
	GUI_Delay(1000);
	SWIPELIST_SetBkColor(hSwipe, SWIPELIST_CI_BK_ITEM_UNSEL, aColor[Index++]);
  }
}

/*************************** End of file ****************************/
Selso has attached the following image:
  • 2018-04-05 17_06_27-Target device.png

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 562

13

Friday, April 6th 2018, 9:10am

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/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*********************************************************************
*
*   	_OwnerDraw
*/
static int _OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
  GUI_RECT   	Rect;
  GUI_COLOR  	Color;

  switch (pDrawItemInfo->Cmd) {
  case WIDGET_ITEM_DRAW_TEXT:
	//
	// Call default owner draw to draw the text
	//
	SWIPELIST_OwnerDraw(pDrawItemInfo);
	//
	// The last item to be drawn
	//
	if (pDrawItemInfo->ItemIndex == SWIPELIST_GetNumItems(pDrawItemInfo->hWin) - 1) {
  	//
  	// Set a bk color
  	//
  	GUI_SetBkColor(SLI_COLOR);
  	//
  	// set up a rectangle to be cleared
  	//
  	Rect.x0 = WM_GetWindowOrgX(pDrawItemInfo->hWin);
  	Rect.y0 = pDrawItemInfo->y1;
  	Rect.x1 = WM_GetWindowSizeX(pDrawItemInfo->hWin);
  	Rect.y1 = LCD_GetYSize();
  	//
  	// Set a user clip rect, otherwise nothing would be drawn due to clipping
  	//
  	WM_SetUserClipRect(&Rect);
  	//
  	// Clear the rectangle
  	//
  	GUI_ClearRectEx(&Rect);
  	//
  	// Restore clip rect
  	//
  	WM_SetUserClipRect(NULL);
	}
	return 0;
  default:
	return SWIPELIST_OwnerDraw(pDrawItemInfo);
  }
}


Regards
Sven

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

14

Friday, April 6th 2018, 11:53am

[resolved]

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.
Selso has attached the following image:
  • 2018-04-06 11_48_09-Target device.png