Widgets on top of GRAPH disappear when using slider

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

    • Widgets on top of GRAPH disappear when using slider

      Hi,
      I have a GRAPH with horizontal slider. There are some buttons in the graph area. Each time I move the slider these buttons disappear behind the graph.
      As a workaround I used WM_BringToTop to make them visible again but this is not very elegant. Is there a way to avoid this?

      Regards
      Jan

      Attached is my GRAPH initialisation

      Source Code

      1. hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_1);
      2. for (Ch = 0; Ch < 9; Ch++)
      3. {
      4. ahData[Ch] = GRAPH_DATA_YT_Create(ChColors[Ch], HorBuff, NULL, 0);
      5. GRAPH_AttachData(hItem, ahData[Ch]); /*add graph data to plot diagram*/
      6. GRAPH_DATA_YT_SetAlign(ahData[Ch], GRAPH_ALIGN_LEFT);
      7. GRAPH_DATA_YT_MirrorX(ahData[Ch], 1);
      8. }
      9. GRAPH_SetBorder(hItem, 0, 0, 0, 20);
      10. GRAPH_SetAutoScrollbar(hItem, GUI_COORD_X, 1);
      11. GRAPH_SetAutoScrollbar(hItem, GUI_COORD_Y, 0); /*disable GRAPH vert. scrollbar has a bug (inverse)*/
      12. GRAPH_SetVSizeX(hItem, HorBuff);
      13. GRAPH_SetVSizeY(hItem, VerBuff);
      14. GRAPH_SetColor(hItem, GUI_GRAY, GRAPH_CI_GRID);
      15. GRAPH_SetColor(hItem, GUI_GRAY, GRAPH_CI_FRAME);
      16. GRAPH_SetColor(hItem, GUI_BLACK, GRAPH_CI_BORDER);
      17. GRAPH_SetColor(hItem, GUI_BLACK, GRAPH_CI_BK);
      18. GRAPH_SetGridFixedX(hItem, 1);
      19. GRAPH_SetGridDistY(hItem, 37);
      20. GRAPH_SetGridDistX(hItem, GRAPH_Width / 10);
      21. GRAPH_SetGridVis(hItem, 1);
      22. GRAPH_SetLineStyleH(hItem, GUI_LS_DOT);
      23. GRAPH_SetLineStyleV(hItem, GUI_LS_DOT);
      24. GRAPH_SetUserDraw(hItem, UserDraw); /*for time scale*/
      25. hScaleV = GRAPH_SCALE_Create(35, GUI_TA_RIGHT|GUI_TA_BOTTOM, GRAPH_SCALE_CF_VERTICAL, 37); /*create and add vertical scale*/
      26. GRAPH_SCALE_SetTextColor(hScaleV, GUI_WHITE);
      27. GRAPH_AttachScale(hItem, hScaleV);
      Display All
    • Hello,

      it is probably because the buttons in the graph area are siblings to the graph.

      Just attach this buttons to the graph as child widgets using WM_AttachWindowAt().

      Then the buttons will be always drawn after the graph is drawn so they should not disappear.

      Alex.
    • Thank you, Alex.
      I made the buttons to child widgets of the diagram, as you suggested, and now they remain visible.
      But the GRAPH widget does not seem to give notifications (there aren't any mentioned in the manual).
      I think that's why also the buttons do not send notifications. Is there a way to get notifications from the graph children?

      Regards
      Jan
    • Hi Jan,

      since your GRAPH widget is the parent window of the buttons, the GRAPH will receive the WM_NOTIFY_PARENT messages sent by the buttons.
      You just need to set a callback to the GRAPH widget and send all WM_NOTIFY_PARENT to the parent of the graph. Then you'll be able to process them in your parent window.

      You'll see how in this small sample:

      C Source Code

      1. #include "DIALOG.h"
      2. #include <stdio.h>
      3. #include <stdlib.h>
      4. /*********************************************************************
      5. *
      6. * Static code
      7. *
      8. **********************************************************************
      9. */
      10. /*********************************************************************
      11. *
      12. * _cbWin
      13. */
      14. static void _cbWin(WM_MESSAGE * pMsg) {
      15. switch (pMsg->MsgId) {
      16. case WM_PAINT:
      17. GUI_SetBkColor(GUI_WHITE);
      18. GUI_Clear();
      19. break;
      20. case WM_NOTIFY_PARENT:
      21. switch (pMsg->Data.v) {
      22. //
      23. // Process message...
      24. //
      25. }
      26. break;
      27. }
      28. }
      29. /*********************************************************************
      30. *
      31. * _cbGraph
      32. */
      33. static void _cbGraph(WM_MESSAGE * pMsg) {
      34. switch (pMsg->MsgId) {
      35. case WM_NOTIFY_PARENT:
      36. WM_SendMessage(WM_GetParent(pMsg->hWin), pMsg); // Send message to parent of this window.
      37. break;
      38. default:
      39. GRAPH_Callback(pMsg); // Everything else is handled by the default callback.
      40. break;
      41. }
      42. }
      43. /*********************************************************************
      44. *
      45. * Public code
      46. *
      47. **********************************************************************
      48. */
      49. /*********************************************************************
      50. *
      51. * MainTask
      52. */
      53. void MainTask(void) {
      54. WM_HWIN hWin;
      55. GRAPH_Handle hGraph;
      56. GUI_Init();
      57. hWin = WM_CreateWindow(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_CF_SHOW, _cbWin, 0); // Main window
      58. hGraph = GRAPH_CreateEx(0, 0, 150, 150, hWin, WM_CF_SHOW, 0, GUI_ID_GRAPH0); // Graph widget
      59. WM_SetCallback(hGraph, _cbGraph);
      60. while (1) {
      61. GUI_Delay(100);
      62. }
      63. }
      Display All

      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.
    • Hi Florian,
      thank you for your answer. I understand that I need a separate callback for the GRAPH.
      However, I'm not completely familiar with the callback mechanism.
      I have lots of references to the GRAPH in my main callback, like filling in data, scaling, sliders etc.
      If I create the diagram after the main window as you suggested all the hGraph references in my main window are still invalid when it is created. Do I need to transfer everything that deals with the diagram into the GRAPH callback?

      Regards
      Jan
    • I think I found the answer myself. I added WM_SetCallback(hGraph, _cbGraph) to WM_INIT_DIALOG of my main window. This redirects messages from all child widgets of GRAPH to the callback routine _cbGraph which again sends them to my main window.
    • There is still one problem remaining. I use GRAPH with a horizontal scrollbar (added with GRAPH_SetAutoScrollbar). Touching the scrollbar causes a WM_NOTIFY_PARENT event. Is the scrollbar a child of the GRAPH? What is its ID? I have to distinguish scrollbar events from my buttons since scrollbar notifications should not go the parent window but to the GRAPH default callback. Else scrolling wouldn't work.
    • Hi Jan,

      you can fix this by getting the ID of the sender window (the button or scrollbar widget).
      With the ID you can easily determine what to do. If the ID matches your button, you send the message to the parent window. If not, you call the default callback.

      C Source Code

      1. Id = WM_GetId(pMsg->hWinSrc);
      2. if (Id == ID_BUTTON) {
      3. WM_SendMessage(WM_GetParent(pMsg->hWin), pMsg);
      4. } else {
      5. GRAPH_Callback(pMsg);
      6. }
      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.
    • Remark to the GRAPH with child widgets:
      I noticed that before I can close the dialog window with GUI_EndDialog(pMsg->hWin, 0), I have to delete the GRAPH using WM_DeleteWindow(hGraph). If I don't delete the GRAPH before ending the dialog I get a hardware fault from my debugger.
    • Hi Jan,

      when a window is deleted, all its child windows are deleted as well. So given your GRAPH widget is a child of the dialog, you won't have to delete it manually when the dialog is deleted.

      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.