How to avoid moving a window by a widget

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

    • How to avoid moving a window by a widget

      Hello to everyone,

      there are some widgets in emWin that accept a PID and do things accordingly to a PID state. For example, SLIDER widget.

      When motion option enabled in a parent window then PID state is to be trasmitted to parent window and slider loses its correct "sliding functionality" since parent window moves instead of slider.

      My question: how to avoid this behaviour? Of course we can handle PID-messages in slider callback and manually enable/disable motion in a parent window.

      But maybe there is an easier way?

      Here is a simple code:

      C Source Code

      1. #include "DIALOG.h"
      2. WM_HWIN hCheck, hText;
      3. void _cbWin(WM_MESSAGE * pMsg) {
      4. GUI_RECT Rect;
      5. switch (pMsg->MsgId) {
      6. case WM_CREATE:
      7. SLIDER_CreateEx(60, 60, 200, 30, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_SLIDER0);
      8. hCheck = CHECKBOX_CreateEx(60, 100, 100, 20, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_CHECK0);
      9. CHECKBOX_SetText(hCheck, "Motion disabled");
      10. hText = TEXT_CreateEx(0, 10, 320, 50, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_TEXT0, "Slider is moving separately from parent window");
      11. TEXT_SetTextAlign(hText, GUI_TA_CENTER);
      12. break;
      13. case WM_NOTIFY_PARENT:
      14. if ((pMsg->hWinSrc == hCheck) && (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED)) {
      15. if (CHECKBOX_IsChecked(hCheck)) {
      16. CHECKBOX_SetText(hCheck, "Motion enabled");
      17. TEXT_SetText(hText, "Slider makes parent window to move\nHow to avoid it?");
      18. WM_MOTION_SetMoveable(pMsg->hWin, WM_CF_MOTION_X, 1);
      19. }
      20. else {
      21. CHECKBOX_SetText(hCheck, "Motion disabled");
      22. TEXT_SetText(hText, "Slider is moving separately from parent window");
      23. WM_MOTION_SetMoveable(pMsg->hWin, WM_CF_MOTION_X, 0);
      24. }
      25. }
      26. break;
      27. case WM_PAINT:
      28. WM_GetClientRect(&Rect);
      29. GUI_SetBkColor(GUI_WHITE);
      30. GUI_ClearRectEx(&Rect);
      31. break;
      32. default:
      33. WM_DefaultProc(pMsg);
      34. break;
      35. }
      36. }
      37. void MainTask(void) {
      38. GUI_Init();
      39. WM_MULTIBUF_Enable(1);
      40. WM_SetDesktopColor(GUI_BLACK);
      41. WM_SetScreenSize(800, 600);
      42. WM_CreateWindow(240, 180, 320, 240, WM_CF_SHOW, _cbWin, 0);
      43. WM_MOTION_Enable(1);
      44. while (1) {
      45. GUI_Delay(50);
      46. }
      47. }
      Display All
      Thanks,
      Alex.
    • Hi Alex,

      The SLIDER callback is missing some code which "swallows" the motion input. Can you set the following callback to the SLIDER? We will add this to the internal SLIDER code as well.

      C Source Code

      1. static void _cbSlider(WM_MESSAGE * pMsg) {
      2. WM_MOTION_INFO * pInfo;
      3. switch (pMsg->MsgId) {
      4. case WM_MOTION:
      5. pInfo = (WM_MOTION_INFO *)pMsg->Data.p;
      6. switch (pInfo->Cmd) {
      7. case WM_MOTION_INIT:
      8. pInfo->Flags = WM_MOTION_MANAGE_BY_WINDOW;
      9. break;
      10. }
      11. break;
      12. default:
      13. SLIDER_Callback(pMsg);
      14. }
      15. }
      Display All

      If you want motion to move the parent window only, then you do not need to add anything else. But you do need to react on WM_MOTION in _cbWin if the motion input should not move the window but instead move something else inside the parent window. The WM_MOTION_MANAGE_BY_WINDOW flag disables the movement of the entire window.

      Thanks for letting us know and sorry for any inconveniences caused by this.

      Best regards,
      Florian
      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.