button and wrap

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

    • Hello,

      you can use skinning option for BUTTON widget and handle text drawing command calling GUI_DispStringInRectWrap() function.

      C Source Code

      1. #include "DIALOG.h"
      2. // Skinning function for the button
      3. int _DrawSkin_BUTTON(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
      4. char str[30];
      5. GUI_RECT pRect;
      6. const GUI_FONT * pFont;
      7. GUI_COLOR TextColor_Disabled, TextColor_Pressed, TextColor_Unpressed;
      8. int TextAlign;
      9. switch (pDrawItemInfo->Cmd) {
      10. case WIDGET_ITEM_DRAW_TEXT:
      11. // Get the coords of the button rect and decrease the rect width
      12. // to avoid covering the button frame with the text
      13. pRect.x0 = pDrawItemInfo->x0 + 4;
      14. pRect.y0 = pDrawItemInfo->y0;
      15. pRect.x1 = pDrawItemInfo->x1 - 4;
      16. pRect.y1 = pDrawItemInfo->y1;
      17. // Get the text of the button
      18. BUTTON_GetText(pDrawItemInfo->hWin, str, 30);
      19. // Get text align
      20. TextAlign = BUTTON_GetTextAlign(pDrawItemInfo->hWin);
      21. // Get font
      22. pFont = BUTTON_GetFont(pDrawItemInfo->hWin);
      23. // Get colors
      24. TextColor_Disabled = BUTTON_GetTextColor(pDrawItemInfo->hWin, BUTTON_CI_DISABLED);
      25. TextColor_Pressed = BUTTON_GetTextColor(pDrawItemInfo->hWin, BUTTON_CI_PRESSED);
      26. TextColor_Unpressed = BUTTON_GetTextColor(pDrawItemInfo->hWin, BUTTON_CI_UNPRESSED);
      27. // Set font
      28. GUI_SetFont(pFont);
      29. // If the button is enabled
      30. if (WM_IsEnabled(pDrawItemInfo->hWin))
      31. {
      32. // Set color for pressed / unpressed state
      33. if (BUTTON_IsPressed(pDrawItemInfo->hWin))
      34. GUI_SetColor(TextColor_Pressed);
      35. else
      36. GUI_SetColor(TextColor_Unpressed);
      37. }
      38. else // Set color for disabled state
      39. GUI_SetColor(TextColor_Disabled);
      40. // Transparent mode
      41. GUI_SetTextMode(GUI_TM_TRANS);
      42. // Display the text using wrap mode word wise
      43. GUI_DispStringInRectWrap(str, &pRect, TextAlign, GUI_WRAPMODE_WORD);
      44. break;
      45. default:
      46. return BUTTON_DrawSkinFlex(pDrawItemInfo);
      47. break;
      48. }
      49. return 0;
      50. }
      51. void MainTask(void) {
      52. BUTTON_Handle hButton;
      53. GUI_Init();
      54. WM_MULTIBUF_Enable(1);
      55. GUI_SetBkColor(GUI_LIGHTGRAY);
      56. GUI_Clear();
      57. // Create a button
      58. hButton = BUTTON_CreateEx(100, 100, 80, 50, WM_HBKWIN, BUTTON_CF_SHOW, 0, GUI_ID_BUTTON0);
      59. // Set button text
      60. BUTTON_SetText(hButton, "A text inside the button");
      61. // Set skinning function for the button
      62. BUTTON_SetSkin(hButton, _DrawSkin_BUTTON);
      63. while(1)
      64. {
      65. GUI_Exec();
      66. }
      67. }
      Display All

      The post was edited 2 times, last by LexaGb ().