Disabling an EDIT widget does not stop cursor blinking

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

    • Disabling an EDIT widget does not stop cursor blinking

      Hello,

      I have a UI where I have several EDIT widgets to enter float values.
      The device I am developing can also be controlled remotely. If the remote control is active then I have to disable the EDIT widgets.
      When I disable the EDIT widgets the cursor remains blinking which suggests the user that entering values is possible (which is obviously not since it is disabled).
      I already created a user defined callback for the EDIT widgets which enables and disables the blinking cursor.
      This improves the behavior. If I disable the EDIT widget the cursor stops blinking but the cursor rectangle remains.
      Attached you can find a simulation sample.

      Is it possible to remove the cursor completely if the EDIT widget gets disabled?

      Hope you can help me

      C Source Code

      1. /*********************************************************************
      2. * SEGGER Microcontroller GmbH & Co. KG *
      3. * Solutions for real time microcontroller applications *
      4. **********************************************************************
      5. * *
      6. * (c) 1996 - 2017 SEGGER Microcontroller GmbH & Co. KG *
      7. * *
      8. * Internet: www.segger.com Support: support@segger.com *
      9. * *
      10. **********************************************************************
      11. ** emWin V5.46 - Graphical user interface for embedded applications **
      12. emWin is protected by international copyright laws. Knowledge of the
      13. source code may not be used to write a similar product. This file may
      14. only be used in accordance with a license and should not be re-
      15. distributed in any way. We appreciate your understanding and fairness.
      16. ----------------------------------------------------------------------
      17. File : WIDGET_SimpleProgbar.c
      18. Purpose : Demonstrates the use of the PROGBAR widget
      19. Requirements: WindowManager - (x)
      20. MemoryDevices - ( )
      21. AntiAliasing - ( )
      22. VNC-Server - ( )
      23. PNG-Library - ( )
      24. TrueTypeFonts - ( )
      25. ----------------------------------------------------------------------
      26. */
      27. #include "GUI.h"
      28. #include "TEXT.h"
      29. #include "EDIT.h"
      30. /*********************************************************************
      31. *
      32. * Defines
      33. *
      34. **********************************************************************
      35. */
      36. //
      37. // Recommended memory to run the sample with adequate performance
      38. //
      39. #define RECOMMENDED_MEMORY (1024L * 5)
      40. /*******************************************************************
      41. *
      42. * static code
      43. *
      44. ********************************************************************
      45. */
      46. void BkCb(WM_MESSAGE *Msg)
      47. {
      48. }
      49. void GUIU_EditCb(WM_MESSAGE * Msg)
      50. {
      51. GUI_RECT EditShape;
      52. unsigned char CursorPos;
      53. if (Msg->MsgId == WM_NOTIFY_ENABLE)
      54. {
      55. if (WM_IsEnabled(Msg->hWin))
      56. {
      57. /* start cursor blinking if the widget gets enabled */
      58. EDIT_EnableBlink(Msg->hWin, 500, 1);
      59. }
      60. else
      61. {
      62. /* stop cursor blinking if the widget gets disabled and hide the
      63. virtual keypad icon */
      64. EDIT_EnableBlink(Msg->hWin, 500, 0);
      65. }
      66. }
      67. /* execute the default widget callback function */
      68. switch (Msg->MsgId)
      69. {
      70. default:
      71. EDIT_Callback(Msg);
      72. }
      73. }
      74. static void _cbDoSomething(WM_HWIN hWin, void * p)
      75. {
      76. if (*(unsigned int*)p != 1)
      77. {
      78. WIDGET_SetFocusable(hWin, 0);
      79. WM_DisableWindow(hWin);
      80. }
      81. else
      82. {
      83. WIDGET_SetFocusable(hWin, 1);
      84. WM_EnableWindow(hWin);
      85. }
      86. }
      87. /*********************************************************************
      88. *
      89. * Public code
      90. *
      91. **********************************************************************
      92. */
      93. /*********************************************************************
      94. *
      95. * MainTask
      96. */
      97. void MainTask(void) {
      98. WM_HWIN Item;
      99. unsigned int Counter = 0;
      100. unsigned int EnableState;
      101. GUI_Init();
      102. /* Set UTF-8 encoding */
      103. GUI_UC_SetEncodeUTF8();
      104. //
      105. // Check if recommended memory for the sample is available
      106. //
      107. if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
      108. GUI_ErrorOut("Not enough memory available.");
      109. return;
      110. }
      111. GUI_SetBkColor(GUI_WHITE);
      112. GUI_Clear();
      113. GUI_SetColor(GUI_BLACK);
      114. GUI_SetFont(&GUI_Font24_ASCII);
      115. GUI_DispStringHCenterAt("EDIT disable test", 160, 5);
      116. WM_SetCallback(WM_HBKWIN, BkCb);
      117. Item = TEXT_CreateEx(5, 50, 400, 40, WM_HBKWIN, WM_CF_SHOW, TEXT_CF_LEFT|TEXT_CF_VCENTER, GUI_ID_TEXT0, "Widgets enabled");
      118. TEXT_SetFont(Item, GUI_FONT_20_ASCII);
      119. TEXT_SetTextColor(Item, GUI_DARKGREEN);
      120. TEXT_SetBkColor(Item, GUI_WHITE);
      121. /* generate some EDIT widgets */
      122. Item = EDIT_CreateEx(5, 100, 125, 40, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT0, 10U);
      123. EDIT_EnableBlink(Item, 500, 1);
      124. EDIT_SetFloatMode(Item, 0, 0, 100, 2, 0);
      125. WM_SetCallback(Item, GUIU_EditCb);
      126. Item = EDIT_CreateEx(5, 150, 125, 40, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT1, 10U);
      127. EDIT_EnableBlink(Item, 500, 1);
      128. EDIT_SetFloatMode(Item, 0, 0, 100, 2, 0);
      129. WM_SetCallback(Item, GUIU_EditCb);
      130. Item = EDIT_CreateEx(5, 200, 125, 40, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT2, 10U);
      131. EDIT_EnableBlink(Item, 500, 1);
      132. EDIT_SetFloatMode(Item, 0, 0, 100, 2, 0);
      133. WM_SetCallback(Item, GUIU_EditCb);
      134. WM_SetFocus(Item);
      135. while(1) {
      136. GUI_Delay(3600);
      137. EnableState = (Counter++) & 0x1;
      138. WM_ForEachDesc(WM_HBKWIN, _cbDoSomething, (void *)&EnableState);
      139. Item = WM_GetDialogItem(WM_HBKWIN, GUI_ID_TEXT0);
      140. if (EnableState)
      141. {
      142. TEXT_SetTextColor(Item, GUI_DARKGREEN);
      143. TEXT_SetText(Item, "Widgets enabled");
      144. }
      145. else
      146. {
      147. TEXT_SetTextColor(Item, GUI_RED);
      148. TEXT_SetText(Item, "Widgets disabled but cursor rectangle remains");
      149. }
      150. /* execute the GUI function */
      151. GUI_Exec();
      152. }
      153. }
      154. /*************************** End of file ****************************/
      Display All
    • Hello,

      to hide the cursor you could try to use EDIT_EnableInversion() with setting cursor background color as transparent and enabling transparency in WM_PAINT message sent to EDIT widgets.

      I modified your code like this:

      C Source Code

      1. #include "DIALOG.h"
      2. void BkCb(WM_MESSAGE *Msg)
      3. {
      4. }
      5. void GUIU_EditCb(WM_MESSAGE * Msg)
      6. {
      7. GUI_RECT EditShape;
      8. unsigned char CursorPos;
      9. if (Msg->MsgId == WM_NOTIFY_ENABLE)
      10. {
      11. if (WM_IsEnabled(Msg->hWin))
      12. {
      13. /* start cursor blinking if the widget gets enabled */
      14. EDIT_EnableBlink(Msg->hWin, 500, 1);
      15. }
      16. else
      17. {
      18. /* stop cursor blinking if the widget gets disabled and hide the
      19. virtual keypad icon */
      20. EDIT_EnableBlink(Msg->hWin, 500, 0);
      21. }
      22. }
      23. /* execute the default widget callback function */
      24. switch (Msg->MsgId)
      25. {
      26. case WM_PAINT:
      27. // Enable alpha channel for transparent cursor
      28. GUI_EnableAlpha(1);
      29. // Standard callback
      30. EDIT_Callback(Msg);
      31. // Disable alpha channel
      32. GUI_EnableAlpha(0);
      33. break;
      34. default:
      35. EDIT_Callback(Msg);
      36. }
      37. }
      38. static void _cbDoSomething(WM_HWIN hWin, void * p)
      39. {
      40. // Check if descendant window is EDIT widget
      41. if (WM_GetCallback(hWin) == GUIU_EditCb)
      42. if (*(unsigned int*)p != 1)
      43. {
      44. WIDGET_SetFocusable(hWin, 0);
      45. // Disable inversion for transparent cursor when EDIT widget is disabled
      46. EDIT_EnableInversion(hWin, 0);
      47. WM_DisableWindow(hWin);
      48. }
      49. else
      50. {
      51. WIDGET_SetFocusable(hWin, 1);
      52. // Enable inversion back when EDIT widget is enabled
      53. EDIT_EnableInversion(hWin, 1);
      54. WM_EnableWindow(hWin);
      55. }
      56. }
      57. void MainTask(void) {
      58. WM_HWIN Item;
      59. unsigned int Counter = 0;
      60. unsigned int EnableState;
      61. GUI_Init();
      62. /* Set UTF-8 encoding */
      63. GUI_UC_SetEncodeUTF8();
      64. GUI_SetBkColor(GUI_WHITE);
      65. GUI_Clear();
      66. GUI_SetColor(GUI_BLACK);
      67. GUI_SetFont(&GUI_Font24_ASCII);
      68. GUI_DispStringHCenterAt("EDIT disable test", 160, 5);
      69. WM_SetCallback(WM_HBKWIN, BkCb);
      70. Item = TEXT_CreateEx(5, 50, 550, 40, WM_HBKWIN, WM_CF_SHOW, TEXT_CF_LEFT|TEXT_CF_VCENTER, GUI_ID_TEXT0, "Widgets enabled");
      71. TEXT_SetFont(Item, GUI_FONT_20_ASCII);
      72. TEXT_SetTextColor(Item, GUI_DARKGREEN);
      73. TEXT_SetBkColor(Item, GUI_WHITE);
      74. /* generate some EDIT widgets */
      75. Item = EDIT_CreateEx(5, 100, 125, 40, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT0, 10U);
      76. EDIT_EnableBlink(Item, 500, 1);
      77. EDIT_SetFloatMode(Item, 0, 0, 100, 2, 0);
      78. // Set transparent bk color for cursor
      79. EDIT_SetBkColor(Item, EDIT_CI_CURSOR, GUI_TRANSPARENT);
      80. WM_SetCallback(Item, GUIU_EditCb);
      81. Item = EDIT_CreateEx(5, 150, 125, 40, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT1, 10U);
      82. EDIT_EnableBlink(Item, 500, 1);
      83. EDIT_SetFloatMode(Item, 0, 0, 100, 2, 0);
      84. // Set transparent bk color for cursor
      85. EDIT_SetBkColor(Item, EDIT_CI_CURSOR, GUI_TRANSPARENT);
      86. WM_SetCallback(Item, GUIU_EditCb);
      87. Item = EDIT_CreateEx(5, 200, 125, 40, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT2, 10U);
      88. EDIT_EnableBlink(Item, 500, 1);
      89. EDIT_SetFloatMode(Item, 0, 0, 100, 2, 0);
      90. // Set transparent bk color for cursor
      91. EDIT_SetBkColor(Item, EDIT_CI_CURSOR, GUI_TRANSPARENT);
      92. WM_SetCallback(Item, GUIU_EditCb);
      93. WM_SetFocus(Item);
      94. while(1)
      95. {
      96. GUI_Delay(3600);
      97. EnableState = (Counter++) & 0x1;
      98. WM_ForEachDesc(WM_HBKWIN, _cbDoSomething, (void *)&EnableState);
      99. Item = WM_GetDialogItem(WM_HBKWIN, GUI_ID_TEXT0);
      100. if (EnableState)
      101. {
      102. TEXT_SetTextColor(Item, GUI_DARKGREEN);
      103. TEXT_SetText(Item, "Widgets enabled");
      104. }
      105. else
      106. {
      107. TEXT_SetTextColor(Item, GUI_RED);
      108. TEXT_SetText(Item, "Widgets disabled and cursor rectangle should have been hidden");
      109. }
      110. GUI_Exec();
      111. }
      112. }
      Display All

      At least it works in my simulator from STemWin 5.32 package.

      Alex.

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

    • Good morning,

      unfortunately I can't use the inverting blink mode of the EDIT widget since I have several text colors which results in a wide mix of different unreadable colors.
      I always have a white cursor and a black text color (for the blinking character).
      But your approach pointed me to feasible solution.
      I change the colors in the GUIU_EditCb function as follows:

      C Source Code

      1. #include "GUI.h"
      2. #include "TEXT.h"
      3. #include "EDIT.h"
      4. /*********************************************************************
      5. *
      6. * Defines
      7. *
      8. **********************************************************************
      9. */
      10. //
      11. // Recommended memory to run the sample with adequate performance
      12. //
      13. #define RECOMMENDED_MEMORY (1024L * 5)
      14. /*******************************************************************
      15. *
      16. * static code
      17. *
      18. ********************************************************************
      19. */
      20. void BkCb(WM_MESSAGE *Msg)
      21. {
      22. }
      23. void GUIU_EditCb(WM_MESSAGE * Msg)
      24. {
      25. GUI_RECT EditShape;
      26. GUI_COLOR Color;
      27. unsigned char CursorPos;
      28. if (Msg->MsgId == WM_NOTIFY_ENABLE)
      29. {
      30. if (WM_IsEnabled(Msg->hWin))
      31. {
      32. /* start cursor blinking if the widget gets enabled and set colors*/
      33. EDIT_EnableBlink(Msg->hWin, 500, 1);
      34. Color = EDIT_GetBkColor(Msg->hWin, EDIT_CI_ENABLED);
      35. EDIT_SetTextColor(Msg->hWin, EDIT_CI_CURSOR, Color);
      36. Color = EDIT_GetTextColor(Msg->hWin, EDIT_CI_ENABLED);
      37. EDIT_SetBkColor(Msg->hWin, EDIT_CI_CURSOR, Color);
      38. }
      39. else
      40. {
      41. /* stop cursor blinking if the widget gets disabled and hide the
      42. virtual keypad icon */
      43. EDIT_EnableBlink(Msg->hWin, 500, 0);
      44. Color = EDIT_GetTextColor(Msg->hWin, EDIT_CI_DISABLED);
      45. EDIT_SetTextColor(Msg->hWin, EDIT_CI_CURSOR, Color);
      46. Color = EDIT_GetBkColor(Msg->hWin, EDIT_CI_DISABLED);
      47. EDIT_SetBkColor(Msg->hWin, EDIT_CI_CURSOR, Color);
      48. }
      49. }
      50. /* execute the default widget callback function */
      51. switch (Msg->MsgId)
      52. {
      53. default:
      54. EDIT_Callback(Msg);
      55. }
      56. }
      57. static void _cbDoSomething(WM_HWIN hWin, void * p)
      58. {
      59. if (*(unsigned int*)p != 1)
      60. {
      61. WIDGET_SetFocusable(hWin, 0);
      62. WM_DisableWindow(hWin);
      63. }
      64. else
      65. {
      66. WIDGET_SetFocusable(hWin, 1);
      67. WM_EnableWindow(hWin);
      68. }
      69. }
      70. /*********************************************************************
      71. *
      72. * Public code
      73. *
      74. **********************************************************************
      75. */
      76. /*********************************************************************
      77. *
      78. * MainTask
      79. */
      80. void MainTask(void) {
      81. WM_HWIN Item;
      82. unsigned int Counter = 0;
      83. unsigned int EnableState;
      84. GUI_Init();
      85. /* Set UTF-8 encoding */
      86. GUI_UC_SetEncodeUTF8();
      87. //
      88. // Check if recommended memory for the sample is available
      89. //
      90. if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
      91. GUI_ErrorOut("Not enough memory available.");
      92. return;
      93. }
      94. GUI_SetBkColor(GUI_WHITE);
      95. GUI_Clear();
      96. GUI_SetColor(GUI_BLACK);
      97. GUI_SetFont(&GUI_Font24_ASCII);
      98. GUI_DispStringHCenterAt("EDIT disable test", 160, 5);
      99. WM_SetCallback(WM_HBKWIN, BkCb);
      100. Item = TEXT_CreateEx(5, 50, 400, 40, WM_HBKWIN, WM_CF_SHOW, TEXT_CF_LEFT|TEXT_CF_VCENTER, GUI_ID_TEXT0, "Widgets enabled");
      101. TEXT_SetFont(Item, GUI_FONT_20_ASCII);
      102. TEXT_SetTextColor(Item, GUI_DARKGREEN);
      103. TEXT_SetBkColor(Item, GUI_WHITE);
      104. /* generate some EDIT widgets */
      105. Item = EDIT_CreateEx(5, 100, 125, 40, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT0, 10U);
      106. EDIT_EnableBlink(Item, 500, 1);
      107. EDIT_SetFloatMode(Item, 0, 0, 100, 2, 0);
      108. EDIT_SetBkColor(Item, EDIT_CI_ENABLED, GUI_WHITE);
      109. EDIT_SetTextColor(Item, EDIT_CI_ENABLED, GUI_BLACK);
      110. EDIT_SetTextColor(Item, EDIT_CI_CURSOR, GUI_WHITE);
      111. EDIT_SetBkColor(Item, EDIT_CI_CURSOR, GUI_BLACK);
      112. EDIT_EnableInversion(Item, 0);
      113. WM_SetCallback(Item, GUIU_EditCb);
      114. Item = EDIT_CreateEx(5, 150, 125, 40, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT1, 10U);
      115. EDIT_EnableBlink(Item, 500, 1);
      116. EDIT_SetFloatMode(Item, 0, 0, 100, 2, 0);
      117. EDIT_SetBkColor(Item, EDIT_CI_ENABLED, GUI_WHITE);
      118. EDIT_SetTextColor(Item, EDIT_CI_ENABLED, GUI_BLACK);
      119. EDIT_SetTextColor(Item, EDIT_CI_CURSOR, GUI_WHITE);
      120. EDIT_SetBkColor(Item, EDIT_CI_CURSOR, GUI_BLACK);
      121. EDIT_EnableInversion(Item, 0);
      122. WM_SetCallback(Item, GUIU_EditCb);
      123. Item = EDIT_CreateEx(5, 200, 125, 40, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT2, 10U);
      124. EDIT_EnableBlink(Item, 500, 1);
      125. EDIT_SetFloatMode(Item, 0, 0, 100, 2, 0);
      126. EDIT_SetBkColor(Item, EDIT_CI_ENABLED, GUI_WHITE);
      127. EDIT_SetTextColor(Item, EDIT_CI_ENABLED, GUI_BLACK);
      128. EDIT_SetTextColor(Item, EDIT_CI_CURSOR, GUI_WHITE);
      129. EDIT_SetBkColor(Item, EDIT_CI_CURSOR, GUI_BLACK);
      130. EDIT_EnableInversion(Item, 0);
      131. WM_SetCallback(Item, GUIU_EditCb);
      132. WM_SetFocus(Item);
      133. while(1) {
      134. GUI_Delay(3600);
      135. EnableState = (Counter++) & 0x1;
      136. WM_ForEachDesc(WM_HBKWIN, _cbDoSomething, (void *)&EnableState);
      137. Item = WM_GetDialogItem(WM_HBKWIN, GUI_ID_TEXT0);
      138. if (EnableState)
      139. {
      140. TEXT_SetTextColor(Item, GUI_DARKGREEN);
      141. TEXT_SetText(Item, "Widgets enabled");
      142. }
      143. else
      144. {
      145. TEXT_SetTextColor(Item, GUI_RED);
      146. TEXT_SetText(Item, "Widgets disabled but cursor rectangle remains");
      147. }
      148. /* execute the GUI function */
      149. GUI_Exec();
      150. }
      151. }
      152. /*************************** End of file ****************************/
      Display All
      Thank you