label
Label API documentation
Functions
label.get_layout_objects(url: string | Hash | Url): label.LayoutObject[]N
- Since Defold 1.13.2
Returns the sprites and links found in the label's current layout.
Each entry contains type, id, the zero-based UTF-32 text_offset,
text_length, resolved x, y, width
and height, and an attributes table. The position is the lower-left
object corner relative to the label's pivot, before applying scale and rotation.
Inline resource rendering is not part of this MVP; sprites use their explicit
dimensions or a one-em square fallback.
const objects = label.get_layout_objects("#label");
for (const object of objects) {
if (object.type === "link") {
print(object.attributes.get("src"), object.text_offset, object.text_length);
} else if (object.type === "sprite") {
print(object.attributes.get("src"), object.x, object.y, object.width, object.height);
}
}local objects = label.get_layout_objects("#label")
for _, object in ipairs(objects) do
if object.type == "link" then
print(object.attributes.src, object.text_offset, object.text_length)
elseif object.type == "sprite" then
print(object.attributes.src, object.x, object.y, object.width, object.height)
end
endParameters
url:string | Hash | Url— the label to inspect
Returns
objects:label.LayoutObject[]— layout objects in source order. 0️⃣text_offsetis 0-based; passed to Defold unchanged.
label.get_text(url: string | Hash | Url): stringD
- Deprecated since 1.13.2
Gets the text from a label component
This function is deprecated. Use go.get("#label", "text") instead.
export default defineScript({
init() {
const text = go.get<label.Properties>()("#label", "text");
print(text);
},
});function init(self)
local text = go.get("#label", "text")
print(text)
endParameters
url:string | Hash | Url— the label to get the text from
Returns
text:string— the label text
label.set_text(url: string | Hash | Url, text: string | number): voidD
- Deprecated since 1.13.2
Sets the text of a label component
This function is deprecated. Use go.set("#label", "text", value) instead.
This method uses the message passing that means the value will be set after dispatch messages step.
More information is available in the Application Lifecycle manual.
export default defineScript({
init() {
go.set<label.Properties>()("#label", "text", "Hello World!");
},
});function init(self)
go.set("#label", "text", "Hello World!")
endParameters
url:string | Hash | Url— the label that should have a constant settext:string | number— the text
Properties
color: Vector4
The color of the label. The type of the property is vector4.
font: Hash
The font used when rendering the label. The type of the property is hash.
leading: number
The leading of the label. This value is used to scale the line spacing of text. The type of the property is number.
line_break: boolean
The line break of the label. This value is used to adjust the vertical spacing of characters in the text. The type of the property is boolean.
material: Hash
The material used when rendering the label. The type of the property is hash.
outline: Vector4
The outline color of the label. The type of the property is vector4.
scale: Vector3
The scale of the label. go.get returns and go.set takes a vector3; go.animate also takes a number, which sets a uniform scale.
shadow: Vector4
The shadow color of the label. The type of the property is vector4.
size: Vector3
Returns the size of the label. The size will constrain the text if line break is enabled. The type of the property is vector3.
text: stringN
- Since Defold 1.13.2
The text of the label.
tracking: number
The tracking of the label. This value is used to adjust the vertical spacing of characters in the text. The type of the property is number.