How to program different skins for different buttons in the same window

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

  • How to program different skins for different buttons in the same window

    :(
    Hi guys,
    If anyone have an answer to this please help.
    I have 16 buttons in a window with the default skin.
    I need to set a single button to round using a different skin, however, if I change the skin for one button it changes for all.
    I cannot seem to target a single button only.
    Any help is appreciated, here is a part of the code
    Thanks
    Rich

    * _cbDialog
    */
    static void _cbDialog(WM_MESSAGE * pMsg) {
    const void * pData;
    WM_HWIN hItem;
    U32 FileSize;
    int NCode;
    int Id;
    // USER START (Optionally insert additional variables)
    // USER END

    switch (pMsg->MsgId) {
    case WM_INIT_DIALOG:
    //
    // Initialization of 'Scn030_UserCodes'
    //
    hItem = pMsg->hWin;
    WINDOW_SetBkColor(hItem, 0x00FFFF80);
    //
    // Initialization of 'ButtonExit'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
    BUTTON_SetFont(hItem, GUI_FONT_16_ASCII);
    BUTTON_SetText(hItem, "Exit");
    //
    // Initialization of 'Edit_UserNum'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
    EDIT_SetText(hItem, "01-000000-00-00");
    EDIT_SetFont(hItem, GUI_FONT_20_ASCII);
    EDIT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
    //
    // Initialization of 'Text1'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
    TEXT_SetText(hItem, "User#-UserCode -Opt1-Opt2");
    TEXT_SetFont(hItem, GUI_FONT_13_ASCII);
    //
    // Initialization of 'Button1'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
    BUTTON_SetText(hItem, "1");
    //
    // Initialization of 'Button2'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
    BUTTON_SetText(hItem, "2");
    //
    // Initialization of 'Button3'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_3);
    BUTTON_SetText(hItem, "3");
    //
    // Initialization of 'Button4'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_4);
    BUTTON_SetText(hItem, "4");
    //
    // Initialization of 'Button5'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_5);
    BUTTON_SetText(hItem, "5");
    //
    // Initialization of 'Button6'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_6);
    BUTTON_SetText(hItem, "6");
    //
    // Initialization of 'Button7'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_7);
    BUTTON_SetText(hItem, "7");
    //
    // Initialization of 'Button8'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_8);
    BUTTON_SetText(hItem, "8");
    //
    // Initialization of 'Button9'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_9);
    BUTTON_SetText(hItem, "9");
    //
    // Initialization of 'Button0'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_10);
    BUTTON_SetText(hItem, "0");
    //
    // Initialization of 'ButtonA'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_11);
    BUTTON_SetText(hItem, "A");
    //
    // Initialization of 'ButtonB'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_12);
    BUTTON_SetText(hItem, "B");
    //
    // Initialization of 'ButtonC'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_13);
    BUTTON_SetText(hItem, "C");
    //
    // Initialization of 'ButtonD'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_14);
    BUTTON_SetText(hItem, "D");
    //
    // Initialization of 'ButtonE'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_15);
    BUTTON_SetText(hItem, "E");
    //
    // Initialization of 'ButtonF'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_16);
    BUTTON_SetText(hItem, "F");
    //
    // Initialization of 'ButtonSave'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_17);
    BUTTON_SetText(hItem, "Save");
    //
    // Initialization of 'Text2'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
    TEXT_SetText(hItem, "Cursor on decimal char");
    TEXT_SetTextColor(hItem, 0x00FF0000);
    //
    // Initialization of 'Image'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE_0);
    pData = _GetImageById(ID_IMAGE_0_IMAGE_0, &FileSize);
    IMAGE_SetBMP(hItem, pData, FileSize);
    // USER START (Optionally insert additional code for further widget initialization)
    hItem = pMsg->hWin;
    WM_SelectWindow(hItem); //used to switch windows
    WM_SetBkWindowColor(GUI_BLACK); //GUI_SetBkColor(GUI_BLACK);
    hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);

    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
    extern GUI_CONST_STORAGE unsigned char bmTestKeyGraphics;
    BUTTON_SKINFLEX_PROPS Props;
    BUTTON_SKINFLEX_PROPS DefaultProps;

    BUTTON_SetBitmap(hItem, BUTTON_BI_UNPRESSED, &bmTestKeyGraphics);

    BUTTON_GetSkinFlexProps(&DefaultProps, BUTTON_SKINFLEX_PI_ENABLED); // Get the default properties for an enabled button, also possible for other state
    BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX); //set skin for all other buttons

    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_14);
    BUTTON_SetSkin(hItem, BUTTON_SKIN_FLEX); //set skin for this button
    BUTTON_GetSkinFlexProps(&Props, BUTTON_SKINFLEX_PI_ENABLED); // Get the default properties for an enabled button, also possible for other state
    Props.aColorFrame[0] = GUI_DARKRED; // Set new colors for different areas, take a look into the manual under skinning
    Props.aColorFrame[1] = GUI_RED;
    Props.aColorFrame[2] = GUI_LIGHTRED;

    Props.Radius = 30;
    BUTTON_SetSkinFlexProps(&Props, BUTTON_SKINFLEX_PI_ENABLED); // Set the new fancy colors for every state (as an example)
    // BUTTON_SetSkinFlexProps(&Props, BUTTON_SKINFLEX_PI_PRESSED);
    BUTTON_SetSkinFlexProps(&Props, BUTTON_SKINFLEX_PI_FOCUSSED);
    BUTTON_SetSkinFlexProps(&Props, BUTTON_SKINFLEX_PI_DISABLED);
    Props.aColorFrame[2] = GUI_BLUE;
    BUTTON_SetSkinFlexProps(&Props, BUTTON_SKINFLEX_PI_PRESSED);
    WM_Invalidate(hItem); // Maybe the most importand part, tell button something has changed, otherwise nothing would happen
    BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX); //set skin for all other buttons

    // USER END
    break;
    case WM_NOTIFY_PARENT:
    Id = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch(Id) {
    case ID_BUTTON_0: // Notifications sent by 'ButtonExit'
    ....
  • Multiple buttons with different colors

    Hi Matz,
    Thanks for the response, just got back from a different proj.
    So the idea is to have 3 black buttons, 1 green button and 1 red button.
    I'd appreciate if anyone have a sample code to do this, including any callback function creation.
    Thanks
    Rich
  • Hi Rich,

    Please take a look into the application attached. I have created four buttons. The first two are getting drawn with different shapes (but still they react on press over their whole area). The third button has the standard stile but with different colors and the last one stays untouched.

    Regards,
    Sven
    Files
    • ButtonSkin.zip

      (5.6 kB, downloaded 699 times, last: )
    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.