How to know width in pixel of a TEXT widget from inside the callback?

  • 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:

    the result is:
    [Blocked Image: https://s17.postimg.org/6fhzza3v3/string_Dim.png]

    As you can see 24 is the whidth of the text rendered by GUI_DispStringAt () and not by TEXT widget.

    best regards
    Max

  • Hi,

    While calling GUI_GetStringDistX() within WM_PAINT the default font is still set and you will receive the string length in pixel in combination with the default font.

    To get the string length of from the TEXT widget you have to set the font used by the text widget before calling GUI_GetStringDistX().

    Try this:

    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: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!