|
Post by honky on Feb 12, 2023 12:11:29 GMT
More info about what you are doing with the text would help.
Is just for exercice (for fun) Texteditor cries the return line. It's not the only thing.
|
|
|
Post by Rod on Feb 12, 2023 14:05:40 GMT
Text is much more difficult than folks think. The texteditor is what it is. Sometimes text without line breaks is as useful as text with line breaks.
Here is how NOT to do it, don't even try to debug, there is so much else wrong with the technique. Its just for fun. Ahh no! remchar$() is a Liberty function.
nomainwin texteditor #main.te 0, 0, 200, 200 open "Text" for window as #main #main "trapclose [quit]"
w=10
[wrap] timer 0 #main.te "!contents? txt$" if len(txt$)>w then txt$=remchar$(txt$,chr$(10)+chr$(13)) wrp$="" row=1 col=len(txt$)-int(len(txt$)/w)*w if col=0 then col=1 for n=1 to len(txt$) step w row=row+1 wrp$=wrp$+mid$(txt$,n,w)+chr$(10) next #main.te "!cls" #main.te wrp$ #main.te "!select ";col;" ";row end if
timer 200,[wrap] wait
[quit] timer 0 close #main end
|
|
|
Post by honky on Feb 12, 2023 14:40:13 GMT
Wow in LB surprising! In:
timer 200, [compte] [compte] scan #w.entr, "!contents? car$": carac=len(car$) if carac = c then 'playwave "2.wav", async: c=c+10 #w.entr, chr$(10)+chr$(13) playwave "2.wav", async: c=c+10 end if wait
The counting of "character events" works. Too bad: chr$(10)+chr$(13) doesn't work.
|
|
|
Post by Rod on Feb 12, 2023 18:28:59 GMT
We are just going round in circles. Please post code that actually runs and demonstrates the problem. Provide instructions on how to generate the error.
As several folks have shown chr$(10) does work, you are not using it correctly.
|
|
|
Post by Rod on Feb 13, 2023 9:53:10 GMT
Looking at your fragment of code I see you do this incorrectly, you issue the chr$(10) AFTER the text is already displayed in the texteditor. So it adds the chr$(10) to the end of the text that is there. It adds a useless line feed. INSERT the chr$(10) in the text BEFORE it is displayed gets the effect you are after.
nomainwin texteditor #main.te 0, 0, 200, 200 open "Text" for window as #main #main "trapclose [quit]" #main.te "this is line one." #main.te "this is"+chr$(10)+"line two." #main.te "this is line three." #main.te chr$(10) #main.te "this is line four." wait
So the above code splits one line but inserts an unwanted line feed after line three. None of this will help with creating an automatic line break. You need to capture the text, reformat it and represent it. While you can do that with the timer as I show it spoils other things like cut copy paste delete insert etc etc.
If you see the texteditor as fundamentally an input control, you would not be surprised that outputting to it has problems. It would be nice if it did allow wrapping but sadly not. Liberty BASIC does allow API wrapping, so if it is important, use Liberty BASIC.
|
|
|
Post by honky on Feb 13, 2023 14:15:04 GMT
The code is here--->: libertybasic.fr/forum/topic-667+syntaxe.phpThe "chr$(13) is well after the text that was written before the: "if" But it is therefore inserted before the text that will be written after. I tried with chr$(10) And chr$(10)+chr$(13) Nothing works. I will look at what is being done with LB and API But APIs are not easy when we don't have control.
|
|
|
Post by Rod on Feb 13, 2023 20:03:22 GMT
You are not really understanding what has been said and shown. The trick to make this work is to insert the chr$(10) BEFORE you print to the texteditor. Since the user has already typed the text it has to be REMOVED, reformatted and reprinted. That is unworkable because it interferes with what the user is typing and stops copy paste insert delete from working. Without replchar() it is also slow.
timer 500, [compte] [compte]
'get current contents #w.entr, "!contents? car$"
'remove cr lf pair car$=left$(car$,len(car$)-2)
'if the input has grown by 10 process it if len(car$)>=carac+10 then carac=len(car$) c$="" col=1 row=1 'remove extraneous cr lf and insert lf at correct point for n=1 to len(car$) if mid$(car$,n,1) <> chr$(13) and mid$(car$,n,1)<>chr$(10) then c$=c$+mid$(car$,n,1) col=col+1 if col=10 then c$=c$+chr$(10) : col=1 : row = row + 1 end if
'now clear the screen and reprint with the correct lf breaks #w.entr "!cls" #w.entr c$;
'set the cursor to the end of text #w.entr "!select ";col;" ";row next end if wait
|
|
|
Post by honky on Feb 14, 2023 11:43:10 GMT
If it's unachievable, we won't do it. End of the story thank you for the explanations
|
|
|
Post by tsh73 on Feb 14, 2023 14:54:18 GMT
Almost usable ;) Just get last line - if it too long, switch to next one
well, if you type text ant it not shows to the right, then you are not on last line (and it will not wrap text)
nomainwin texteditor #main.te 0, 0, 200, 200 statictext #main.st "", 205, 0, 150, 200 open "Text wrap" for window as #main #main "trapclose [quit]"
w=10
[wrap] timer 0 'Wraps only *last* line '- not exacly wraps but just goes to new line #main.te, "!lines numLines"; #main.te, "!line ";numLines;" string$" 'last line #main.st numLines;">";string$;"<" 'that's status to see what's going on if len(string$) > w then 'just break string as fast as we note it #main.te "" 'empty string puts new line OK '#main.te "*" '"*"; to see where we add LF #main.te, "!select 1 " ;numLines+1 'and put cursor at new line end if
[skip] timer 200,[wrap] wait
[quit] timer 0 close #main end
|
|
|
Post by honky on Feb 14, 2023 16:33:52 GMT
It's works! Decidedly, it's still tsh73 the winner !
|
|