Difference between revisions of "TextField:getPointFromTextPosition"
(added example + 1 typo) |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
Line 6: | Line 6: | ||
=== <translate>Description</translate> === | === <translate>Description</translate> === | ||
<translate>Returns the coordinates from a given offset within the text.</translate> | <translate>Returns the coordinates from a given offset within the text.</translate> | ||
− | < | + | <syntaxhighlight lang="lua"> |
(number),(number) = TextField:getPointFromTextPosition(offset) | (number),(number) = TextField:getPointFromTextPosition(offset) | ||
</source> | </source> | ||
Line 19: | Line 19: | ||
=== <translate>Example</translate> === | === <translate>Example</translate> === | ||
'''Draws a red underline under the 'is' word:''' | '''Draws a red underline under the 'is' word:''' | ||
− | < | + | <syntaxhighlight lang="lua"> |
local font = TTFont.new("fonts/Tahoma.ttf", 32, "", true, 1) | local font = TTFont.new("fonts/Tahoma.ttf", 32, "", true, 1) | ||
local text = TextField.new(font, "This is a text") | local text = TextField.new(font, "This is a text") |
Revision as of 14:31, 13 July 2023
Available since: Gideros 2019.5
Class: TextField
Description
Returns the coordinates from a given offset within the text. <syntaxhighlight lang="lua"> (number),(number) = TextField:getPointFromTextPosition(offset) </source>
Parameters
offset: (string) The byte offset into the text string.
Return values
Returns (number) The X coordinate.
Returns (number) The Y coordinate.
Example
Draws a red underline under the 'is' word: <syntaxhighlight lang="lua"> local font = TTFont.new("fonts/Tahoma.ttf", 32, "", true, 1) local text = TextField.new(font, "This is a text") text:setPosition(100, 100) local isS, isE = string.find(text:getText(), " is ") --Get 'is' word position local isSX, isSY = text:getPointFromTextPosition(isS) --Get 'i' starting point local isEX, isEY = text:getPointFromTextPosition(isE - 1) -- Get 's' end point -- Draw a red underline under the 'is' word local underline = Pixel.new(0xFF0000, 1, isEX - isSX, 3) underline:setPosition(100 + isSX, 100 + 2) stage:addChild(text) stage:addChild(underline) </source>
- 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