LISTBOX - Is there a way to display two-lined item

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

    • LISTBOX - Is there a way to display two-lined item

      Hi,

      I would like to know that there is any way to express more than one lined listbox item.

      For example,

      "Meet with Henry
      2019/11/30"

      Thank you,

      Regards,
      Ashley
    • Hello,

      it is possible with using owner draw function where you can display multilined strings at dedicated item.

      C Source Code

      1. #include "DIALOG.h"
      2. LISTBOX_Handle hLstbx;
      3. int _LISTBOX_CustomDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
      4. GUI_RECT ItemRect;
      5. GUI_COLOR TextColor;
      6. switch (pDrawItemInfo->Cmd) {
      7. case WIDGET_ITEM_GET_YSIZE:
      8. // Change ysize for two lined item
      9. if (pDrawItemInfo->ItemIndex == 2)
      10. return LISTBOX_OwnerDraw(pDrawItemInfo) * 2;
      11. else
      12. return LISTBOX_OwnerDraw(pDrawItemInfo);
      13. break;
      14. case WIDGET_ITEM_DRAW:
      15. // Display two lined text at the item
      16. if (pDrawItemInfo->ItemIndex == 2) {
      17. LISTBOX_OwnerDraw(pDrawItemInfo);
      18. ItemRect.x0 = pDrawItemInfo->x0;
      19. ItemRect.y0 = pDrawItemInfo->y0;
      20. ItemRect.x1 = pDrawItemInfo->x1;
      21. ItemRect.y1 = pDrawItemInfo->y1;
      22. if (LISTBOX_GetItemDisabled(pDrawItemInfo->hWin, pDrawItemInfo->ItemIndex) == 1) {
      23. TextColor = LISTBOX_GetTextColor(pDrawItemInfo->hWin, LISTBOX_CI_DISABLED);
      24. }
      25. else {
      26. if (LISTBOX_GetSel(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
      27. if (WM_HasFocus(pDrawItemInfo->hWin))
      28. TextColor = LISTBOX_GetTextColor(pDrawItemInfo->hWin, LISTBOX_CI_SELFOCUS);
      29. else
      30. TextColor = LISTBOX_GetTextColor(pDrawItemInfo->hWin, LISTBOX_CI_SEL);
      31. }
      32. else
      33. TextColor = LISTBOX_GetTextColor(pDrawItemInfo->hWin, LISTBOX_CI_UNSEL);
      34. }
      35. GUI_SetColor(TextColor);
      36. GUI_DispStringInRect("Two lined\nitem3", &ItemRect, LISTBOX_GetTextAlign(pDrawItemInfo->hWin));
      37. }
      38. else
      39. return LISTBOX_OwnerDraw(pDrawItemInfo);
      40. break;
      41. default:
      42. return LISTBOX_OwnerDraw(pDrawItemInfo);
      43. break;
      44. }
      45. return 0;
      46. }
      47. void MainTask(void) {
      48. GUI_Init();
      49. WM_MULTIBUF_Enable(1);
      50. WM_SetDesktopColor(GUI_DARKGRAY);
      51. hLstbx = LISTBOX_CreateEx(50, 50, 100, 54, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTBOX0, NULL);
      52. LISTBOX_AddString(hLstbx, "One lined item 1");
      53. LISTBOX_AddString(hLstbx, "One lined item 2");
      54. LISTBOX_AddString(hLstbx, ""); // -> to be two lined, display the text in owner draw function
      55. LISTBOX_SetOwnerDraw(hLstbx, _LISTBOX_CustomDraw);
      56. while (1) {
      57. GUI_Delay(50);
      58. }
      59. }
      Display All
      Alex.

      The post was edited 4 times, last by LexaGB ().

    • I use dialog which creates a LISTBOX widget from resource table entry.(GUI_CreateDialogBox) to hold several widget.
      And I was wondering there is a way to draw multi-lined item by setting some configuration.

      I will try owner drawing as you say.
      Thank you very much~

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

    • Hello,

      there is no difference how you are doing: whether you create a widget from resource table or create it manually.

      Resource table just calls the same creating API function with some basic parameters of a widget.

      So there is no configuration to do items with multilined text immediately when creating a listbox.

      My sample code just was easier to do creating a listbox directly using API.

      The main thing was to reveal the owner draw mechanism that would work in all the cases.

      Alex.

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

    • Upd:

      you can do a little easier: set multilined string when call API function: LISTBOX_AddString(hLstbx, "Two lined\nitem 3");

      and then handle only command WIDGET_ITEM_GET_YSIZE in your owner draw function to change the ysize of the item.


      Alex.