Difference between revisions of "TextField.new"
From GiderosMobile
(17 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
+ | |||
'''Available since:''' Gideros 2011.6<br/> | '''Available since:''' Gideros 2011.6<br/> | ||
+ | '''Class:''' [[TextField]]<br/> | ||
+ | |||
=== Description === | === 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. | |
− | Creates a new | + | <syntaxhighlight lang="lua"> |
− | default font. If you specify | + | TextField.new(font,text,sample,layout) |
− | + | </syntaxhighlight> | |
− | < | + | |
− | |||
− | </ | ||
=== Parameters === | === Parameters === | ||
− | '''font''': (FontBase) | + | '''font''': (FontBase) the font used for displaying the TextField object. If nil, default font is used<br/> |
− | '''text''': (string | + | '''text''': (string) the text to be displayed '''optional'''<br/> |
'''sample''': (string) sample to determine line height '''optional'''<br/> | '''sample''': (string) sample to determine line height '''optional'''<br/> | ||
− | '''layout''': (table) | + | '''layout''': (table) layout parameters, see [[TextField:setLayout]] '''optional'''<br/> |
+ | |||
+ | ''text'' has now more tags available ('''Gideros 2024.2'''): | ||
+ | * '''\e[u=''val'']underlined\e[!u]''', ''val'' = line thickness |0, 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 |-1, 1], ''val2'' = line thickness |0, 1] | ||
+ | * '''\e[color=''val'']text color\e[color]''', ''val'' = hex color and alpha (ex: #f005) | ||
+ | |||
+ | === Examples === | ||
+ | '''Simple text''' | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | local text = TextField.new(nil, "This is a text") | ||
+ | text:setPosition(32, 64) | ||
+ | stage:addChild(text) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | '''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 + layout''' | ||
+ | <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],\n".. | ||
+ | "text is \e[i=15]oblique 15°\e[!i],\n".. | ||
+ | "custom \e[l=0.5:0.5]line placement and thickness\e[l],\n".. | ||
+ | "last \e[color=#f00]is text color\e[color]." | ||
+ | ) | ||
+ | tf:setLayout { w=500, h=200, flags=1280|FontBase.TLF_CENTER|FontBase.TLF_VCENTER } | ||
+ | tf:setPosition(0, 40) | ||
+ | stage:addChild(tf) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | {{TextField}} |
Latest revision as of 09:58, 26 August 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)
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
text has now more tags available (Gideros 2024.2):
- \e[u=val]underlined\e[!u], val = line thickness |0, 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 |-1, 1], val2 = line thickness |0, 1]
- \e[color=val]text color\e[color], val = hex color and alpha (ex: #f005)
Examples
Simple text
local text = TextField.new(nil, "This is a text")
text:setPosition(32, 64)
stage:addChild(text)
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 + layout
local font = TTFont.new("fonts/arial.ttf", 20, "", nil, nil)
local tf = TextField.new(font,
"Text is \e[u=0.2]underlined\e[!u],\n"..
"text is \e[i=15]oblique 15°\e[!i],\n"..
"custom \e[l=0.5:0.5]line placement and thickness\e[l],\n"..
"last \e[color=#f00]is text color\e[color]."
)
tf:setLayout { w=500, h=200, flags=1280|FontBase.TLF_CENTER|FontBase.TLF_VCENTER }
tf:setPosition(0, 40)
stage:addChild(tf)
- TextField
- TextField.new
- TextField:getLayout
- TextField:getLetterSpacing
- TextField:getLineHeight
- TextField:getPointFromTextPosition
- TextField:getSample
- TextField:getText
- TextField:getTextColor
- TextField:getTextPositionFromPoint
- TextField:setFont
- TextField:setLayout
- TextField:setLetterSpacing
- TextField:setSample
- TextField:setText
- TextField:setTextColor