Difference between revisions of "D2Editor:setExpression"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
− | D2Editor:'''setExpression''' | + | __NOTOC__ |
+ | |||
+ | |||
+ | D2Editor:'''setExpression''' is a function that is part of the D2Editor Library. | ||
<br> | <br> | ||
Line 19: | Line 22: | ||
function on.charIn(char) | function on.charIn(char) | ||
− | currentText = editor:getExpression() -- or getText() | + | currentText = editor:getExpression() -- or editor:getText() |
− | editor:setExpression(currentText .. char) -- or setText(...) | + | editor:setExpression(currentText .. char) -- or editor:setText(...) |
--Add char to the editor | --Add char to the editor | ||
end | end | ||
Line 30: | Line 33: | ||
</source> | </source> | ||
− | A very simple text editor (its actually more complicated | + | 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 : | ||
+ | |||
+ | For example, '''editor:setExpression("\\1vector AB")''' will render as : <math>\overrightarrow{AB}</math> | ||
+ | |||
== See also == | == See also == |
Revision as of 18:05, 25 February 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.create()
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 :
For example, editor:setExpression("\\1vector AB") will render as : [math]\overrightarrow{AB}[/math]