Question
I'm following up on a previous post (link unavailable) about styling text with EDC. After applying EDC styles to a label, I need to update the text programmatically. However, when I keep the text attribute in the EDC component, subsequent changes are ignored. If I remove the text attribute, nothing is displayed.
I've tried using elm_object_item_part_text_set with various part names ("custom", "label2", "default"), but nothing changes.
Here's my EDC file:
collections {
group {
name: "elm/label/base/custom";
parts {
text { "label2";
scale: 1;
desc { "default";
color: 0 0 255 254;
color2: 255 0 0 255;
visible: 1;
text {
size: 50;
font: "Sans";
text: "TEXT";
align: 0.5 0.5;
min: 0 0;
}
align: 0.5 0.5;
rel1.relative: 0.25 0.25;
rel2.relative: 0.75 0.75;
map {
on: 1;
rotation.z: 180;
perspective_on: 1;
backface_cull: 1;
}
}
}
}
}
}
How can I update this styled text programmatically?
Answer
Problem Understanding
The issue occurs when trying to update text that has been styled using EDC. The main problems are:
- The text doesn't update when the text attribute is kept in EDC
- The text disappears when the text attribute is removed from EDC
- Using
elm_object_item_part_text_setwith common part names doesn't work
Solution Methods
-
Add an identifier to the text block:
- The text block in EDC needs a name attribute for programmatic access
- Example modification:
text { name: "label_test"; scale: 1; desc { "default"; color: 0 0 255 254; // ... rest of the styling } }
-
Use the correct function with the proper part name:
- Instead of
elm_object_item_part_text_set, useelm_object_part_text_set - The part name should match the name you gave in the EDC file
- Instead of
Code Examples
Here's how to update the text programmatically:
elm_object_part_text_set(label_widget, "label_test", "New Text");
Where:
label_widgetis your label object"label_test"is the name you defined in EDC"New Text"is the text you want to display
Additional Tips
- Ensure the part name in your code matches exactly with the name in EDC (case-sensitive)
- If you're using multiple styled labels, give each one a unique name in EDC
- Remember that this solution works for labels styled with EDC, not regular labels