Tuesday, May 22nd 2018, 11:46pm 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.

aaa1

Beginner

Date of registration: Mar 8th 2018

Posts: 16

1

Friday, April 27th 2018, 9:53am

CHECKBOX background color

I want to change the checkbox color using function CHECKBOX_SetBoxBkColor(). Problem is the color does not change..
Here is my simple code:


WM_TOUCH:

hItem = WM_GetDialogItem(pMsg->hWin, ID_STATUS_CHECKBOX_1);
CHECKBOX_SetBoxBkColor(hItem, GUI_YELLOW, CHECKBOX_CI_ENABLED);
break;

Any problem with my code? How can I solve the problem?
Thanks

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 584

2

Friday, April 27th 2018, 11:19am

Hi,

If you are using the SkinFlex look for widgets (which is the default), some functions have no direct impact. This is also true for the checkbox.

The area of the CHECKBOX consists of multiple colors (there is a small gradient), therefor it wouldn't make sense to set a single color.

For these widgets you have to use the function <WIDGET>_GetSkinFlexProps() and <WIDGET>_SetSkinFlexProps() to modify their colors.

Read the properties with the get-function, modify it and write the properties back with the set-function.

Attached is a short example on how to do this with the checkbox.

Regards,
Sven
SEGGER - Schoenen has attached the following file:

aaa1

Beginner

Date of registration: Mar 8th 2018

Posts: 16

3

Friday, April 27th 2018, 2:57pm

okay thanks!

Also, I don't want the checkbox to be set manually by the user, so I put WIDGET_SetFocusable(hItem, 0) in the WM_INIT_DIALOG section.
Despite this, the checkbox status can still be changed manually by the user..

Is there another way to do so or am I doing something wrong?

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 584

4

Friday, April 27th 2018, 5:02pm

Hi,

You could either set a custom callback for the checkbox and react on WM_TOUCH but simply do nothing:

C/C++ Source code

1
2
	hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECKBOX_0);
	WM_SetCallback(hItem, _cbCheckbox);


C/C++ Source code

1
2
3
4
5
6
7
8
9
static void _cbCheckbox(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  case WM_TOUCH:
	break;
  default:
	CHECKBOX_Callback(pMsg);
	break;
  }
}


Or you read the enabled flex skin properties and set them for disabled state. Then you can disable the checkbox but it will look like enbaled. It can be still set programatically.

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
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN	hItem;
  int    	NCode;
  int    	Id;
  static int Index;
  GUI_COLOR  aColor0[] = { GUI_DARKRED, GUI_DARKBLUE };
  GUI_COLOR  aColor1[] = { GUI_RED, GUI_BLUE };
  static CHECKBOX_SKINFLEX_PROPS Props = {0};

  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
	//
	// Initialization of 'Checkbox'
	//
	hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECKBOX_0);
	CHECKBOX_SetText(hItem, "Check");
	WM_DisableWindow(hItem);
	CHECKBOX_GetSkinFlexProps(&Props, CHECKBOX_SKINFLEX_PI_ENABLED);
	CHECKBOX_SetSkinFlexProps(&Props, CHECKBOX_SKINFLEX_PI_DISABLED);
	break;
  case WM_NOTIFY_PARENT:
	Id	= WM_GetId(pMsg->hWinSrc);
	NCode = pMsg->Data.v;
	switch(Id) {
	case ID_BUTTON_0: // Notifications sent by 'Button'
  	switch(NCode) {
  	case WM_NOTIFICATION_RELEASED:
    	hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECKBOX_0);
    	if (CHECKBOX_GetState(hItem)) {
      	CHECKBOX_SetState(hItem, 0);
    	} else {
      	CHECKBOX_SetState(hItem, 1);
    	}
    	break;
  	}
  	break;
	}
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}


Regards,
Sven