TEXT_SetWrapMode auto wrapmode

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

    • TEXT_SetWrapMode auto wrapmode

      Hello.
      The service TEXT_SetWrapMode allows a text to be wrapped by word or by char, but is there is a way to concatante the both feature ?
      I mean, first it tries to wrap by word, if it is not possible it wraps by char
      Exemple for the text "hello my name is" :

      GUI_WRAPMODE_CHAR
      hello my na
      me is

      GUI_WRAPMODE_WORD
      hello my
      name is

      All is ok


      But if my word is "Blablablablabla"

      For GUI_WRAPMODE_CHAR it will be :
      Blablabla
      blabla

      but for GUI_WRAPMODE_WORD it will be cut :
      Blablabla
      like a GUI_WRAPMODE_NONE.

      Thanks for your answer.
    • I try to use TEXT_GetNumLines
      to check if a new line has been created or not ..
      Every time it returns 1 .

      It returns 2 only if I put a '\n' in my text , I believed it will returned the real current line

      exemple , : TEXT_SetText(hItem,"Hello my name is toto");
      result is for exmple :
      Hello my name
      is toto



      I believed that TEXT_GetNumLines returns 2 , but it returns 1.


      If i do :
      TEXT_SetText(hItem,"Hello my name\n is toto");

      result is : Hello my nameis toto

      TEXT_GetNumLines returns 2 ..


      Here is my code:


      static const GUI_WIDGET_CREATE_INFO _aListJob[] = {
      { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 800, 480, 0, 0x0, 0 },
      { TEXT_CreateIndirect, "ID_TXTLEGEND_D", ID_TXTLEGEND_D, 240, 190, 240, 20, 0, 0x0, 0 }
      };


      static void _cbDialogListJob(WM_MESSAGE * pMsg) {
      WM_HWIN hItem;
      switch (pMsg->MsgId) {
      case WM_INIT_DIALOG:
      hItem = WM_GetDialogItem(pMsg->hWin, ID_TXTLEGEND_D);


      TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_TOP);
      TEXT_SetText(hItem, "Hello this is a exemple");
      TEXT_SetFont(hItem, &GUI_Fontfont_text_medium);
      WM_SetWindowPos(hItem, 560, 265, (757 - 560), 70);
      TEXT_SetWrapMode(hItem, GUI_WRAPMODE_NONE);
      TEXT_SetBkColor(hItem, GUI_GREEN);



      break;
      default:
      WM_DefaultProc(pMsg);
      break;
      }
      }


      void MainTask(void) {
      WM_HWIN v_hwin;


      GUI_Init(); // Initialize the GUI
      WM_SetBkWindowColor(GUI_WHITE); // Set a default background color
      GUI_Clear();

      v_hwin = GUI_CreateDialogBox(_aListJob, GUI_COUNTOF(_aListJob), _cbDialogListJob, WM_HBKWIN, 0, 0);
      printf("GUI_WRAPMODE_NONE = TEXT_GetNumLines = %d", TEXT_GetNumLines(WM_GetDialogItem(v_hwin, ID_TXTLEGEND_D)));
      GUI_Delay(1000);


      TEXT_SetWrapMode(WM_GetDialogItem(v_hwin, ID_TXTLEGEND_D), GUI_WRAPMODE_WORD);
      printf("GUI_WRAPMODE_WORD = TEXT_GetNumLines = %d", TEXT_GetNumLines(WM_GetDialogItem(v_hwin, ID_TXTLEGEND_D)));
      GUI_Delay(1000);
      TEXT_SetWrapMode(WM_GetDialogItem(v_hwin, ID_TXTLEGEND_D), GUI_WRAPMODE_CHAR);
      printf("GUI_WRAPMODE_CHAR = TEXT_GetNumLines = %d", TEXT_GetNumLines(WM_GetDialogItem(v_hwin, ID_TXTLEGEND_D)));


      do
      {
      GUI_Delay(1000);
      }while(1);

      }
    • Hi,

      Unfortunately, it is not possible to combine the wrap modes. But we will think about that and discuss this internally.

      Regarding the number of lines, this was a bug in TEXT_GetNumLines(). The function didn't uses the font set for the TEXT widget and return a number of lines required by using the default font. This is fixed and will be realeased with the next major update of emWin.

      As a workaround you can do the following:

      C Source Code

      1. pFontText = TEXT_GetFont(hText); // Get TEXT font
      2. pFontOld = GUI_SetFont(pFontText); // Set the font
      3. NumLines = TEXT_GetNumLines(hText); // Get number of lines using the TEXT font
      4. GUI_SetFont(pFontOld); // Restore old font


      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.