Selecting Text and Native Control

I am trying to understand how text is handled in Corona, and I only have the vaguest understanding.  If I have a textbox with a lot of text, can I use any Corona commands to handle a user selected text item?  If the native app lets you select text and highlight, can I change my app to add the ability to copy the selected text, and append it to other previously selected text.  For example, if I have a reading selection, I am interested in letting the user choose unfamiliar words, and add them to a spelling list in order to export them and print them out.  Is this possible?

Similarly, would I be able to append a string to a user selected bit of text, for output via wireless or printing or email?

And, one more topic, is it bad design to place too much text in a text box?  Should I have it called from a web site, instead?  Is there a limit on size?

TIA

Yep, that will work. The textbox handle will run everytime you enter or change anything in a textBox. It´s a pain to debug under windows/Android as you can´t get text functions to work in the simulator under windows.

But if you have a mac or install hackintosh, you can do efficient debugging under OSX.

Here is a code snippet from one of my programs that shows how it can be handled (you have to change it a little to get it to work):

[lua]

    textramme=“Textramme.png”

    statText={}
    statText[1]=“Player name:”
    statText[2]=name
    statText[3]=“Player email:”
    statText[4]=email
    statText[5]=“Password:”
    statText[6]=password
    statText[7]=“Location:”…string.sub(scorelocation,1,14)
    statText[8]=""
    statText[9]=“Touch to edit”
    statLabel={}

local function textHandle( getObj )
                    return
                    function( event )
                        if ( “began” == event.phase ) then
                        elseif ( “ended” == event.phase ) or ( “submitted” == event.phase ) or (“editing”== event.phase) then

                                – This event is called when the user stops editing a field:
                                – for example, when they touch a different field or keyboard focus goes away
                                l=getObj().num
                                statText[l]= tostring( getObj().text )
–                                print( "Text entered = " … statText[l])         – display the text entered
                                textreturn=string.find(statText[l],string.char(10),1)     – LF er ascii: 10 (ios)
                                if textreturn~=nil then
–                                    print(“return at:”…textreturn)
                                    – remove “return” from text field (text should not be more than one line)
                                    statText[l]=string.gsub( statText[l], string.char(10), “” )
                                end

                        end
                    end     – “return function()”
                end

    for l=1,#statText do
        if l==2 or l==4  or l==6 then
            menuText[l] = display.newImageRect( textramme, 600, 75 )   – textramme is my gfx that I use to enclose the textbox
            menuText[l].x = display.contentWidth/2
            menuText[l].y = 70*l+95
            if l==2 or l==4 or l==6 then
                textBox[l] = native.newTextBox( 11, 70*l+43, 620, 78)
                textBox[l]:addEventListener( ‘userInput’,
                textHandle(
                function ()
                    return textBox[l]
                end ) )
                textBox[l]:setTextColor( 255, 255, 255, 255 )
                textBox[l].hasBackground = false
                textBox[l].align = “center”  – correct alignment/placement only shows up on device or Xcode
                textBox[l].text = statText[l]
                textBox[l].font = native.newFont( “Cantarell-Bold”, 20 )
                textBox[l].inputType = “default”
                textBox[l].alpha = 0.5
                textBox[l].isEditable = true
                textBox[l].num=l
                textBox[l].y = 70*l+82
            end
        end

        — Draw the text
        statLabel[l]=display.newText(statText[l], display.contentWidth/2+txtpx[k], 70*l+60+txtpy[k], labelFont, 40 )
        statLabel[l].x=statLabel[l][k].x-(statLabel[l][k].contentWidth/2)
        statLabel[l][k]:setTextColor( 255, 255, 255, 255 )
    end

[/lua]

As you can see, this code uses a textbox, but prevents the user from entering a linefeed (LF or Ascii=10) to keep it to a single line. After that you can do about anything with the text to auto-format, move it or whatever.

You may have to adjust the x&y coordinates to superimpose the textbox on the drawn text, but I´ll leave that to you (its easier if you make your text Bold or do some fancy textdrawing).

Thanks a bunch for your help!  I am trying to get my program to work enough to get a chance to work with these text issues.  I’ll let you know if I have any questions

Yep, that will work. The textbox handle will run everytime you enter or change anything in a textBox. It´s a pain to debug under windows/Android as you can´t get text functions to work in the simulator under windows.

But if you have a mac or install hackintosh, you can do efficient debugging under OSX.

Here is a code snippet from one of my programs that shows how it can be handled (you have to change it a little to get it to work):

[lua]

    textramme=“Textramme.png”

    statText={}
    statText[1]=“Player name:”
    statText[2]=name
    statText[3]=“Player email:”
    statText[4]=email
    statText[5]=“Password:”
    statText[6]=password
    statText[7]=“Location:”…string.sub(scorelocation,1,14)
    statText[8]=""
    statText[9]=“Touch to edit”
    statLabel={}

local function textHandle( getObj )
                    return
                    function( event )
                        if ( “began” == event.phase ) then
                        elseif ( “ended” == event.phase ) or ( “submitted” == event.phase ) or (“editing”== event.phase) then

                                – This event is called when the user stops editing a field:
                                – for example, when they touch a different field or keyboard focus goes away
                                l=getObj().num
                                statText[l]= tostring( getObj().text )
–                                print( "Text entered = " … statText[l])         – display the text entered
                                textreturn=string.find(statText[l],string.char(10),1)     – LF er ascii: 10 (ios)
                                if textreturn~=nil then
–                                    print(“return at:”…textreturn)
                                    – remove “return” from text field (text should not be more than one line)
                                    statText[l]=string.gsub( statText[l], string.char(10), “” )
                                end

                        end
                    end     – “return function()”
                end

    for l=1,#statText do
        if l==2 or l==4  or l==6 then
            menuText[l] = display.newImageRect( textramme, 600, 75 )   – textramme is my gfx that I use to enclose the textbox
            menuText[l].x = display.contentWidth/2
            menuText[l].y = 70*l+95
            if l==2 or l==4 or l==6 then
                textBox[l] = native.newTextBox( 11, 70*l+43, 620, 78)
                textBox[l]:addEventListener( ‘userInput’,
                textHandle(
                function ()
                    return textBox[l]
                end ) )
                textBox[l]:setTextColor( 255, 255, 255, 255 )
                textBox[l].hasBackground = false
                textBox[l].align = “center”  – correct alignment/placement only shows up on device or Xcode
                textBox[l].text = statText[l]
                textBox[l].font = native.newFont( “Cantarell-Bold”, 20 )
                textBox[l].inputType = “default”
                textBox[l].alpha = 0.5
                textBox[l].isEditable = true
                textBox[l].num=l
                textBox[l].y = 70*l+82
            end
        end

        — Draw the text
        statLabel[l]=display.newText(statText[l], display.contentWidth/2+txtpx[k], 70*l+60+txtpy[k], labelFont, 40 )
        statLabel[l].x=statLabel[l][k].x-(statLabel[l][k].contentWidth/2)
        statLabel[l][k]:setTextColor( 255, 255, 255, 255 )
    end

[/lua]

As you can see, this code uses a textbox, but prevents the user from entering a linefeed (LF or Ascii=10) to keep it to a single line. After that you can do about anything with the text to auto-format, move it or whatever.

You may have to adjust the x&y coordinates to superimpose the textbox on the drawn text, but I´ll leave that to you (its easier if you make your text Bold or do some fancy textdrawing).

Thanks a bunch for your help!  I am trying to get my program to work enough to get a chance to work with these text issues.  I’ll let you know if I have any questions

can i have the entire code?because i want only copy the textbox’s contenet in a variable but i am not able to do it

can i have the entire code?because i want only copy the textbox’s contenet in a variable but i am not able to do it