TextArea
Create a multi-line text area the user can type into.
TextArea objects are used for entering text that may span several lines. If the text is taller than the area, a scroll bar appears on the right.
Creating a TextArea
You can create a TextArea using the following functions:
TextArea()
TextArea(text, columns, rows, color, font)
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str |
'' |
The text to start with. |
columns |
int |
8 |
The width of the area, in characters. |
rows |
int |
5 |
The height of the area, in lines. |
color |
Color |
Color.WHITE |
The area color. |
font |
Font |
None |
The font, for example Font("Serif", Font.ITALIC, 16). If omitted, the default font is used. |
For example,
textarea = TextArea("Start Typing...", 10, 8, Color.YELLOW)
Once created, you can add it to a Display using the Display's add() function.
Functions
Once a TextArea textarea has been created, the following functions are available:
| Function | Description |
|---|---|
textarea.getText() |
Return the text in the area. |
textarea.getFont() |
Return the area's font. |
textarea.setText(text) |
Set the text in the area. |
textarea.setFont(font) |
Set the area's font. |
textarea.setColor(color) |
Set the area's color. |
Position
| Function | Description |
|---|---|
textarea.getPosition() |
Return the object's position, the top-left corner of its bounding box. |
textarea.getX() |
Return the object's horizontal position. |
textarea.getY() |
Return the object's vertical position. |
textarea.getCenter() |
Return the object's center point. |
textarea.getCenterX() |
Return the object's horizontal center. |
textarea.getCenterY() |
Return the object's vertical center. |
textarea.setPosition(x, y) |
Move the object so the top-left corner of its bounding box sits at the given point. |
textarea.setX(x) |
Set the object's horizontal position. |
textarea.setY(y) |
Set the object's vertical position. |
textarea.setCenter(x, y) |
Move the object so its center sits at the given point. |
textarea.setCenterX(x) |
Set the object's horizontal center. |
textarea.setCenterY(y) |
Set the object's vertical center. |
textarea.move(x, y) |
Move the object to a new position. |
Size
| Function | Description |
|---|---|
textarea.getSize() |
Return the object's width and height. |
textarea.getWidth() |
Return the object's width. |
textarea.getHeight() |
Return the object's height. |
textarea.setSize(width, height) |
Set the object's width and height. |
textarea.setWidth(width) |
Set the object's width. |
textarea.setHeight(height) |
Set the object's height. |
Rotation
NOTE: Controls cannot be rotated. A control has these methods available, but they do nothing.
| Function | Description |
|---|---|
textarea.setRotation(rotation) |
Do nothing, since controls cannot be turned. |
textarea.getRotation() |
Return how far the object is turned. |
textarea.rotate(angle) |
Turn the object by an additional angle. |
Visibility
| Function | Description |
|---|---|
textarea.getVisibility() |
Return how visible the object is. |
textarea.setVisibility(visibility) |
Set how visible the object is. |
Information
| Function | Description |
|---|---|
textarea.getEndpoints() |
Return the object's four corners. |
textarea.getBoundingBox() |
Return the smallest upright box that surrounds the object. |
textarea.getGroup() |
Return the Group this object belongs to. |
textarea.getDisplay() |
Return the Display this object is on. |
textarea.setToolTipText() |
Set the hover text shown over the object. |
Hit Testing
| Function | Description |
|---|---|
textarea.contains(x, y) |
Report whether a point lies inside the object. |
textarea.intersects(other) |
Report whether this object overlaps another. |
textarea.encloses(other) |
Report whether this object completely contains another. |
Events
| Function | Description |
|---|---|
textarea.onMouseClick(action) |
Set up a function to call when the mouse is clicked on this object. |
textarea.onMouseDown(action) |
Set up a function to call when the mouse textarea is pressed on this object. |
textarea.onMouseUp(action) |
Set up a function to call when the mouse textarea is released over this object. |
textarea.onMouseMove(action) |
Set up a function to call when the mouse moves over this object. |
textarea.onMouseDrag(action) |
Set up a function to call when the mouse is dragged over this object. |
textarea.onMouseEnter(action) |
Set up a function to call when the mouse moves onto this object. |
textarea.onMouseExit(action) |
Set up a function to call when the mouse moves off this object. |
textarea.onKeyType(action) |
Set up a function to call when a key is typed (pressed and released). |
textarea.onKeyDown(action) |
Set up a function to call when a key is pressed down. |
textarea.onKeyUp(action) |
Set up a function to call when a key is released. |