🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Determine the width of a character

    Arduino
    2
    3
    5.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      HansIm
      last edited by

      How can I determine the width of a character from the freefonts? I tried: "M5. Lcd.width('W',myfont)
      This reported that width is not known.

      1 Reply Last reply Reply Quote 0
      • H
        HansIm
        last edited by

        I think there's a translation error here: I want to read the width of the characters. (Google translated :-))

        I can determine the size of the characters. With FreeFonts, not all characters are the same width. An "i" is narrower than an "M".
        Since I want to split my screen into two areas, the left part should not write in the right part. If I can read the width of the characters, I know when to start a new line.

        m5stackM 1 Reply Last reply Reply Quote 0
        • m5stackM
          m5stack @HansIm
          last edited by

          @hansim

          in the this lib file , you can find the str width return function:

          https://github.com/m5stack/M5Stack/blob/master/src/utility/In_eSPI.h

            int16_t  textWidth(const char *string, uint8_t font),
                     textWidth(const char *string),
                     textWidth(const String& string, uint8_t font),
                     textWidth(const String& string),
                     fontHeight(int16_t font),
                     fontHeight(void);
          
          1 Reply Last reply Reply Quote 1
          • First post
            Last post