I need to know the width in pixel of a TEXT widget text from inside the (overridden) callback.
I tried to use GUI_GetStringDistX () but it seems that the font it uses to calculate the width is different from the one user by TEXT widget to render the text.
I have a small slice of code:
Display All
the result is:
[img]https://s17.postimg.org/6fhzza3v3/string_Dim.png[/img]
As you can see 24 is the whidth of the text rendered by GUI_DispStringAt () and not by TEXT widget.
best regards
Max
I tried to use GUI_GetStringDistX () but it seems that the font it uses to calculate the width is different from the one user by TEXT widget to render the text.
I have a small slice of code:
C Source Code
- #include "GUI.h"
- #include "TEXT.h"
- #include <stdio.h>
- static int extent = 0;
- void _cbCallback(WM_MESSAGE * pMsg)
- {
- switch (pMsg->MsgId)
- {
- case WM_PAINT:
- {
- char str[20];
- TEXT_GetText(pMsg->hWin, str, 20);
- extent = GUI_GetStringDistX(str);
- TEXT_Callback(pMsg);
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- void MainTask(void)
- {
- GUI_Init();
- GUI_SetBkColor(GUI_WHITE);
- GUI_Clear();
- GUI_SetColor(GUI_BLACK);
- GUI_DispStringAt("DONE", 10, 10);
- WM_HWIN hWin;
- hWin = TEXT_CreateEx(10, 17, 50, 20, WM_HBKWIN, WM_CF_SHOW, TEXT_CF_LEFT|TEXT_CF_TOP, GUI_ID_TEXT0, "");
- WM_SetCallback(hWin, _cbCallback);
- TEXT_SetText(hWin, "DONE");
- GUI_Delay(100);
- char str[3];
- sprintf(str, "%d", extent);
- GUI_DispStringAt(str, 10, 30);
- while(1)
- {
- GUI_Delay(100);
- }
- }
the result is:
[img]https://s17.postimg.org/6fhzza3v3/string_Dim.png[/img]
As you can see 24 is the whidth of the text rendered by GUI_DispStringAt () and not by TEXT widget.
best regards
Max