Checkbox

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

  • Hallo,
    is it possible to make the size of the Checkbox independet of the size of ist text?
    I need two lines of text behind the Checkbox but i don't want a huge Checkbox itself.
    Can anyone help we?
    Stephan
  • Hi,

    Here is an example how you might proceed. I guess what you are looking for is CHECKBOX_SetSkinFlexButtonSize().

    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * Defines
    5. *
    6. **********************************************************************
    7. */
    8. /*********************************************************************
    9. *
    10. * Static data
    11. *
    12. **********************************************************************
    13. */
    14. /*********************************************************************
    15. *
    16. * Static code
    17. *
    18. **********************************************************************
    19. */
    20. /*********************************************************************
    21. *
    22. * _CheckboxSkin
    23. */
    24. static int _CheckboxSkin(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
    25. int State;
    26. GUI_RECT Rect;
    27. char acBuffer[100];
    28. const GUI_FONT * pFont;
    29. switch (pDrawItemInfo->Cmd) {
    30. case WIDGET_ITEM_DRAW_TEXT:
    31. Rect.x0 = pDrawItemInfo->x0 + 30;
    32. Rect.y0 = pDrawItemInfo->y0;
    33. Rect.x1 = pDrawItemInfo->x1;
    34. Rect.y1 = pDrawItemInfo->y1;
    35. CHECKBOX_GetText(pDrawItemInfo->hWin, acBuffer, sizeof(acBuffer));
    36. GUI_SetColor(GUI_BLACK);
    37. GUI_SetTextMode(GUI_TM_TRANS);
    38. pFont = CHECKBOX_GetDefaultFont();
    39. GUI_SetFont(pFont);
    40. GUI_DispStringInRectWrap(acBuffer, &Rect, GUI_TA_LEFT | GUI_TA_VCENTER, GUI_WRAPMODE_WORD);
    41. return 0;
    42. case WIDGET_ITEM_DRAW_FOCUS:
    43. Rect.x0 = pDrawItemInfo->x0 + 28;
    44. Rect.y0 = pDrawItemInfo->y0;
    45. Rect.x1 = pDrawItemInfo->x1;
    46. Rect.y1 = pDrawItemInfo->y1;
    47. GUI_DrawFocusRect(&Rect, 1);
    48. return 0;
    49. default:
    50. return CHECKBOX_DrawSkinFlex(pDrawItemInfo);
    51. }
    52. }
    53. /*********************************************************************
    54. *
    55. * _cbBk
    56. */
    57. static void _cbBk(WM_MESSAGE * pMsg) {
    58. WM_HWIN hItem;
    59. switch (pMsg->MsgId) {
    60. case WM_CREATE:
    61. hItem = CHECKBOX_Create(10, 10, 180, 30, pMsg->hWin, GUI_ID_CHECK0, WM_CF_SHOW);
    62. CHECKBOX_SetText(hItem, "This is a text which doesn't fit into one line");
    63. CHECKBOX_SetSkin(hItem, _CheckboxSkin);
    64. CHECKBOX_SetSkinFlexButtonSize(hItem, 20);
    65. break;
    66. case WM_PAINT:
    67. GUI_SetBkColor(GUI_WHITE);
    68. GUI_Clear();
    69. break;
    70. default:
    71. WM_DefaultProc(pMsg);
    72. break;
    73. }
    74. }
    75. /*********************************************************************
    76. *
    77. * Public code
    78. *
    79. **********************************************************************
    80. */
    81. /*********************************************************************
    82. *
    83. * MainTask
    84. */
    85. void MainTask(void) {
    86. WM_HWIN hButton;
    87. GUI_Init();
    88. WM_CreateWindowAsChild(0, 0, 480, 272, WM_HBKWIN, WM_CF_SHOW, _cbBk, 0);
    89. while (1) {
    90. GUI_Delay(100);
    91. }
    92. }
    93. /*************************** End of file ****************************/
    Display All


    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.