Git Product home page Git Product logo

Comments (8)

grovesNL avatar grovesNL commented on June 14, 2024

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.

olofwalker avatar olofwalker commented on June 14, 2024

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.

grovesNL avatar grovesNL commented on June 14, 2024

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.

olofwalker avatar olofwalker commented on June 14, 2024

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.

grovesNL avatar grovesNL commented on June 14, 2024

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 TextAreas though that's a pretty niche use case.

from glyphon.

olofwalker avatar olofwalker commented on June 14, 2024

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.

grovesNL avatar grovesNL commented on June 14, 2024

Yeah exactly, or maybe some buffer cache that's shared between UI widgets depending on the lifecycle of the UI Widget.

from glyphon.

olofwalker avatar olofwalker commented on June 14, 2024

Thanks for your work on this library and answering my questions!

from glyphon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.