Comments (8)
Hi! We need to create a proper example here. In general we're just using metadata
to pass through something we can use to derive the depth later on.
So you'd set some metadata
set on the Attrs
for the buffer, then use prepare_with_depth
with some function to pull the metadata and get the depth (however you want).
e.g. here's a really simple example where we just pack the depth into metadata directly, but you could do something more complicated if you want to pull depth values from somewhere else (based on a ID, order, etc.):
let attrs = Attrs::new()
// Pack the depth into metadata directly
.metadata(depth.to_bits() as usize)
buffer.set_text("I have a depth!", attrs);
// Later when preparing the text area...
renderer.prepare_with_depth(
/* ... rest of the arguments ... */
|metadata| {
// Convert metadata to depth however you'd like
f32::from_bits(metadata as u32)
},
);
from glyphon.
Thanks, I overlooked the attributes!
Is the idea that the TextArea
and Buffer
should be ephemeral? That the prepare
statement on the FontRender
class can be called once, and then repeatedly rendered until something changes ?
from glyphon.
Yeah exactly. You can call prepare
whenever text/attributes change (maybe optimistically if the amount of text is tiny), then re-render as much as you'd like. You could also split into multiple groups of text areas to prepare
/render
if their frequency is different, e.g., if you have one label that changes at a high frequency but other text is relatively static.
from glyphon.
Cool, got it.
Just one more question.
What was the rationale for having a reference to the Buffer
in the TextArea
? Instead of Prepare
taking for example a Vec<(Buffer,TextArea)>
?
from glyphon.
Buffer
and TextArea
can have different update frequencies depending on the application, so I wanted to allow reusing buffers while recreating text areas on-demand. e.g., maybe during a resize the text area bounds change so we want to clip to those new bounds, but we might not want to change the buffer in that case. In practice this means you'd probably cache buffers but recreate text areas somewhere near the prepare
call.
You can also reuse one Buffer
across multiple TextArea
s though that's a pretty niche use case.
from glyphon.
Ok, so for example a UI Widget struct that needs some text drawn, should have a Buffer
as a member that can later on be referenced by a `TextArea when preparing.
from glyphon.
Yeah exactly, or maybe some buffer cache that's shared between UI widgets depending on the lifecycle of the UI Widget.
from glyphon.
Thanks for your work on this library and answering my questions!
from glyphon.
Related Issues (20)
- Handle culling and clipping HOT 1
- Add documentation for all public types
- Some Source Suggestions. HOT 1
- Text atlas pipeline sample count HOT 4
- TextArea buffer reference field HOT 4
- Feature Request - C API HOT 1
- How is clipping handled? HOT 1
- Out of memory error when max_texture_dimension_2d isn't limited HOT 2
- Convert mouse position to line, character in window event? HOT 4
- `BufferLine::set_align` documentation inconsistency around resets HOT 1
- Center Text HOT 20
- OOM with large font size HOT 7
- Integration with application HOT 3
- get dimensions of rendered text HOT 2
- Crate isn't updated on crates.io HOT 5
- Consider adding a changelog and/or use GitHub releases HOT 2
- Fix interpretation of sRGB colors from cosmic-text Attrs as linear HOT 3
- WASM browser support? HOT 3
- wgpu 13 support HOT 1
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 glyphon.