Input text with external fonts

Hi everybody.

I was thinking about a future app i would like to create, i’m using KWIKSHER for that.

i’ve been searching for a solution on the forum but can’t find it.

I know how to add external font in the lua code.

But i was wondering what is the code to add to a “button” to call one of the external font i will add?

Example : 

added 4 external fonts 

have 4 buttons to select the fonts

1 input text area

Thank you for your help.

if you wanted to have text using multiple fonts at one time like a text editor you would need to use multiple display.newText to pull it off

but if only one font is used for all text then the easiest way is to use native.newTextBox( ) and on each button press use object.font to change the font.

hi jstrahan

Actually i did post the “same” post on kwiksher forum and the developer told me that i should add this : 

local myField.font = native.newFont( native.systemFontBold, 18 ) --you can use a font name instead of the native.systemFontBold entry

Is that ok to add this to my button ?

Thanks a lot

I am a non-codder…sorry

you can but its only used to set/change the font of native.newTextBox and native.newTextField

it does not work with display.newText

This is the code i have after publishing : 

(made with kwik, i understand that can be a little bit different for you)

i made 2 layers : 

back (background)

and kwiksher offer you the possibility to replace a blank rectangle that i named “area”

the code : 

– area positioning 

       local function fieldHandler_area(event) 

               if (“began” == event.phase) then  

               elseif (“ended” == event.phase) then  

               elseif (“submitted” == event.phase) then  

                  local path = system.pathForFile( “gogo.txt”, system.DocumentsDirectory ) 

                  local file = io.open( path, “w+” ) 

                  file:write( area.text ) 

                  io.close( file ) 

                  native.setKeyboardFocus(nil) 

               end  

       end 

       area = native.newTextField( 278, 312, 1480, 204 ) 

       area.input = “phone” 

       area:addEventListener( “userInput”, fieldHandler_area ) 

       area.oriX = area.x; area.oriY = area.y 

So we are talking about native.newTextField…right?

if i want to change the font of this native.newTextField i will add this code to a button : 

local myField.font = native.newFont( native.systemFontBold, 18 ) --you can use a font name instead of the native.systemFontBold entry

And if i have 4 fonts, and 4 buttons to select the font i want to use i just need this “area” (blank rectagnle)?

I feel stupid to post here as i am not a codder. ;(

Thank you

no problem, you shouldn’t feel stupid.

to answer your question, using the code post above it should be

area.font = native.newFont( native.systemFontBold, 18 ) 

now depending on how the code is formatted this may cause a scope issue it just depends on where in the code area is set to local. if its set at top of code then there may not be any issues but if set somewhere else in code you may have to fix this also

OK great.

i will try all of this a bit later.

Thanks you for your help ; )

welcome

if you wanted to have text using multiple fonts at one time like a text editor you would need to use multiple display.newText to pull it off

but if only one font is used for all text then the easiest way is to use native.newTextBox( ) and on each button press use object.font to change the font.

hi jstrahan

Actually i did post the “same” post on kwiksher forum and the developer told me that i should add this : 

local myField.font = native.newFont( native.systemFontBold, 18 ) --you can use a font name instead of the native.systemFontBold entry

Is that ok to add this to my button ?

Thanks a lot

I am a non-codder…sorry

you can but its only used to set/change the font of native.newTextBox and native.newTextField

it does not work with display.newText

This is the code i have after publishing : 

(made with kwik, i understand that can be a little bit different for you)

i made 2 layers : 

back (background)

and kwiksher offer you the possibility to replace a blank rectangle that i named “area”

the code : 

– area positioning 

       local function fieldHandler_area(event) 

               if (“began” == event.phase) then  

               elseif (“ended” == event.phase) then  

               elseif (“submitted” == event.phase) then  

                  local path = system.pathForFile( “gogo.txt”, system.DocumentsDirectory ) 

                  local file = io.open( path, “w+” ) 

                  file:write( area.text ) 

                  io.close( file ) 

                  native.setKeyboardFocus(nil) 

               end  

       end 

       area = native.newTextField( 278, 312, 1480, 204 ) 

       area.input = “phone” 

       area:addEventListener( “userInput”, fieldHandler_area ) 

       area.oriX = area.x; area.oriY = area.y 

So we are talking about native.newTextField…right?

if i want to change the font of this native.newTextField i will add this code to a button : 

local myField.font = native.newFont( native.systemFontBold, 18 ) --you can use a font name instead of the native.systemFontBold entry

And if i have 4 fonts, and 4 buttons to select the font i want to use i just need this “area” (blank rectagnle)?

I feel stupid to post here as i am not a codder. ;(

Thank you

no problem, you shouldn’t feel stupid.

to answer your question, using the code post above it should be

area.font = native.newFont( native.systemFontBold, 18 ) 

now depending on how the code is formatted this may cause a scope issue it just depends on where in the code area is set to local. if its set at top of code then there may not be any issues but if set somewhere else in code you may have to fix this also

OK great.

i will try all of this a bit later.

Thanks you for your help ; )

welcome