iced icon indicating copy to clipboard operation
iced copied to clipboard

Calculating canvas text size

Open arctic-alpaca opened this issue 3 years ago • 3 comments

Hello,

I'm trying to display canvas::Text next to a chart drawn on a canvas. To get the spacing/padding around the text right, I need to know the amount of space the text will take up on the canvas.

I tried to read the source code and follow the program execution to see how the text gets drawn on the canvas in an attempt to implement this myself but didn't get anywhere. I am thankful for any help on this subject.

arctic-alpaca avatar Aug 11 '20 14:08 arctic-alpaca

I think the way to go here is to provide a new argument to canvas::Program::draw to perform text measurements.

I will try to tackle this soon.

hecrj avatar Aug 16 '20 22:08 hecrj

I will try to tackle this soon.

Thank you very much!

I think the way to go here is to provide a new argument to canvas::Program::draw to perform text measurements.

I don't quite understand your train of thought. I envisioned a function like iced::widget::canvas::Text::size_on_canvas() -> Rectangle where the Rectangle would be the texts boundaries. Could you go into a bit more detail once you find the time?

arctic-alpaca avatar Aug 17 '20 18:08 arctic-alpaca

I am also drawing charts and need text size measurement for layout. If it makes easier, only support for monospace + basic shaping is fine until the feature is fully implemented.

elbaro avatar Aug 07 '23 03:08 elbaro