Text box while updating updates quite large area in the window

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

    • Text box while updating updates quite large area in the window

      Hello,

      I am trying to figure out a solution for text box which while validating refreshes large part of the window, thought the text box size is very small. How to invalidate only the text inside the text widget? I tried looking at the clipping but did not understand how it works.
    • Hi,

      In general the clipping algorithm of the Window Manager takes care of only updating the area windows and widgets if they are invalid.

      The TEXT widget is transparent by default which causes the background to be redrawn (you will enter the WM_PAINT case of the window behind the widget). But only the area of the transparent widget gets drawn.

      If the widget is not transparent you will not enter WM_PAINT of the background because the background is not visible at all.

      In the example below there are two TEXT widgets, one is transparent and one is opaque. Both widgets will be redrawn every 100 ms.
      Each time the background gets drawn it changes its color.

      For the left widget the background has to be redrawn each time (although it is just a small part) and you will se how the color changes.

      The right widget gets also redrawn but has a background color set. This doesn't cause the bk window to be redrawn.

      The colorful parts between the widgets are also caused by the clipping mechanism (bk window receives multiple paint events, one for each rectangle around the widgets).

      Please take a look into the manual at chapter 18.2.3 'Background window redrawing and callback' for more information about clipping.


      C Source Code

      1. #include "DIALOG.h"
      2. /*********************************************************************
      3. *
      4. * Static code
      5. *
      6. **********************************************************************
      7. */
      8. /*********************************************************************
      9. *
      10. * _cbBk
      11. */
      12. static void _cbBk(WM_MESSAGE * pMsg) {
      13. GUI_COLOR aColor[] = {GUI_RED, GUI_GREEN, GUI_BLUE};
      14. static int Index;
      15. switch (pMsg->MsgId) {
      16. case WM_PAINT:
      17. GUI_SetBkColor(aColor[Index++]);
      18. GUI_Clear();
      19. Index = (Index == GUI_COUNTOF(aColor)) ? 0 : Index;
      20. break;
      21. default:
      22. WM_DefaultProc(pMsg);
      23. break;
      24. }
      25. }
      26. /*********************************************************************
      27. *
      28. * Public code
      29. *
      30. **********************************************************************
      31. */
      32. /*********************************************************************
      33. *
      34. * MainTask
      35. */
      36. void MainTask(void) {
      37. WM_HWIN hText0;
      38. WM_HWIN hText1;
      39. GUI_Init();
      40. WM_SetCallback(WM_HBKWIN, _cbBk);
      41. hText0 = TEXT_CreateEx(20, 20, 80, 30, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_TEXT0, "Some text");
      42. TEXT_SetTextAlign(hText0, GUI_TA_HCENTER | GUI_TA_VCENTER);
      43. hText1 = TEXT_CreateEx(120, 20, 80, 30, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_TEXT0, "Some text");
      44. TEXT_SetBkColor(hText1, GUI_MAGENTA);
      45. TEXT_SetTextAlign(hText1, GUI_TA_HCENTER | GUI_TA_VCENTER);
      46. while (1) {
      47. GUI_Delay(100);
      48. WM_Invalidate(hText0);
      49. WM_Invalidate(hText1);
      50. }
      51. }
      52. /*************************** 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.