Difference between revisions of "TextField.new"

From GiderosMobile
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
 
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/TextField|TextField]]<br/>
+
'''Class:''' [[TextField]]<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
Creates a new [[Special:MyLanguage/TextField|TextField]] object with the specified font and text. Gideros runtime includes a<br />
+
Creates a new '''TextField''' object with the specified font and text. Gideros runtime includes a default font. If you specify ''nil'' for the font parameter while creating the '''TextField''' object, default font is used.
default font. If you specify ''nil'' for the font parameter while creating the [[Special:MyLanguage/TextField|TextField]] object, default font is used.<br />
+
<syntaxhighlight lang="lua">
<br /></translate>
+
TextField.new(font,text,sample,layout)
<source lang="lua">
+
</syntaxhighlight>
TextField.new(font,text,sample,layout)
+
 
</source>
+
''text'' has now more '''tags''' available ('''Gideros 2024.2'''):
=== <translate>Parameters</translate> ===
+
* '''\e[u=''val'']underlined\e[!u]''', ''val'' = line thickness between 0 and 1
'''font''': (FontBase) <translate>The font used for displaying this [[Special:MyLanguage/TextField|TextField]] object. If nil, default font is used.</translate> <br/>
+
* '''\e[i=''val'']oblique\e[!i]''', ''val'' = text angle in degree
'''text''': (string, optional) <translate>The text to be displayed.</translate> <br/>
+
* '''\e[l=''val1'':''val2'']custom line placement and thickness\e[l]''', ''val1'' = line placement (between -1 and 1), ''val2'' = line thickness (between 0 and 1)
'''sample''': (string) <translate>sample to determine line height</translate> '''optional'''<br/>
+
* '''\e[color=''val'']text color\e[color]''', ''val'' = hex color and alpha (ex: #f005)
'''layout''': (table) <translate>Layout parameters, see [[Special:MyLanguage/TextField:setLayout|TextField:setLayout]]</translate> '''optional'''<br/>
+
 
 +
=== Parameters ===
 +
'''font''': (FontBase) the font used for displaying the TextField object. If nil, default font is used<br/>
 +
'''text''': (string) the text to be displayed '''optional'''<br/>
 +
'''sample''': (string) sample to determine line height '''optional'''<br/>
 +
'''layout''': (table) layout parameters, see [[TextField:setLayout]] '''optional'''<br/>
 +
 
 +
=== Examples ===
 +
'''Semi transparent colored text'''
 +
<syntaxhighlight lang="lua">
 +
local text = TextField.new(nil, "This is a \e[color=#f005]semi transparent red\e[color] text")
 +
text:setPosition(32, 64)
 +
stage:addChild(text)
 +
</syntaxhighlight>
 +
 
 +
'''New Gideros 2024.2 tags'''
 +
<syntaxhighlight lang="lua">
 +
local font = TTFont.new("fonts/arial.ttf", 20, "", nil, nil)
 +
local tf = TextField.new(font,
 +
"Text is \e[u=0.2]underlined\e[!u], text is \e[i=15]oblique 15°\e[!i], custom \e[l=1:0.5]line placement and thickness\e[l], last \e[color=#f00]is text color\e[color].")
 +
tf:setLayout { w=400, h=100, flags=1280|FontBase.TLF_CENTER|FontBase.TLF_VCENTER }
 +
tf:setPosition(0, 40)
 +
stage:addChild(tf)
 +
</syntaxhighlight>
  
 
{{TextField}}
 
{{TextField}}

Latest revision as of 19:48, 30 April 2024


Available since: Gideros 2011.6
Class: TextField

Description

Creates a new TextField object with the specified font and text. Gideros runtime includes a default font. If you specify nil for the font parameter while creating the TextField object, default font is used.

TextField.new(font,text,sample,layout)

text has now more tags available (Gideros 2024.2):

  • \e[u=val]underlined\e[!u], val = line thickness between 0 and 1
  • \e[i=val]oblique\e[!i], val = text angle in degree
  • \e[l=val1:val2]custom line placement and thickness\e[l], val1 = line placement (between -1 and 1), val2 = line thickness (between 0 and 1)
  • \e[color=val]text color\e[color], val = hex color and alpha (ex: #f005)

Parameters

font: (FontBase) the font used for displaying the TextField object. If nil, default font is used
text: (string) the text to be displayed optional
sample: (string) sample to determine line height optional
layout: (table) layout parameters, see TextField:setLayout optional

Examples

Semi transparent colored text

local text = TextField.new(nil, "This is a \e[color=#f005]semi transparent red\e[color] text")
text:setPosition(32, 64)
stage:addChild(text)

New Gideros 2024.2 tags

local font = TTFont.new("fonts/arial.ttf", 20, "", nil, nil)
local tf = TextField.new(font,
	"Text is \e[u=0.2]underlined\e[!u], text is \e[i=15]oblique 15°\e[!i], custom \e[l=1:0.5]line placement and thickness\e[l], last \e[color=#f00]is text color\e[color].")
tf:setLayout { w=400, h=100, flags=1280|FontBase.TLF_CENTER|FontBase.TLF_VCENTER }
tf:setPosition(0, 40)
stage:addChild(tf)