Difference between revisions of "gc:drawString"
Jump to navigation
Jump to search
(top default in recent apilevels) |
|||
(12 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
'''drawString ''' is a function that is part of [[:Category:gc|gc]] (Graphics Context). | '''drawString ''' is a function that is part of [[:Category:gc|gc]] (Graphics Context). | ||
− | |||
This function is used to display text, numbers etc. on the screen at specified coordinates. | This function is used to display text, numbers etc. on the screen at specified coordinates. | ||
+ | |||
+ | |||
+ | Returns an integer corresponding to the width of the displayed string. | ||
+ | |||
+ | |||
+ | {{Since|3.0}} | ||
== Syntax == | == Syntax == | ||
Line 11: | Line 16: | ||
! Parameter !! Type !! Description | ! Parameter !! Type !! Description | ||
|- | |- | ||
− | | <u>string</u> || string || The text to display | + | | <u><center>string</center></u> || string || The text to display |
|- | |- | ||
− | | <u>x</u> || number || the ''x'' coordinate of the beginning of the string. Relative to ''position''. | + | | <u><center>x</center></u> || number || the ''x'' coordinate of the beginning of the string. Relative to ''position''. |
|- | |- | ||
− | | <u>y</u> || number || the ''y'' coordinate of the beginning of the string. Relative to ''position''. | + | | <u><center>y</center></u> || number || the ''y'' coordinate of the beginning of the string. Relative to ''position''. |
|- | |- | ||
− | | <u>position</u> || string || the string’s anchor point. It can either be "baseline", “bottom”, “middle”, or “top”. | + | | <u><center>position</center></u> || string || the string’s anchor point (vertical alignment). It can either be "baseline", “bottom”, “middle”, or “top”. See screenshot below. |
|} | |} | ||
− | == Example | + | |
− | <syntaxhighlight>gc:drawString("Hello World", 0, 0, "top")</syntaxhighlight> | + | The ''position'' argument is optional, and defaults to "bottom" when not specified in apilevels < 2.3. For apilevels >= 2.3, the default is "top". |
+ | |||
+ | == Example == | ||
+ | <syntaxhighlight>function on.paint(gc) | ||
+ | gc:drawString("Hello World", 0, 0, "top") | ||
+ | end</syntaxhighlight> | ||
will display Hello World at the top-left part of the screen. | will display Hello World at the top-left part of the screen. | ||
+ | |||
+ | |||
+ | == Good to know == | ||
+ | In order to clear up what 'position' does, here's an animated image with the 4 possibilities, showing a text that is drawn at the same 60;60 coordinates, but with different "position" attributes.<br /> | ||
+ | [[File:drawString_text_position.gif]] | ||
<br /><br /> | <br /><br /> | ||
[[Category:gc]] | [[Category:gc]] |
Latest revision as of 07:00, 8 April 2015
drawString is a function that is part of gc (Graphics Context).
This function is used to display text, numbers etc. on the screen at specified coordinates.
Returns an integer corresponding to the width of the displayed string.
This has been introduced in TI-Nspire OS 3.0 (Changes).
Syntax
gc:drawString(string, x, y [,position])
Parameter | Type | Description |
---|---|---|
string | The text to display | |
number | the x coordinate of the beginning of the string. Relative to position. | |
number | the y coordinate of the beginning of the string. Relative to position. | |
string | the string’s anchor point (vertical alignment). It can either be "baseline", “bottom”, “middle”, or “top”. See screenshot below. |
The position argument is optional, and defaults to "bottom" when not specified in apilevels < 2.3. For apilevels >= 2.3, the default is "top".
Example
function on.paint(gc)
gc:drawString("Hello World", 0, 0, "top")
end
will display Hello World at the top-left part of the screen.
Good to know
In order to clear up what 'position' does, here's an animated image with the 4 possibilities, showing a text that is drawn at the same 60;60 coordinates, but with different "position" attributes.