hecrj / coffee

An opinionated 2D game engine for Rust
https://docs.rs/coffee
MIT License
1.09k stars 55 forks source link

`Font::measure` returns wrong values #43

Closed hecrj closed 5 years ago

hecrj commented 5 years ago

I found this issue when working on #35.

Right now, the UI renderer applies a correction when measuring Text widgets. This is a dirtyfix and it probably doesn't work well with different fonts.

Here is what happens if we do not apply the correction with Inconsolata Regular:

image

I think GlyphBrush::pixel_bounds is not returning a correct value. We should probably investigate why and file an issue/PR in the glyph-brush repo.

hecrj commented 5 years ago

Issue reproduced and reported: https://github.com/alexheretic/glyph-brush/issues/68

It turns out that pixel_bounds is not compatible with Section::bounds. Totally my fault! :sweat_smile: The former are the conservative pixel boundaries for the Section, the latter are the bounds available for the text layout. While these may seem like the same thing, they are not (fonts are complicated!). I suspected something like that could be the issue.

We need a GlyphBrush::layout_bounds method. The glyph_brush author has already a working version! :tada:

So we just need to wait until a new glyph_brush release.