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

    text formatting

    UIFlow
    3
    4
    6.0k
    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.
    • F
      fonzies83
      last edited by

      Dear all,
      I want to ask if there is a way and if someone know how is possible with UIFlow to take the text with some space and empty line and convert it in a text with each word in one different line. Thank you and regards.

      Example:
      text BEFORE:
      TEXT1 TEXT2

      TEXT3

      text AFTER:
      TEXT1
      TEXT2
      TEXT3

      1 Reply Last reply Reply Quote 0
      • G
        Gaviota
        last edited by

        Hi,
        wiht the Execute code of the advanced section you can enter python code, because if you take the replace block in the text section the '\n' will be changed by UIFlow into '\n'.
        See my UIFlow-Example:
        0_1587491992793_parse_string.png

        ... and the following is the python code of my example:


        from m5stack import *
        from m5ui import *
        from uiflow import *

        setScreenColor(0x222222)

        label0 = M5TextBox(0, 30, "Text", lcd.FONT_DejaVu18,0xFFFFFF, rotate=0)
        label1 = M5TextBox(0, 120, "Text", lcd.FONT_DejaVu18,0xFFFFFF, rotate=0)
        rectangle0 = M5Rect(0, 100, 320, 5, 0xFFFFFF, 0xFFFFFF)

        str_original = None
        str_parse = None

        str_original = ''
        str_parse = ''
        str_original = 'TEXT1 TEXT2\n\nTEXT3'
        label0.setText(str(str_original))
        str_parse = str_original.replace(' ', '\n')
        str_parse = str_parse.replace('\n\n', '\n')
        label1.setText(str(str_parse))

        A lot of nice M5Stack stuff :) ....

        1 Reply Last reply Reply Quote 0
        • F
          fonzies83
          last edited by

          Thank you for your answer. But maybe I post wrong my question. The string was not always the same, every time the space between the various text can change. So there is the possibility with some loop to format different strings that are incoming in this form:
          TEXT1
          TEXT2
          TEXT3
          Because my problem is that is the string arrive like this:
          TEXT1

          TEXT2
          etc.
          I'm not able to see it in the m5 stick display. I need a sort of formatting when the string arrive before display it.

          Thank you and regards.

          1 Reply Last reply Reply Quote 0
          • R
            robalstona
            last edited by robalstona

            @fonzies83 try this commands

            0_1587847750162_IMG_20200425_224437444_HDR~2.jpg

            1 Reply Last reply Reply Quote 0
            • First post
              Last post