Difference between revisions of "D2Editor:setExpression"
Jump to navigation
Jump to search
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | |||
− | |||
D2Editor:'''setExpression''' is a function that is part of the D2Editor Library. | D2Editor:'''setExpression''' is a function that is part of the D2Editor Library. | ||
− | |||
− | |||
This function sets the contents of a D2Editor, and is a synonym of setText. | This function sets the contents of a D2Editor, and is a synonym of setText. | ||
Line 15: | Line 11: | ||
<source lang="lua" highlight=9> | <source lang="lua" highlight=9> | ||
− | function on. | + | function on.construction() -- or on.create if OS 3.1 |
editor = D2Editor.newRichText() | editor = D2Editor.newRichText() | ||
editor:move(0,0) | editor:move(0,0) | ||
Line 52: | Line 48: | ||
*\\1vector : The text rendered inside is will be displayed under the vector arrow. | *\\1vector : The text rendered inside is will be displayed under the vector arrow. | ||
*\\1word : | *\\1word : | ||
+ | *\\0el {''content''} : Inserts a MathBox with the ''content'' inside it. | ||
For example, '''editor:setExpression("\\1vector AB")''' will render as : http://i.imgur.com/aqVd8.jpg | For example, '''editor:setExpression("\\1vector AB")''' will render as : http://i.imgur.com/aqVd8.jpg | ||
== See also == | == See also == | ||
+ | <categorytree mode=pages>D2Editor</categorytree> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
[[Category:D2Editor]] | [[Category:D2Editor]] |
Latest revision as of 17:47, 18 June 2012
D2Editor:setExpression is a function that is part of the D2Editor Library.
This function sets the contents of a D2Editor, and is a synonym of setText.
Syntax
D2Editor:setExpression(text, [cursor], [selection])
Sets the content to text, or appends it to a certain position if cursor is set. If selection is -1, no text is selected (?).
Example
function on.construction() -- or on.create if OS 3.1
editor = D2Editor.newRichText()
editor:move(0,0)
editor:resize(200,100)
end
function on.charIn(char)
currentText = editor:getExpression() -- or editor:getText()
editor:setExpression(currentText .. char) -- or editor:setText(...)
--Add char to the editor
end
function on.enterKey()
on.charIn(string.char(10))
--Add a new line
end
A very simple text editor (its actually more complicated, but it shows the basics).
Tips & Tricks
In order to insert some special template like MathBoxes, vectors shapes, angles etc., you have to put these in the setExpression argument :
- \\1angle : The text rendered inside is will be displayed under the "angle" shape
- \\1circle : Symbol for circle
- \\1keyword :
- \\1line : Symbol for line (parenthesis)
- \\1lineseg : Symbol for line segment
- \\1ray :
- \\1rtri :
- \\1subhead :
- \\1subscrp : Subscript text
- \\1supersc : Superscript text
- \\1title :
- \\1tri : Triangle symbol
- \\1vector : The text rendered inside is will be displayed under the vector arrow.
- \\1word :
- \\0el {content} : Inserts a MathBox with the content inside it.
For example, editor:setExpression("\\1vector AB") will render as : http://i.imgur.com/aqVd8.jpg
See also
<categorytree mode=pages>D2Editor</categorytree>