Is there a way to get the size of a text element? #347
Answered
by
silver-zepp
dimasah901
asked this question in
Q&A
-
I tried to create a client for a messanger on zepp os 3 but got stuck on a problem - I can't figure out the size of a text element. I want to draw a rounded rectangle underneath the text and properly display the messages based on their side. I want to be able to do something like this: function addMessage (list, text, y) {
target.createWidget(widget.TEXT, {
x: px(17),
y: 5,
w: DEVICE_WIDTH - px(20),
h: DEVICE_HEIGHT,
text_size: px(36),
text: message,
text_style: text_style.WRAP,
line_space: px(-30),
color: THEME.TEXT_PRIMARY
});
return someSystemAPI.getTextSize(text).height
}
const viewContainer = createWidget(widget.VIEW_CONTAINER, {
x: px(0),
y: px(0),
w: DEVICE_WIDTH,
h: DEVICE_HEIGHT
})
let y = 5;
y += addMessage(list, text[0], y) + 5;
y += addMessage(list, text[1], y) + 5;
y += addMessage(list, text[2], y) + 5; Where the next message's y is the sum of the previous messages' heights. |
Beta Was this translation helpful? Give feedback.
Answered by
silver-zepp
May 22, 2024
Replies: 1 comment 3 replies
-
Here: https://docs.zepp.com/docs/reference/device-app-api/newAPI/ui/getTextLayout |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
dimasah901
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here: https://docs.zepp.com/docs/reference/device-app-api/newAPI/ui/getTextLayout