Drawable
A drawable is basically a list of pixels that can be drawn on the widget canvas. The drawable class is abstract and cannot be instantiated but all the drawables inherit from it.
moveTo(x, y)
Directly moves the drawable to the specified position, without animating it.
Example
Parameters
Parameter | Type | Description |
---|---|---|
x | int | The x coordinate of the new position. |
y | int | The y coordinate of the new position. |
Returns
None
translateBy(dx, dy)
Moves the drawable by the specified amount of pixels.
Example
Parameters
Parameter | Type | Description |
---|---|---|
dx | int | The amount of pixels to move the drawable in the x axis. |
dy | int | The amount of pixels to move the drawable in the y axis. |
Returns
None
translateByX(dx)
Moves the drawable by the specified amount of pixels in the x axis.
Example
Parameters
Parameter | Type | Description |
---|---|---|
dx | int | The amount of pixels to move the drawable in the x axis. |
Returns
None
translateByY(dy)
Moves the drawable by the specified amount of pixels in the y axis.
Example
Parameters
Parameter | Type | Description |
---|---|---|
dy | int | The amount of pixels to move the drawable in the y axis. |
Returns
None
setFrameDuration(frameDurationMs)
Sets the duration of each frame in milliseconds. This is used for animations to determine the speed.
Example
Parameters
Parameter | Type | Description |
---|---|---|
frameDurationMs | unsigned int | Duration of each frame in milliseconds |
Returns
None
setColor(color)
Sets the color of the drawable using a Color
object.
Example
from mosaico import widget
from mosaico.color import Color
text = widget.createText()
text.setColor(Color(255, 0, 0)) # Sets color to red
Parameters
Parameter | Type | Description |
---|---|---|
color | Color | The color to set |
Returns
None
setHexColor(hexColor)
Sets the color of the drawable using a hex string.
Example
from mosaico import widget
text = widget.createText()
text.setHexColor("#FF0000") # Sets color to red
Parameters
Parameter | Type | Description |
---|---|---|
hexColor | string | The hex string representing the color |
Returns
None
animateTo(x, y, animationDurationMs)
Animates the drawable to move to the specified position over the given duration.
Example
from mosaico import widget
text = widget.createText()
text.animateTo(50, 50, 2000) # Move to (50, 50) over 2000 milliseconds
Parameters
Parameter | Type | Description |
---|---|---|
x | int | The x coordinate of the target position |
y | int | The y coordinate of the target position |
animationDurationMs | unsigned int | Duration of the animation in milliseconds |
Returns
None
hide()
Hides the drawable.
Example
Returns
None
show()
Shows the drawable if it is hidden.
Example
Returns
None
isVisible()
Checks if the drawable is currently visible.
Example
from mosaico import widget
text = widget.createText()
print(text.isVisible()) # Outputs: True or False
Returns
Type | Description |
---|---|
bool | True if visible, False otherwise |
isAnimating()
Checks if the drawable is currently animating.
Example
from mosaico import widget
text = widget.createText()
print(text.isAnimating()) # Outputs: True or False
Returns
Type | Description |
---|---|
bool | True if animating, False otherwise |
getX()
Gets the current x coordinate of the drawable.
Example
from mosaico import widget
text = widget.createText()
print(text.getX()) # Outputs: current x position
Returns
Type | Description |
---|---|
int | The x coordinate |
getY()
Gets the current y coordinate of the drawable.
Example
from mosaico import widget
text = widget.createText()
print(text.getY()) # Outputs: current y position
Returns
Type | Description |
---|---|
int | The y coordinate |
centerHorizontally()
Centers the drawable horizontally on the widget.
Example
Returns
None
Caveats
Obviously, this method should be called after setting the width of the drawable.
The text widget is special since the width cannot be determined beforehand, make
sure to center text only in the loop()
function where the widget is already drawn and its width is known.
centerVertically()
Centers the drawable vertically on the widget.
Example
Returns
None