Partially show child window with scrolling function

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

    • Partially show child window with scrolling function

      Hi all,

      I'm trying to setup a vertical scrolling child window inside its parent window.
      This child window Y dimension should be greater than the parent window so it will be partially visible according the current scrolling position.
      The child window contains BUTTON and TEXT objects that have to move according to the current scrolling position

      At the moment I've managed to create a small child window with an own button and the code looks like that:

      Source Code

      1. static const GUI_WIDGET_CREATE_INFO _aGUISWIPELISTTEST_MainWinDialogCreate[] = {
      2. // Main Window
      3. { WINDOW_CreateIndirect, "GUISWIPELISTTEST Window", GUISWIPELISTTEST_ID_MAIN_WIN, GUISWIPELISTTEST_WINDOW_XPOS, GUISWIPELISTTEST_WINDOW_YPOS, GUISWIPELISTTEST_WINDOW_XSIZE + 100, GUISWIPELISTTEST_WINDOW_YSIZE + 100, 0, 0, 0 },
      4. // Texts and Labels
      5. // USER START (Optionally insert additional widgets)
      6. // USER END
      7. };
      8. //Main dialog creation
      9. g_GUISwipeListTest.hWin = GUI_CreateDialogBox(_aGUISWIPELISTTEST_MainWinDialogCreate, GUI_COUNTOF(_aGUISWIPELISTTEST_MainWinDialogCreate), _cbDialogGUISWIPELISTTEST_MainWin, WM_GetDesktopWindowEx(0), 0, 0);
      10. ...
      11. static void _cbDialogGUISWIPELISTTEST_MainWin(WM_MESSAGE *pMsg)
      12. {
      13. switch (pMsg->MsgId) {
      14. case WM_INIT_DIALOG:
      15. //
      16. // Initialization of 'Window'
      17. //
      18. hItem = pMsg->hWin;
      19. WINDOW_SetBkColor(hItem,GUI_CUSTOM_MAIN_BACKGROUND_COLOR);
      20. WM_EnableWindow(hItem);
      21. //
      22. // Subwindow initialization
      23. //
      24. g_GUISwipeListTest.hChildWin = WM_CreateWindowAsChild(GUISWIPELISTTEST_FOOTER_LINE_XPOS, 20, GUISWIPELISTTEST_FOOTER_LINE_XSIZE, 150, pMsg->hWin, WM_CF_SHOW | WM_CF_HASTRANS | WM_CF_MEMDEV_ON_REDRAW, _cbSUBWINDOW_N0, sizeof(WM_HWIN));
      25. //Button inside child window
      26. hItem_Btn =
      27. BUTTON_CreateEx(0,0,80,20,g_GUISwipeListTest.hChildWin, WM_CF_SHOW, 0, GUISWIPELISTTEST_ID_BTN_SUB_N0);
      28. WM_SetCallback (hItem_Btn, _cbGUISWIPELISTTEST_Btn_Sub_N0);
      29. break;
      30. case WM_MOTION:
      31. pInfo = (WM_MOTION_INFO *)pMsg->Data.p;
      32. switch (pInfo->Cmd) {
      33. case WM_MOTION_INIT:
      34. pInfo->Flags = WM_CF_MOTION_Y;
      35. break;
      36. }
      37. break;
      38. default:
      39. WM_DefaultProc(pMsg);
      40. break;
      41. }
      42. }
      Display All

      The child window has its own callback and so its own button, the visualization and the touch response is fine.

      So my questions are:
      - If I make a larger (in terms of Y-axis) child window how can I make it only partially according to the current Y-scrolling?
      - How can I make the child window scroll only on the Y-axis without moving all the window? Where do I have to write the WM_MOTION case? In both parent and child window?

      (And also if I made some mistake and this is not the proper way to do the trick...)

      Thank you!
      Mark
      Images
      • scrolling_child_window.png

        18.5 kB, 800×600, viewed 1,254 times
    • Hello,

      an unusual way, but clearly effective if you want to scroll a child dialog with a swipe. I'd make a swipelist in a main dialog, then add an empty item and attach a child dialog to that item. Otherwise you will have to create an additional window, then attach a child dialog to it and transmit motion messages to it whereas the swipelist already has the necessary functionality.

      C Source Code: main.c

      1. #include "DIALOG.h"
      2. #define ID_MAIN_0 (GUI_ID_USER + 0x00)
      3. #define ID_TEXT_MAIN_0 (GUI_ID_USER + 0x01)
      4. #define ID_SWIPELIST_MAIN_0 (GUI_ID_USER + 0x02)
      5. #define ID_CHILD_0 (GUI_ID_USER + 0x03)
      6. #define ID_TEXT_CHILD_0 (GUI_ID_USER + 0x04)
      7. #define ID_BUTTON_CHILD_0 (GUI_ID_USER + 0x05)
      8. #define ID_BUTTON_CHILD_1 (GUI_ID_USER + 0x06)
      9. #define ID_BUTTON_CHILD_2 (GUI_ID_USER + 0x07)
      10. static const GUI_WIDGET_CREATE_INFO _aMainDlg[] = {
      11. { WINDOW_CreateIndirect, "Window", ID_MAIN_0, 0, 0, 320, 240, 0, 0x0, 0 },
      12. { TEXT_CreateIndirect, "Text", ID_TEXT_MAIN_0, 0, 0, 320, 50, 0, 0x64, 0 },
      13. { SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_MAIN_0, 40, 40, 242, 180 },
      14. };
      15. static const GUI_WIDGET_CREATE_INFO _aChildDlg[] = {
      16. { WINDOW_CreateIndirect, "Window", ID_CHILD_0, 40, 40, 240, 320, 0, 0x0, 0 },
      17. { TEXT_CreateIndirect, "Text", ID_TEXT_CHILD_0, 0, 0, 240, 50, 0, 0x64, 0 },
      18. { BUTTON_CreateIndirect, "Button", ID_BUTTON_CHILD_0, 20, 70, 200, 24, 0, 0x0, 0 },
      19. { BUTTON_CreateIndirect, "Button", ID_BUTTON_CHILD_1, 20, 170, 200, 25, 0, 0x0, 0 },
      20. { BUTTON_CreateIndirect, "Button", ID_BUTTON_CHILD_2, 20, 270, 200, 25, 0, 0x0, 0 },
      21. };
      22. WM_HWIN hMainDlg, hChildDlg;
      23. static void _cbMainDlg(WM_MESSAGE * pMsg) {
      24. WM_HWIN hItem;
      25. switch (pMsg->MsgId) {
      26. case WM_INIT_DIALOG:
      27. WINDOW_SetBkColor(pMsg->hWin, GUI_GRAY);
      28. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_MAIN_0);
      29. TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x00000000));
      30. TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
      31. TEXT_SetFont(hItem, GUI_FONT_32_ASCII);
      32. TEXT_SetText(hItem, "MAIN DIALOG");
      33. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_MAIN_0);
      34. SWIPELIST_AddItem(hItem, " ", 321);
      35. SWIPELIST_SetBkColor(hItem, SWIPELIST_CI_BK_ITEM_UNSEL, GUI_WHITE);
      36. SWIPELIST_ItemAttachWindow(hItem, 0, hChildDlg, 1, 0);
      37. break;
      38. default:
      39. WM_DefaultProc(pMsg);
      40. break;
      41. }
      42. }
      43. static void _cbChildDlg(WM_MESSAGE * pMsg) {
      44. WM_HWIN hItem;
      45. switch (pMsg->MsgId) {
      46. case WM_INIT_DIALOG:
      47. WINDOW_SetBkColor(pMsg->hWin, GUI_WHITE);
      48. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_CHILD_0);
      49. TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x00000000));
      50. TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
      51. TEXT_SetFont(hItem, GUI_FONT_32_ASCII);
      52. TEXT_SetText(hItem, "CHILD WINDOW");
      53. break;
      54. default:
      55. WM_DefaultProc(pMsg);
      56. break;
      57. }
      58. }
      59. void MainTask(void) {
      60. GUI_Init();
      61. WM_MULTIBUF_Enable(1);
      62. WM_SetDesktopColor(GUI_BLACK);
      63. hChildDlg = GUI_CreateDialogBox(_aChildDlg, GUI_COUNTOF(_aChildDlg), _cbChildDlg, WM_HBKWIN, 0, 0);
      64. hMainDlg = GUI_CreateDialogBox(_aMainDlg, GUI_COUNTOF(_aMainDlg), _cbMainDlg, WM_HBKWIN, 0, 0);
      65. while (1) {
      66. GUI_Exec();
      67. }
      68. }
      Display All
      Regards,

      Anthony

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

    • cilmagemlu wrote:

      Hello,

      an unusual way, but clearly effective if you want to scroll a child dialog with a swipe. I'd make a swipelist in a main dialog, then add an empty item and attach a child dialog to that item. Otherwise you will have to create an additional window, then attach a child dialog to it and transmit motion messages to it whereas the swipelist already has the necessary functionality.

      C Source Code: main.c

      1. #include "DIALOG.h"
      2. #define ID_MAIN_0 (GUI_ID_USER + 0x00)
      3. #define ID_TEXT_MAIN_0 (GUI_ID_USER + 0x01)
      4. #define ID_SWIPELIST_MAIN_0 (GUI_ID_USER + 0x02)
      5. #define ID_CHILD_0 (GUI_ID_USER + 0x03)
      6. #define ID_TEXT_CHILD_0 (GUI_ID_USER + 0x04)
      7. #define ID_BUTTON_CHILD_0 (GUI_ID_USER + 0x05)
      8. #define ID_BUTTON_CHILD_1 (GUI_ID_USER + 0x06)
      9. #define ID_BUTTON_CHILD_2 (GUI_ID_USER + 0x07)
      10. static const GUI_WIDGET_CREATE_INFO _aMainDlg[] = {
      11. { WINDOW_CreateIndirect, "Window", ID_MAIN_0, 0, 0, 320, 240, 0, 0x0, 0 },
      12. { TEXT_CreateIndirect, "Text", ID_TEXT_MAIN_0, 0, 0, 320, 50, 0, 0x64, 0 },
      13. { SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_MAIN_0, 40, 40, 242, 180 },
      14. };
      15. static const GUI_WIDGET_CREATE_INFO _aChildDlg[] = {
      16. { WINDOW_CreateIndirect, "Window", ID_CHILD_0, 40, 40, 240, 320, 0, 0x0, 0 },
      17. { TEXT_CreateIndirect, "Text", ID_TEXT_CHILD_0, 0, 0, 240, 50, 0, 0x64, 0 },
      18. { BUTTON_CreateIndirect, "Button", ID_BUTTON_CHILD_0, 20, 70, 200, 24, 0, 0x0, 0 },
      19. { BUTTON_CreateIndirect, "Button", ID_BUTTON_CHILD_1, 20, 170, 200, 25, 0, 0x0, 0 },
      20. { BUTTON_CreateIndirect, "Button", ID_BUTTON_CHILD_2, 20, 270, 200, 25, 0, 0x0, 0 },
      21. };
      22. WM_HWIN hMainDlg, hChildDlg;
      23. static void _cbMainDlg(WM_MESSAGE * pMsg) {
      24. WM_HWIN hItem;
      25. switch (pMsg->MsgId) {
      26. case WM_INIT_DIALOG:
      27. WINDOW_SetBkColor(pMsg->hWin, GUI_GRAY);
      28. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_MAIN_0);
      29. TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x00000000));
      30. TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
      31. TEXT_SetFont(hItem, GUI_FONT_32_ASCII);
      32. TEXT_SetText(hItem, "MAIN DIALOG");
      33. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_MAIN_0);
      34. SWIPELIST_AddItem(hItem, " ", 321);
      35. SWIPELIST_SetBkColor(hItem, SWIPELIST_CI_BK_ITEM_UNSEL, GUI_WHITE);
      36. SWIPELIST_ItemAttachWindow(hItem, 0, hChildDlg, 1, 0);
      37. break;
      38. default:
      39. WM_DefaultProc(pMsg);
      40. break;
      41. }
      42. }
      43. static void _cbChildDlg(WM_MESSAGE * pMsg) {
      44. WM_HWIN hItem;
      45. switch (pMsg->MsgId) {
      46. case WM_INIT_DIALOG:
      47. WINDOW_SetBkColor(pMsg->hWin, GUI_WHITE);
      48. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_CHILD_0);
      49. TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x00000000));
      50. TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
      51. TEXT_SetFont(hItem, GUI_FONT_32_ASCII);
      52. TEXT_SetText(hItem, "CHILD WINDOW");
      53. break;
      54. default:
      55. WM_DefaultProc(pMsg);
      56. break;
      57. }
      58. }
      59. void MainTask(void) {
      60. GUI_Init();
      61. WM_MULTIBUF_Enable(1);
      62. WM_SetDesktopColor(GUI_BLACK);
      63. hChildDlg = GUI_CreateDialogBox(_aChildDlg, GUI_COUNTOF(_aChildDlg), _cbChildDlg, WM_HBKWIN, 0, 0);
      64. hMainDlg = GUI_CreateDialogBox(_aMainDlg, GUI_COUNTOF(_aMainDlg), _cbMainDlg, WM_HBKWIN, 0, 0);
      65. while (1) {
      66. GUI_Exec();
      67. }
      68. }
      Display All
      Hello Anthony,

      thank you for your answer.

      It looks like a good idea, I've struggled a little with the SWIPELIST_ItemAttachWindow function that was not working properly due to wrong object dimension (couldn't attach the window because it was too large) but I managed to make it work after fixing it!
      Thank you!

      Best regards,
      Mark