How to copy display.newText from the screen?

Code 1.

local anyText = display.newText ("Some dance to remember!", display.contentCenterX, display.contentCenterY/4, native.systemFont, 25)

Code 2.

local anotherText =
      {text = "This is only part of the story.\n\nAs things are, we have all adventured into Universe of immeasurable, of incalculable, possibilities, of situations never contemplated by the trend of Evolution.",
       x = display.contentCenterX,
       y = display.contentCenterY + 25,
       width = display.contentWidth - 25,
       font = native.systemFont,
       fontSize = 25,
       align = "left"}

local quote = display.newText (anotherText)
quote:setFillColor (1, 1, 1)

Result.

Question 1. How to copy any text that was shown at the scene. (Android device. To save the quote in any other programm or send via messenger or paste into any search engine)

Question 2. How to set justified alignment to the text without a headache, but smiling just a little bit.

Question 3. How correctly rotate the text if the hardware was rotated left or right.

Question 4. Is it possible to some kind of spell check be bolted to user text input?

Manee Thancs.

#1 Actually this is a multi-component question. So I’ll answer the first part of it.
Every text object has a field named text. You can reference that to get the text data out of it.
How you would send it via messenger, etc… those are all best asked in their own post.

#2 - display.newText() objects do not support justified alignment. There is no easy way I know of to do this. I could do it, but it would involve iteratively adding one line of text at a time and justifying each one as I went along. Be aware, you cannot reach into the object and find the position of individual characters.

Please note: By searching the forums I found a post by someone else who may have solved this:

If that doesn’t work I would google “justified text corona sdk” I’d also go to gitHub.com and do a simliar search.

#3
A. You’ll need to set up your app to rotate the screen when device orientation changes.
https://docs.coronalabs.com/guide/distribution/buildSettings/index.html#auto-orientation

B. You’ll need to detect the orientation has changed and redraw the text:
Detection: https://docs.coronalabs.com/api/event/orientation/index.html

#4
You can add a listener to text input fields and filter the input as desired by writing code to process the text as the user enters it (editing phase).
https://docs.coronalabs.com/api/event/userInput/index.html
https://docs.coronalabs.com/api/event/userInput/phase.html

2 Likes

Thanks for the answers. As I understood it is not possible to select and copy text to the clipboard from the phone screen like we can do it in any browser, text reader or text editor.

The post about multiline text align expired 7 years ago, the code is not avaliable now:

Nevertheless, I’ve got the idea…

I didn’t mention clipboards. I avoided answering the implied sub-questions in #1.

However, no you cannot select a text display object.

You can however select the text in a native.textField and copy that to the copy-buffer just as you can with any native text field.

Corona does not supply a way to access the OS copy-paste buffer AFAIK, but since native text fields are handled by the OS they can access it.

I don’t know why you said “…like we can do it in any browser, text reader or text editor…” You’re conflating concepts. The only reason you can select text in your examples is they are made to allow that.

1 Like

@isTrigger,

I have used a plugin to copy and paste “string”, to and from, clip board and my app on Android device. You can give it a try here.

https://docs.coronalabs.com/plugin/pasteboard/index.html

Please see the docs for full details.

2 Likes

Well, I think this only one way:

  • make an additional button for ''COPY" action;
  • define what to copy if the button is pressed;
  • use your perfect plugin pasteboard.copy( "string" , "Hello World!" )

Ok, it may be helpful, thanks.