🤖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

    Scheduled Pinned Locked Moved Arduino
    3 Posts 2 Posters 6.7k Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post