Custom skinning callback function for button

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

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