alexheretic / glyph-brush

Fast GPU cached text rendering
Apache License 2.0
688 stars 52 forks source link

Best way to determine bounds of an entire section #85

Closed chinedufn closed 4 years ago

chinedufn commented 4 years ago

I'm looking to be able to look up the top-left and bottom-right corner for a text section.

This will allow me to do collision detection between a section and any other rectangle - such as the current mouse position.

The solution I have in mind (do let me know if you have a better one!) is

  1. Call process_queued on all of my text sections

  2. Calculate the SectionHash of a text section that I want to look up

  3. Look it up in the calculate_glyph_cache: FxHashMap<SectionHash, Glyphed<'font, V>>

It appears as if there is no way to access the calculate_glyph_cache from outside of the glyph_brush module - which is problematic for me since I want to be able to access it from my crate

Questions

  1. Is there a better solution to my problem that you have in mind?

  2. If not - would there be any issue with exposing calculate_glyph_cache by reference? Happy to submit a PR.

alexheretic commented 4 years ago

GlyphBrush implements GlyphCruncher which provides pixel_bounds & glyph_bounds.

chinedufn commented 4 years ago

Ohhh nice!

One things come to mine - minor so feel free to ignore

GlyphCruncher name

The name feels a little cutesy to me and doesn't necessarily describe what it is.

I know it's difficult to name since it's a grab bag of functionality.

I like how specs uses the Ext suffix in WorldExt - a trait that provides extra methods on a World.

https://docs.rs/specs/0.16.0/specs/trait.WorldExt.html

So one idea is to rename GlyphCruncher to GlyphBrushExt

Again - these are just thoughts that come to mind. I'm a fan of glyph-brush so feel free to disagree!!


Thanks!!

alexheretic commented 4 years ago

Yep valid points about the name. We have GlyphCalculator which can calculate layouts & bounds but isn't interested in vertices/drawing & GlyphBrush which also does that to but is very much in to vertices.

So I have a trait for the common bits they can both do. Ideally called GlyphCalculator but I'd already used that. So GlyphCruncher...

I think of Ext as for additional functionality for certain situations / provided externally. I guess that's why it didn't come to mind. Maybe it's better anyway, I'm not 100% sure.

Open to more suggestions!