Comments (2)
I do have a solution, but it is far from ideal. I wanted to look into adding support for this trough code-changes in wgpu_glyph itself, but haven't had time yet.
This is a simplified version of how I ended up doing it. After each draw I can use self.last_bounds + the index of the glyph to
highlight a rect that covers it like a text selection.
Note: To handle whitespace I ended up replacing it with a "_" and making the color invisible. When I used regular whitepace
it does not draw anything and the bound rect was missing causing the indexes to be wrong.
fn my_draw_text(&mut self, ...) {
let layout = ...;
let section = ...;
// Avoid re-allocating new vec's every time by storing them internally
self.last_glyphs.clear();
self.last_bounds.clear();
// Get all the glyphs for the current section to calculate their bounds. Due to
// mutable borrow, this must be stored first.
self.last_glyphs
.extend(self.brush.glyphs_custom_layout(&s, &layout).cloned());
// Calculate the bounds of each glyph
self.last_bounds
.extend(self.last_glyphs.iter().map(|glyph| {
let bounds = &fonts[glyph.font_id.0].glyph_bounds(&glyph.glyph);
Rect::new(
Vec2::new(bounds.min.x, bounds.min.y),
Vec2::new(bounds.max.x, bounds.max.y),
)
}));
// Queue the glyphs for drawing
self.brush.queue_custom_layout(s, &layout);
}
from wgpu_glyph.
This is helpful, thank you for posting your example!
from wgpu_glyph.
Related Issues (20)
- Bug: wgpu_glyph renders gibberish psuedo-glyphs when used with ANGLE and or OpenGL backend on ARM OSX
- Wasm support? HOT 3
- Glyph rendering issues with GL backend HOT 1
- Multi line text can cause validation error if scale factor != 1 HOT 1
- error: could not compile `wgpu`
- Slight inconsistency between generated images HOT 1
- repeatedly blinks HOT 1
- Owned Types
- Stroked text?
- Broken text rendering on wasm32 target in Firefox HOT 5
- Latest release fails with validation error using wgpu 0.11.1 HOT 2
- Wrong Render Result for SourceHanSerif fonts
- Get bounding box of drawn text HOT 2
- Font weight problem HOT 2
- Depth example doesn't show anything on macOS HOT 1
- Background color
- Stoke text
- Alignment/Positioning doesn't work correctly
- Broken Documentation links?
- No support for resolve_target?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wgpu_glyph.