Hello, everyone :wave: How would you implement thi...
# compose
h
Hello, everyone đź‘‹ How would you implement this "labels over the image" behavior in Compose? Knowing that those values are variable
k
Modifier.drawWithContent
h
Hmm, in the image right ?
k
This modifier allows you to draw something before or after the main content has been drawn. That’s where you’d add your lines and texts, if that is what you’re asking. What exactly is the question? How to position the texts? How to draw them? How to determine exactly where the texts and the lines should be for any arbitrary image that may or may not depict a car?
h
yeah, the drawWithContent gave me a idea, but my question is "*How to position the texts?"* relative to the image in way that if the size/density of the device changes the labels will be in the same place.
k
Do you know where each callout needs to be? Like in terms of width percentage and height percentage? That the front hood is at 20% width and 80% height, and the rear trunk at 85% width and 30% height? If yes, you’d use those numbers along with the pixel / dp width and height of the canvas (size.width, size.height) to draw the lines and the texts. If not, that’s what you’d need to figure out first, which isn’t a Compose question.
You use the canvas / current density to convert pixels to dps if needed, but otherwise
DrawScope.drawText
accepts the usual sp values for text size in the style attribute.
h
Ok, got it Thank you very much, Kirill
đź‘Ť 1