Button with image and text

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

  • Hi,
    one way is to draw the button completely yourself. Set the button callback to your callback

    Source Code

    1. WM_SetCallback(h,_cbButton);



    then define the callback, where you handle paint yourself, rest of the button behavior is standard

    Source Code

    1. static void _cbButton(WM_MESSAGE * pMsg){ switch (pMsg->MsgId) { case WM_PAINT: _OnPaint(pMsg->hWin); break; //The original callback default: BUTTON_Callback(pMsg); break; }}



    and finally the paint function

    Source Code

    1. static void _OnPaint(WM_HWIN h) { //get button rectangle GUI_RECT rect; WM_GetClientRect(&rect);
    2. //do your painting here}



    In the paint function, you have access to all button properties via the passed handle, or by functions which work with the current widget by default. If you wanted the standard button drawn in the background, you would have to let emWin draw the button first and then do your drawing.

    Petr
  • Hi,

    Petr absolutely is right. Attached is a sample which will explain this with a bit more detail.

    Regards,
    Sven
    Files
    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.