Tuesday, April 24th 2018, 6:32pm 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.

Lullaby

Beginner

Date of registration: Aug 3rd 2016

Posts: 23

1

Thursday, March 15th 2018, 1:02pm

Custom skinning callback function for button

Hi,

I was doing some experimentation with the custom skinning callback function for button.
In my code, I write like the following:-

case WM_INIT_DIALOG:
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_B0);

BUTTON_SetSkin(hItem, _CustomSkin);


And inside the custom skinning function, I write:


int _CustomSkin(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo)
{
int Id;

switch (pDrawItemInfo->Cmd)
{
case WIDGET_ITEM_DRAW_BACKGROUND:
Id = WM_GetId(pDrawItemInfo->hWin);
switch (Id)
{
case ID_BUTTON_B0:
switch((unsigned int)eToggle)
{
case TOGGLE_YELLOW:
BUTTON_SetSkinFlexProps(&PropsButtonUnpressed1, BUTTON_SKINFLEX_PI_ENABLED);
BUTTON_SetSkinFlexProps(&PropsButtonUnpressed1, BUTTON_SKINFLEX_PI_FOCUSSED);
break;
case TOGGLE_RED:
BUTTON_SetSkinFlexProps(&PropsButtonUnpressed2, BUTTON_SKINFLEX_PI_ENABLED);
BUTTON_SetSkinFlexProps(&PropsButtonUnpressed2, BUTTON_SKINFLEX_PI_FOCUSSED);
break;
}
BUTTON_SetSkinFlexProps(&PropsButtonPressed, BUTTON_SKINFLEX_PI_PRESSED);
BUTTON_DrawSkinFlex(pDrawItemInfo); // Draw button with new properties
break;
}
default:
BUTTON_DrawSkinFlex(pDrawItemInfo);
break;
}
return 0;
}

My problem is:- periodically this toggle parameter is changing in my application side of the code and I want this custom skinning function to be invoked everytime this color toggle happens.
I have met the purpose by directly calling redundantly BUTTON_SetSkin(hItem, _CustomSkin); again wherever I require this.
But I know, it is not the right method. Is it like we need to invalidate or call paint method?
I am not sure. Neither I didn't understand its usecase from any of the emWin samples or emWin user manual as well.


Please share your valuable thoughts on this.
Looking forward to hear from you soon.

Thank you,
Lullaby.

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 562

2

Tuesday, March 20th 2018, 2:52pm

Hi,

You should simply call WM_InvalidateWindow() with the handle of the button if the toggle variable gets changed. WM_InvalidateWindow() marks the button as invalid and it gets redrawn the next time GUI_Exec() or GUI_Delay() gets called (but don't call one these functions right after invalidating the button to it only at a central position in your application).

Regards
Sven

Similar threads