grovesNL / glyphon

🦅🦁 Fast, simple 2D text renderer for wgpu
438 stars 54 forks source link

get dimensions of rendered text #61

Closed BKSalman closed 1 year ago

BKSalman commented 1 year ago

Hello!

I want to get the size of the rendered text rather than the whole buffer dimensions, because I'm setting it to the whole width of the window (probably shouldn't do that(?)), but if there is a way to measure the text with a function or something that would solve a couple of issues I'm having

can this be done in this crate or cosmic-text?

grovesNL commented 1 year ago

Hi! :wave: For now you'd generally want to set the buffer bounds to some area you place to place the text in, then use options like alignment to align the text within those bounds.

Currently it might be easiest to measure each line (e.g., in iced it's done like https://github.com/iced-rs/iced/blob/a3489e4af960388e9f73988b88df361022a654a4/wgpu/src/text.rs#L293-L301). You could also use visible_lines with the line height as an approximation for the vertical height of visible lines only.

BKSalman commented 1 year ago

Thank you for the quick reply!

I used the same way iced did that, and it worked :).

thank you for helping!