Start a new topic

text formatting - new line not working

NX40024T032 Display
Editor version V0.46

When writing text to text box if I include escape character \r or \n I get strange results.
a few random pixels on screen turn on, in the location where \r  was, i do not get a line feed - new line is not started. How to force a new line?
"Device Locked, %d:%d hours\rremaining", disabled_remaining.hour, disabled_remaining.minute); 
does not print correctly
isbr is true, xcen and ycen is set to centered


\r \" and \\ are the only currently supported escape characters

Such is supported over serial.

    t0.txt="Hello"+"\r"+"World"ÿÿÿ


Although \r will create multi line, it does not look after all possibilities

such as word breaks and centering of each line of the multi-line .txt

another point to consider is just your used font. Not every font behaves same in terms of wordwrap and line breaks within a multiline text ....


adding an additional space at the right position can help ...

There was indeed a bug in older versions with \r

Such bug was fixed in v0.46 and now works as shown above

so you can no longer use "\r" control code in the printf function to produce a carriage return, line feed. 

to get it to work you have to use "\\r" in the printf function.  the first 2 \\ produces the single \ and then the r which the display interprets as its own control character.

So the display display does not recognize a hex 0d - as produced by the \r in the printf function. only an ascii '\r'. 


Your statement "so you can no longer use \r" is incorrect.

I have already shown its use case where it works.

what I was saying is the control character \r in a printf statement will not work, you are sending the ascii string'\r' in your example above.

Nextion is not driven by a single programming language, for a single compiler, or single library of functions.

printf and its limitations has no bearing for Nextion


Does not matter how your language generates the proper required sequences

- what does matter is Nextion receiving the needed sequence, triple 0xFF terminated.


Correct. Hex 0x0D was never accepted as textbased "\r" replacement.

The .txt attribute is a string, array of char (not really, an inaccessible array).

.txt is generally expected to render into graphic representation on the screen

as chars 0 to 31 are non printable, there is no provision for in the zi font matrix.


ORD(char) - 32 becomes position in font to font matrix data.

So first char in font file space character, char 32, first matrix (preview font in Editor)


0x0D has no matrix, is in ascii terms unprintable.

minimal provisions made (in tight MCU space) to provide exceptions

 - support for \r exception is created

 - support for \\ and \" is expanded

 - no other escape sequence provided for.


But the nature of the small Nextion side MCU need be taken into consideration

- it is just a small MCU tasked with also running user generated HMI

- it just can not hold all possible cases, its just a small MCU


i m updating the textbox t3 from arduino code ..how can i use next line in this case

 

//a loop reading from file and printing each line of file in str...it is working perfectly but instead of writing to a new line in textbox t3 ..it is writing on same line again and again ...tell me how to add new line in this case..

    Serial.println(str);

  sendCommand("page 4"); 

   t3.setText(str);

append the text "\r" at the end of your line

not working here 
can u kindly give me an example 

reading from SD card



 while (true) {

    n = readField(&myFile, str, sizeof(str), ",\n");

 

    // done if Error or at EOF.

    if (n == 0) break;

 

    // Print the type of delimiter.

    if (str[n-1] == ',' || str[n-1] == '\n') {

      Serial.print(str[n-1] == ',' ? F("comma: ") : F(""));

      // Remove the delimiter.

      str[n-1] =0;

    } else {

      // At eof, too long, or read error. Too long is error.

      Serial.print(myFile.available() ? F("error: ") : F("eof: "));

    }

    // Print the field.

    Serial.println(str);

    strcat(buffer,str);

    sendCommand("page 4");

    t3.setText(str);


i want to add newline at textbox t3  everytime when there is a new line in file of SD card 

you are printing your new line 'str' to text box not the appended buffer, each pass through your while loop!

t3.settext overwrites previous data written?

I am not using the arduino  code base so I am guessing that is true.

yes it overwrites the previous code.
buffer was used just to check something...
str has actual string which i wanted to print but with a new line

Login or Signup to post a comment